chaospy.quadrature.sparse_grid¶
- chaospy.quadrature.sparse_grid(order, dist, growth=None, recurrence_algorithm='stieltjes', rule='gaussian', tolerance=1e-10, scaling=3, n_max=5000)[source]¶
Smolyak sparse grid constructor.
- Args:
- order (int, numpy.ndarray):
The order of the grid. If
numpy.ndarray
, it overrides bothdim
andskew
.- dist (chaospy.distributions.baseclass.Distribution):
The distribution which density will be used as weight function.
- growth (bool, None):
If True sets the growth rule for the quadrature rule to only include orders that enhances nested samples. Defaults to the same value as
sparse
if omitted.- recurrence_algorithm (str):
Name of the algorithm used to generate abscissas and weights in case of Gaussian quadrature scheme. If omitted,
analytical
will be tried first, andstieltjes
used if that fails.- rule (str):
Rule for generating abscissas and weights. Either done with quadrature rules, or with random samples with constant weights.
- tolerance (float):
The allowed relative error in norm between two quadrature orders before method assumes convergence.
- scaling (float):
A multiplier the adaptive order increases with for each step quadrature order is not converged. Use 0 to indicate unit increments.
- n_max (int):
The allowed number of quadrature points to use in approximation.
- Returns:
- (numpy.ndarray, numpy.ndarray):
Abscissas and weights created from sparse grid rule. Flatten such that
abscissas.shape == (len(dist), len(weights))
.
- Example:
>>> distribution = chaospy.J(chaospy.Normal(0, 1), chaospy.Uniform(-1, 1)) >>> abscissas, weights = chaospy.quadrature.sparse_grid(1, distribution) >>> abscissas.round(4) array([[-1. , 0. , 0. , 0. , 1. ], [ 0. , -0.5774, 0. , 0.5774, 0. ]]) >>> weights.round(4) array([ 0.5, 0.5, -1. , 0.5, 0.5]) >>> abscissas, weights = chaospy.quadrature.sparse_grid([2, 1], distribution) >>> abscissas.round(2) array([[-1.73, -1. , -1. , -1. , 0. , 1. , 1. , 1. , 1.73], [ 0. , -0.58, 0. , 0.58, 0. , -0.58, 0. , 0.58, 0. ]]) >>> weights.round(2) array([ 0.17, 0.25, -0.5 , 0.25, 0.67, 0.25, -0.5 , 0.25, 0.17])