Exemplo n.º 1
0
    def mean(self):
        opQuad = createOperationFirstMoment(self.grid)
        if self.trans is None:
            firstMoment = opQuad.doQuadrature(self.unnormalized_alpha_vec)
        else:
            bounds = DataMatrix(self.trans.getBounds())
            firstMoment = opQuad.doQuadrature(self.unnormalized_alpha_vec,
                                              bounds)

        return firstMoment
Exemplo n.º 2
0
def test_firstMoment(grid, lmax):
    grid.getGenerator().regular(lmax)
    resolution = 100000
    gridStorage = grid.getStorage()
    b = grid.getBasis()
    op = pysgpp.createOperationFirstMoment(grid)
    alpha = pysgpp.DataVector(grid.getSize(), 1.0)
    bounds = pysgpp.DataMatrix(1, 2, 0.0)
    bounds.set(0, 1, 1.0)
    res = 0.0
    for i in range(grid.getSize()):
        lev = gridStorage.getPoint(i).getLevel(0)
        ind = gridStorage.getPoint(i).getIndex(0)
        temp_res = 0.0
        for c in range(resolution):
            x = float(c) / resolution
            temp_res += x * b.eval(lev, ind, x)
        res += alpha.get(i) * temp_res / resolution
    print("--FirstMoment--")
    print(res)
    print(op.doQuadrature(alpha, bounds))
    print(res - op.doQuadrature(alpha, bounds))