def __computeRanking(self, v, w, A, b): """ Compute ranking for variance estimation \argmax_{i \in \A} | w (2 Av + wb) | @param v: DataVector, coefficients of known grid points @param w: DataVector, estimated coefficients of unknown 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(w) # w * b av.add(b) # 2 * Av + w * b w.componentwise_mult(av) # = w * (2 * Av + w * b) w.abs() # = | w * (2 * Av + w * b) | return w.array()
def computePiecewiseConstantBilinearForm(grid, U): # create bilinear form of the grid gs = grid.getStorage() A = DataMatrix(gs.size(), gs.size()) createOperationLTwoDotExplicit(A, grid) # multiply the entries with the pdf at the center of the support p = DataVector(gs.getDimension()) q = DataVector(gs.getDimension()) for i in range(gs.size()): gs.getCoordinates(gs.getPoint(i), p) for j in range(gs.size()): gs.getCoordinates(gs.getPoint(j), q) # compute center of the support p.add(q) p.mult(0.5) # multiply the entries in A with the pdf at p y = float(A.get(i, j) * U.pdf(p)) A.set(i, j, y) A.set(j, i, y) return A
def computePiecewiseConstantBilinearForm(grid, U): # create bilinear form of the grid gs = grid.getStorage() A = DataMatrix(gs.size(), gs.size()) createOperationLTwoDotExplicit(A, grid) # multiply the entries with the pdf at the center of the support p = DataVector(gs.dim()) q = DataVector(gs.dim()) for i in xrange(gs.size()): gs.get(i).getCoords(p) for j in xrange(gs.size()): gs.get(j).getCoords(q) # compute center of the support p.add(q) p.mult(0.5) # multiply the entries in A with the pdf at p y = float(A.get(i, j) * U.pdf(p)) A.set(i, j, y) A.set(j, i, y) return A