SG++
python.uq.operations.sparse_grid Namespace Reference

Functions

def add (alpha, alphas)
 
def addConst (grid, alpha, c, y)
 
def balance (grid)
 
def checkInterpolation (grid, alpha, nodalValues, epsilon=1e-13)
 
def checkPositivity (grid, alpha)
 
def copyGrid (grid, level=0, deg=1)
 
def createGrid (grid, dim, deg=1, addTruncatedBorder=False)
 
def dehierarchize (grid, alpha)
 
def dehierarchizeList (grid, alpha, gps)
 
def dehierarchizeOnNewGrid (gridResult, grid, alpha)
 
def estimateConvergence (grid, gp, v)
 
def estimateSurplus (grid, gp, v)
 def estimateSurplus(grid, gp, v): gs = grid.getStorage() ix = gs.getSequenceNumber(gp) More...
 
def evalHierToTop (basis, grid, coeffs, gp, d)
 
def evalSGFunction (grid, alpha, p, isConsistent=True)
 
def evalSGFunctionBasedOnParents (grid, alpha, gpi)
 
def evalSGFunctionMulti (grid, alpha, samples, isConsistent=True)
 
def getBasis (grid)
 
def getBoundsOfSupport (gs, level, index, gridType)
 
def getDegree (grid)
 
def getGridPointsOnBoundary (level, index)
 
def getGridPointsOnBoundaryEfficiently (level, index)
 
def getHierarchicalAncestors (grid, gp)
 
def getIndex (gp)
 
def getLevel (gp)
 
def getLevelIndex (gp)
 
def getNonExistingHierarchicalAncestors (grid, gp)
 
def hasAllChildren (grid, gp)
 
def hasBorder (gridType)
 
def hasChildren (grid, gp)
 
def haveHierarchicalRelationshipByLevelIndex (leveli, indexi, levelj, indexj)
 
def haveOverlappingSupport (gpi, gpj)
 
def haveOverlappingSupportByLevelIndex (leveli, indexi, levelj, indexj)
 
def haveOverlappingSupportDimx (lid, iid, ljd, ijd)
 
def hierarchize (grid, nodalValues, isConsistent=True, ignore=None)
 
def hierarchizeBruteForce (grid, nodalValues, ignore=None)
 
def hierarchizeEvalHierToTop (grid, nodalValues)
 
def insertHierarchicalAncestors (grid, gp)
 
def insertPoint (grid, gp)
 
def insertTruncatedBorder (grid, gp)
 
def isHierarchicalAncestor (gpi, gpj)
 
def isHierarchicalAncestorByLevelIndex (leveli, indexi, levelj, indexj)
 
def isHierarchicalAncestorDimx (li, ii, lj, ij)
 
def isRefineable (grid, gp)
 
def isValid (grid, gp)
 
def isValid1d (grid, level, index)
 
def parent (grid, gp, d)
 
def parents (grid, gp)
 
def sub (alpha, alphas)
 

Variables

list bsplineBoundaryGridTypes
 
 bsplineGridTypes = bsplineNoBoundaryGridTypes+bsplineBoundaryGridTypes
 
list bsplineNoBoundaryGridTypes
 
list linearBoundaryGridTypes
 
 linearGridTypes = linearNoBoundaryGridTypes+linearBoundaryGridTypes
 
list linearNoBoundaryGridTypes
 
list polyBoundaryGridTypes = [GridType_PolyBoundary]
 
 polyGridTypes = polyNoBoundaryGridTypes+polyBoundaryGridTypes
 
list polyNoBoundaryGridTypes
 

Function Documentation

def python.uq.operations.sparse_grid.add (   alpha,
  alphas 
)
def python.uq.operations.sparse_grid.addConst (   grid,
  alpha,
  c,
  y 
)
def python.uq.operations.sparse_grid.balance (   grid)
def python.uq.operations.sparse_grid.checkInterpolation (   grid,
  alpha,
  nodalValues,
  epsilon = 1e-13 
)
def python.uq.operations.sparse_grid.checkPositivity (   grid,
  alpha 
)
def python.uq.operations.sparse_grid.createGrid (   grid,
  dim,
  deg = 1,
  addTruncatedBorder = False 
)
def python.uq.operations.sparse_grid.dehierarchizeList (   grid,
  alpha,
  gps 
)
evaluate sparse grid function at grid points in gps
@param grid: Grid
@param alpha: DataVector
@param gps: list of HashGridPoint

References sgpp::op_factory.createOperationMultipleEval().

def python.uq.operations.sparse_grid.dehierarchizeOnNewGrid (   gridResult,
  grid,
  alpha 
)
def python.uq.operations.sparse_grid.estimateSurplus (   grid,
  gp,
  v 
)

def estimateSurplus(grid, gp, v): gs = grid.getStorage() ix = gs.getSequenceNumber(gp)

surplus is already known

if ix < len(v): print "warning: not estimated", return v[ix]

vgp = []

get all available parents

myParents = [(d, pgp) for (d, pgp) in parents(grid, gp) if gs.isContaining(pgp)] vparents = np.ndarray(len(myParents), dtype='float') for i, (dp, p) in enumerate(myParents): ipar = gs.getSequenceNumber(p) vparents[i] = v[ipar]

get all grand parents = parents of parents

for dgrp, grp in parents(grid, p):

use a linear extrapolation through parent and grandparent

to estimate the surplus of the current collocation node

igrandpar = gs.getSequenceNumber(grp) xpar = p.getStandardCoordinate(dgrp) xgrandpar = grp.getStandardCoordinate(dgrp) xgp = p.getStandardCoordinate(dgrp) + 2 ** -gp.getLevel(dp)

slope between parent and grand parent

a = (v[ipar] - v[igrandpar]) / (xpar - xgrandpar)

half the slope for the child

a /= 2.

same behavior -> keep direction

if (v[ipar] > 0 and v[igrandpar] > 0) or \ (v[ipar] < 0 and v[igrandpar] < 0): sign = 1.

alternating behavior -> change direction

else: sign = -1.

a *= sign

add constant part

b = v[ipar] - a * xpar

force extrapolation with half the difference between

father and grand father for the child

xgp = xpar + (xpar - xgrandpar) / 2.

do the linear extrapolation

y = a * xgp + b

import matplotlib.pyplot as plt

plt.plot([xpar, xgp], [a * xi + b for xi in [xpar, xgp]])

plt.plot([xgrandpar, xpar], [sign * 2 * a * xi + v[ipar]

- sign * 2 * a * xpar

for xi in [xgrandpar, xpar]])

plt.plot(xpar, v[ipar], marker='p', label='parent')

plt.plot(xgrandpar, v[igrandpar], marker='o', label='grand father')

plt.plot(xgp, y, marker='x', label='self')

plt.legend(loc='best')

plt.show()

        vgp.append(y)

if len(vgp) == 0:
    vgp = vparents

return np.max(vgp) 
Linear extrapolation of the surplus
@param grid: Grid
@param gp: HashGridPoint
@param v: DataVector, surplus vector
@return: float, estimated surplus for gp

References python.uq.operations.sparse_grid.parents().

Referenced by python.uq.refinement.RefinementStrategy.SquaredSurplusBFRanking.rank(), python.uq.refinement.RefinementStrategy.ExpectationValueBFRanking.rank(), python.uq.refinement.RefinementStrategy.LinearSurplusEstimationRanking.rank(), and python.uq.refinement.RefinementStrategy.VarianceBFRanking.update().

def python.uq.operations.sparse_grid.evalHierToTop (   basis,
  grid,
  coeffs,
  gp,
  d 
)
def python.uq.operations.sparse_grid.evalSGFunctionBasedOnParents (   grid,
  alpha,
  gpi 
)
def python.uq.operations.sparse_grid.getGridPointsOnBoundaryEfficiently (   level,
  index 
)
def python.uq.operations.sparse_grid.getNonExistingHierarchicalAncestors (   grid,
  gp 
)
def python.uq.operations.sparse_grid.hasAllChildren (   grid,
  gp 
)
def python.uq.operations.sparse_grid.hasChildren (   grid,
  gp 
)
def python.uq.operations.sparse_grid.haveHierarchicalRelationshipByLevelIndex (   leveli,
  indexi,
  levelj,
  indexj 
)
def python.uq.operations.sparse_grid.hierarchizeEvalHierToTop (   grid,
  nodalValues 
)
def python.uq.operations.sparse_grid.insertTruncatedBorder (   grid,
  gp 
)
insert points on the border recursively for grids with border
@param grid: Grid
@param gp: HashGridPoint
@return: list of HashGridPoint, contains all the newly added grid points

References python.uq.operations.sparse_grid.insertPoint().

Referenced by python.uq.operations.forcePositivity.operationMakePositive.OperationMakePositive.addFullGridPoints(), python.uq.learner.builder.GridDescriptor.GridDescriptor.createGrid(), and python.uq.refinement.LocalRefinementStrategy.CreateAllChildrenRefinement.refine().

def python.uq.operations.sparse_grid.isHierarchicalAncestorByLevelIndex (   leveli,
  indexi,
  levelj,
  indexj 
)
def python.uq.operations.sparse_grid.isValid1d (   grid,
  level,
  index 
)
def python.uq.operations.sparse_grid.parent (   grid,
  gp,
  d 
)
def python.uq.operations.sparse_grid.sub (   alpha,
  alphas 
)

Variable Documentation

list python.uq.operations.sparse_grid.bsplineBoundaryGridTypes
Initial value:
1 = [GridType_BsplineBoundary,
2  GridType_BsplineClenshawCurtis]
python.uq.operations.sparse_grid.bsplineGridTypes = bsplineNoBoundaryGridTypes+bsplineBoundaryGridTypes
list python.uq.operations.sparse_grid.bsplineNoBoundaryGridTypes
Initial value:
1 = [GridType_Bspline,
2  GridType_ModBspline,
3  GridType_ModBsplineClenshawCurtis]
list python.uq.operations.sparse_grid.linearBoundaryGridTypes
Initial value:
1 = [GridType_LinearBoundary,
2  GridType_LinearL0Boundary,
3  GridType_LinearTruncatedBoundary]
python.uq.operations.sparse_grid.linearGridTypes = linearNoBoundaryGridTypes+linearBoundaryGridTypes
list python.uq.operations.sparse_grid.linearNoBoundaryGridTypes
Initial value:
1 = [GridType_Linear,
2  GridType_ModLinear]
list python.uq.operations.sparse_grid.polyBoundaryGridTypes = [GridType_PolyBoundary]
python.uq.operations.sparse_grid.polyGridTypes = polyNoBoundaryGridTypes+polyBoundaryGridTypes
list python.uq.operations.sparse_grid.polyNoBoundaryGridTypes
Initial value:
1 = [GridType_Poly,
2  GridType_ModPoly]