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


Python DataVector.abs方法代码示例

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


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

示例1: __computeRanking

# 需要导入模块: from pysgpp import DataVector [as 别名]
# 或者: from pysgpp.DataVector import abs [as 别名]
    def __computeRanking(self, v, A, b):
        """
        Compute ranking for variance estimation

        \argmax_{i \in \A} | v (2 Av - vb) |

        @param v: DataVector, coefficients of known grid points
        @param A: DataMatrix, stiffness matrix
        @param b: DataVector, squared expectation value contribution
        @return: numpy array, contains the ranking for the given samples
        """
        # update the ranking
        av = DataVector(A.getNrows())
        av.setAll(0.0)
        # = Av
        for i in xrange(A.getNrows()):
            for j in xrange(A.getNcols()):
                av[i] += A.get(i, j) * v[j]
        av.mult(2.)  # = 2 * Av
        b.componentwise_mult(v)  # = v * b
        av.sub(b)  # = 2 * Av - v * b

        w = DataVector(v)
        w.componentwise_mult(av)  # = v * (2 * Av - v * b)
        w.abs()  # = | v * (2 * Av - v * b) |

        return w.array()
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:29,代码来源:RefinementStrategy.py

示例2: testOps

# 需要导入模块: from pysgpp import DataVector [as 别名]
# 或者: from pysgpp.DataVector import abs [as 别名]
    def testOps(self):
        from pysgpp import DataVector
        # sum
        self.assertAlmostEqual(self.d_rand.sum(), sum(self.l_rand_total))

        # sqr
        d = DataVector(self.d_rand)
        d.sqr()
        for i in xrange(self.N):
            self.assertEqual(self.d_rand[i]**2, d[i])

        # abs
        d = DataVector(self.d_rand)
        d.abs()
        for i in xrange(self.N):
            self.assertEqual(abs(self.d_rand[i]), d[i])

        # componentwise_mult
        d = DataVector(self.d_rand)
#	d2 = DataVector(self.nrows, self.ncols)
	d2 = DataVector(self.N)
        for i in xrange(self.N):
            d2[i] = i
	d.componentwise_mult(d2)
        for i in xrange(self.N):
            self.assertEqual(self.d_rand[i]*i, d[i])

        # componentwise_div
        d = DataVector(self.d_rand)
        for i in xrange(self.N):
            d2[i] = i+1
	d.componentwise_div(d2)
        for i in xrange(self.N):
            self.assertEqual(self.d_rand[i]/(i+1), d[i])
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:36,代码来源:test_DataVector.py

示例3: computeErrors

# 需要导入模块: from pysgpp import DataVector [as 别名]
# 或者: from pysgpp.DataVector import abs [as 别名]
def computeErrors(jgrid, jalpha,
                  grid1, alpha1,
                  grid2, alpha2,
                  n=200):
    """
    Compute some errors to estimate the quality of the
    interpolation.
    @param jgrid: Grid, new discretization
    @param jalpha: DataVector, new surpluses
    @param grid1: Grid, old discretization
    @param alpha1: DataVector, old surpluses
    @param grid2: Grid, old discretization
    @param alpha2: DataVector, old surpluses
    @return: tuple(<float>, <float>), maxdrift, l2norm
    """
    jgs = jgrid.getStorage()

    # create control samples
    samples = DataMatrix(np.random.rand(n, jgs.dim()))

    # evaluate the sparse grid functions
    jnodalValues = evalSGFunctionMulti(jgrid, jalpha, samples)

    # eval grids
    nodalValues1 = evalSGFunctionMulti(grid1, alpha1, samples)
    nodalValues2 = evalSGFunctionMulti(grid2, alpha2, samples)

    # compute errors
    p = DataVector(jgs.dim())
    err = DataVector(n)
    for i in xrange(n):
        samples.getRow(i, p)
        y = nodalValues1[i] * nodalValues2[i]
        if abs(jnodalValues[i]) > 1e100:
            err[i] = 0.0
        else:
            err[i] = abs(y - jnodalValues[i])

    # get error statistics
    # l2
    l2norm = err.l2Norm()
    # maxdrift
    err.abs()
    maxdrift = err.max()

    return maxdrift, l2norm
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:48,代码来源:discretizeProduct.py

示例4: computeErrors

# 需要导入模块: from pysgpp import DataVector [as 别名]
# 或者: from pysgpp.DataVector import abs [as 别名]
def computeErrors(jgrid, jalpha, grid, alpha, f, n=200):
    """
    Compute some errors to estimate the quality of the
    interpolation.
    @param jgrid: Grid, new discretization
    @param jalpha: DataVector, new surpluses
    @param grid: Grid, old discretization
    @param alpha: DataVector, old surpluses
    @param f: function, to be interpolated
    @param n: int, number of Monte Carlo estimates for error estimation
    @return: tuple(<float>, <float>), maxdrift, l2norm
    """
    jgs = jgrid.getStorage()

    # create control samples
    samples = DataMatrix(np.random.rand(n, jgs.dim()))

    # evaluate the sparse grid functions
    jnodalValues = evalSGFunctionMulti(jgrid, jalpha, samples)
    nodalValues = evalSGFunctionMulti(grid, alpha, samples)

    # compute errors
    p = DataVector(jgs.dim())
    err = DataVector(n)
    for i in xrange(n):
        samples.getRow(i, p)
        y = f(p.array(), nodalValues[i])
        err[i] = abs(y - jnodalValues[i])

    # get error statistics
    # l2
    l2norm = err.l2Norm()
    # maxdrift
    err.abs()
    maxdrift = err.max()

    return maxdrift, l2norm
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:39,代码来源:discretization.py


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