本文整理汇总了Python中pysgpp.DataMatrix.componentwise_mult方法的典型用法代码示例。如果您正苦于以下问题:Python DataMatrix.componentwise_mult方法的具体用法?Python DataMatrix.componentwise_mult怎么用?Python DataMatrix.componentwise_mult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysgpp.DataMatrix
的用法示例。
在下文中一共展示了DataMatrix.componentwise_mult方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: var
# 需要导入模块: from pysgpp import DataMatrix [as 别名]
# 或者: from pysgpp.DataMatrix import componentwise_mult [as 别名]
def var(self, grid, alpha, U, T, mean):
r"""
Extraction of the expectation the given sparse grid function
interpolating the product of function value and pdf.
\int\limits_{[0, 1]^d} (f(x) - E(f))^2 * pdf(x) dx
"""
# extract correct pdf for moment estimation
vol, W = self._extractPDFforMomentEstimation(U, T)
D = T.getTransformations()
# copy the grid, and add a trapezoidal boundary
# ngrid = GridDescriptor().fromGrid(grid)\
# .withBorder(BorderTypes.TRAPEZOIDBOUNDARY)\
# .createGrid()
# compute nodalValues
# ngs = ngrid.getStorage()
# nodalValues = DataVector(ngs.size())
# p = DataVector(ngs.dim())
# for i in xrange(ngs.size()):
# ngs.get(i).getCoords(p)
# nodalValues[i] = evalSGFunction(grid, alpha, p) - mean
#
# # hierarchize the new function
# nalpha = hierarchize(ngrid, nodalValues)
ngs = grid.getStorage()
ngrid, nalpha = grid, alpha
# compute the integral of the product times the pdf
acc = DataMatrix(ngs.size(), ngs.size())
acc.setAll(1.)
err = 0
for i, dims in enumerate(W.getTupleIndices()):
dist = W[i]
trans = D[i]
# get the objects needed for integrating
# the current dimensions
gpsi, basisi = project(ngrid, dims)
if isinstance(dist, SGDEdist):
# project distribution on desired dimensions
# get the objects needed for integrating
# the current dimensions
gpsk, basisk = project(dist.grid, range(len(dims)))
# compute the bilinear form
tf = TrilinearGaussQuadratureStrategy([dist], trans)
A, erri = tf.computeTrilinearFormByList(gpsk, basisk, dist.alpha,
gpsi, basisi,
gpsi, basisi)
else:
# we compute the bilinear form of the grids
# compute the bilinear form
if len(dims) == 1:
dist = [dist]
trans = [trans]
bf = BilinearGaussQuadratureStrategy(dist, trans)
A, erri = bf.computeBilinearFormByList(gpsi, basisi,
gpsi, basisi)
# accumulate the results
acc.componentwise_mult(A)
# accumulate the error
err += acc.sum() / (acc.getNrows() * acc.getNcols()) * erri
# compute the variance
tmp = DataVector(acc.getNrows())
self.mult(acc, nalpha, tmp)
moment = vol * nalpha.dotProduct(tmp)
moment = moment - mean ** 2
return moment, err