当前位置: 首页>>代码示例>>Python>>正文


Python DataMatrix.sum方法代码示例

本文整理汇总了Python中pysgpp.DataMatrix.sum方法的典型用法代码示例。如果您正苦于以下问题:Python DataMatrix.sum方法的具体用法?Python DataMatrix.sum怎么用?Python DataMatrix.sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysgpp.DataMatrix的用法示例。


在下文中一共展示了DataMatrix.sum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: var

# 需要导入模块: from pysgpp import DataMatrix [as 别名]
# 或者: from pysgpp.DataMatrix import sum [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
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:76,代码来源:AnalyticEstimationStrategy.py


注:本文中的pysgpp.DataMatrix.sum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。