def rank(self, grid, gp, alphas, params, *args, **kws): # get grid point associated to ix gs = grid.getStorage() p = [gp.getCoord(j) for j in xrange(gs.dim())] # get joint distribution ap = params.activeParams() U = ap.getIndependentJointDistribution() T = ap.getJointTransformation() q = T.unitToProbabilistic(p) # scale surplus by probability density ix = gs.seq(gp) # get area of basis function A = 1.0 for d in xrange(gs.dim()): A *= getIntegral(grid, gp.getLevel(d), gp.getIndex(d)) return abs(alphas[ix]) * A * U.pdf(q)
def rank(self, grid, gp, alphas, params, *args, **kws): # get grid point associated to ix gs = grid.getStorage() p = [gs.getCoordinates(gp, j) for j in range(gs.getDimension())] # get joint distribution ap = params.activeParams() U = ap.getIndependentJointDistribution() T = ap.getJointTransformation() q = T.unitToProbabilistic(p) # estimate the surplus alpha = estimateSurplus(grid, gp, alphas) # get area of basis function A = 1.0 for d in range(gs.getDimension()): A *= getIntegral(grid, gp.getLevel(d), gp.getIndex(d)) return abs(alpha) * U.pdf(q) * A
def rank(self, grid, gp, alphas, params, *args, **kws): gs = grid.getStorage() # estimate the convergence of ancestors of gp ratio = estimateConvergence(grid, gp, alphas) # get grid point associated to ix p = [gp.getCoord(j) for j in xrange(gs.dim())] # get joint distribution ap = params.activeParams() U = ap.getIndependentJointDistribution() T = ap.getJointTransformation() q = T.unitToProbabilistic(p) # get area of basis function A = 1.0 for d in xrange(gs.dim()): A *= getIntegral(grid, gp.getLevel(d), gp.getIndex(d)) return abs(ratio) * U.pdf(q) * A
def __doMarginalize(grid, alpha, dd, measure=None): gs = grid.getStorage() dim = gs.dim() if dim < 2: raise AttributeError("The grid has to be at least of dimension 2") if dd >= dim: raise AttributeError("The grid has only %i dimensions, so I can't \ integrate over %i" % (dim, dd)) # create new grid n_dim = dim - 1 n_grid = createGrid(grid, n_dim) n_gs = n_grid.getStorage() # insert grid points n_gp = HashGridIndex(n_dim) for i in xrange(gs.size()): gp = gs.get(i) for d in range(dim): if d == dd: # omit marginalization direction continue elif d < dd: n_gp.set(d, gp.getLevel(d), gp.getIndex(d)) else: n_gp.set(d - 1, gp.getLevel(d), gp.getIndex(d)) # insert grid point if not n_gs.has_key(n_gp): n_gs.insert(n_gp) n_gs.recalcLeafProperty() # create coefficient vector n_alpha = DataVector(n_gs.size()) n_alpha.setAll(0.0) # set function values for n_alpha for i in xrange(gs.size()): gp = gs.get(i) for d in range(dim): if d == dd: dd_level = gp.getLevel(d) dd_index = gp.getIndex(d) elif d < dd: n_gp.set(d, gp.getLevel(d), gp.getIndex(d)) else: n_gp.set(d - 1, gp.getLevel(d), gp.getIndex(d)) if not n_gs.has_key(n_gp): raise Exception("This should not happen!") # compute the integral of the given basis if measure is None: q, err = getIntegral(grid, dd_level, dd_index), 0. else: dist, trans = measure[0][dd], measure[1][dd] lf = LinearGaussQuadratureStrategy([dist], [trans]) basis = getBasis(grid) gpdd = HashGridIndex(1) gpdd.set(0, dd_level, dd_index) q, err = lf.computeLinearFormByList([gpdd], basis) q = q[0] # search for the corresponding index j = n_gs.seq(n_gp) n_alpha[j] += alpha[i] * q return n_grid, n_alpha, err
def __doMarginalize(grid, alpha, linearForm, dd, measure=None): gs = grid.getStorage() dim = gs.getDimension() if dim < 2: raise AttributeError("The grid has to be at least of dimension 2") if dd >= dim: raise AttributeError("The grid has only %i dimensions, so I can't \ integrate over %i" % (dim, dd)) # create new grid n_dim = dim - 1 n_grid = createGrid(grid, n_dim) n_gs = n_grid.getStorage() # insert grid points n_gp = HashGridPoint(n_dim) for i in range(gs.getSize()): gp = gs.getPoint(i) for d in range(dim): if d == dd: # omit marginalization direction continue elif d < dd: n_gp.set(d, gp.getLevel(d), gp.getIndex(d)) else: n_gp.set(d - 1, gp.getLevel(d), gp.getIndex(d)) # insert grid point if not n_gs.isContaining(n_gp): n_gs.insert(n_gp) n_gs.recalcLeafProperty() # create coefficient vector n_alpha = np.zeros(n_gs.getSize()) basis = getBasis(grid) # set function values for n_alpha for i in range(gs.getSize()): gp = gs.getPoint(i) for d in range(dim): if d == dd: dd_level = gp.getLevel(d) dd_index = gp.getIndex(d) elif d < dd: n_gp.set(d, gp.getLevel(d), gp.getIndex(d)) else: n_gp.set(d - 1, gp.getLevel(d), gp.getIndex(d)) if not n_gs.isContaining(n_gp): raise Exception("This should not happen!") # compute the integral of the given basis if measure is None: q, err = getIntegral(grid, dd_level, dd_index), 0. else: dist, trans = measure[0][dd], measure[1][dd] linearForm.setDistributionAndTransformation([dist], [trans]) gpdd = HashGridPoint(1) gpdd.set(0, dd_level, dd_index) q, err = linearForm.computeLinearFormByList(gs, [gpdd], basis) q = q[0] * trans.vol() err *= trans.vol() # search for the corresponding index j = n_gs.getSequenceNumber(n_gp) n_alpha[j] += alpha[i] * q return n_grid, n_alpha, err