adaptive_approximate_sparse_grid

pyapprox.approximate.adaptive_approximate_sparse_grid(fun, univariate_variables, callback=None, refinement_indicator=<function variance_refinement_indicator>, univariate_quad_rule_info=None, max_nsamples=100, tol=0, verbose=0, config_variables_idx=None, config_var_trans=None, cost_function=None, max_level_1d=None)[source]

Compute a sparse grid approximation of a function.

Parameters
funcallable

The function to be minimized

fun(z) -> np.ndarray

where z is a 2D np.ndarray with shape (nvars,nsamples) and the output is a 2D np.ndarray with shape (nsamples,nqoi)

univariate_variableslist

A list of scipy.stats random variables of size (nvars)

callbackcallable

Function called after each iteration with the signature

callback(approx_k)

where approx_k is the current approximation object.

refinement_indicatorcallable

A function that retuns an estimate of the error of a sparse grid subspace with signature

refinement_indicator(subspace_index,nnew_subspace_samples,sparse_grid) -> float, float

where subspace_index is 1D np.ndarray of size (nvars), nnew_subspace_samples is an integer specifying the number of new samples that will be added to the sparse grid by adding the subspace specified by subspace_index and sparse_grid is the current pyapprox.adaptive_sparse_grid.CombinationSparseGrid object. The two outputs are, respectively, the indicator used to control refinement of the sparse grid and the change in error from adding the current subspace. The indicator is typically but now always dependent on the error.

univariate_quad_rule_infolist

List containing two entries. The first entry is a list (or single callable) of univariate quadrature rules for each variable with signature

quad_rule(l)->np.ndarray,np.ndarray

where the integer l specifies the level of the quadrature rule and x and w are 1D np.ndarray of size (nsamples) containing the quadrature rule points and weights, respectively.

The second entry is a list (or single callable) of growth rules with signature

growth_rule(l)->integer

where the output nsamples specifies the number of samples in the quadrature rule of level l.

If either entry is a callable then the same quad or growth rule is applied to every variable.

max_nsamplesfloat

If cost_function==None then this argument is the maximum number of evaluations of fun. If fun has configure variables

If cost_function!=None Then max_nsamples is the maximum cost of constructing the sparse grid, i.e. the sum of the cost of evaluating each point in the sparse grid.

The cost_function!=None` same behavior as ``cost_function==None can be obtained by setting cost_function = lambda config_sample: 1.

This is particularly useful if fun has configure variables and evaluating fun at these different values of these configure variables has different cost. For example if there is one configure variable that can take two different values with cost 0.5, and 1 then 10 samples of both models will be measured as 15 samples and so if max_nsamples is 19 the algorithm will not terminate because even though the number of samples is the sparse grid is 20.

tolfloat

Tolerance for termination. The construction of the sparse grid is terminated when the estimate error in the sparse grid (determined by refinement_indicator is below tol.

verboseinteger

Controls messages printed during construction.

config_variable_idxinteger

The position in a sample array that the configure variables start

config_var_transpyapprox.adaptive_sparse_grid.ConfigureVariableTransformation

An object that takes configure indices in [0,1,2,3…] and maps them to the configure values accepted by fun

cost_functioncallable

A function with signature

cost_function(config_sample) -> float

where config_sample is a np.ndarray of shape (nconfig_vars). The output is the cost of evaluating fun at config_sample. The units can be anything but the units must be consistent with the units of max_nsamples which specifies the maximum cost of constructing the sparse grid.

max_level_1dnp.ndarray (nvars)

The maximum level of the sparse grid in each dimension. If None There is no limit

Returns
resultpyapprox.approximate.ApproximateResult

Result object with the following attributes

approxpyapprox.adaptive_sparse_grid.CombinationSparseGrid

The sparse grid approximation