sensitivity.chaos¶
Polynomial chaos expansion of the output of a scan.
A polynomial chaos expansion writes an output of the model as a series of polynomials of its inputs which are orthonormal under the distributions of the inputs,
y(u) = sum over alpha of c_alpha * Psi_alpha(u),
so the mean of the output is c_0, its variance is the sum of the squares of
the other coefficients, and the variance of every group of inputs is the sum
of the squares of the coefficients whose multi-index is supported exactly on
that group (Sudret 2008). The Sobol indices follow from the coefficients
without a single further simulation: the first order index of an input is the
share of the variance of the coefficients of that input alone, its total
index the share of every coefficient which reads it, and the interaction of
two inputs the share of the coefficients supported on the pair. The
expansion is also a surrogate: PolynomialChaos.predict evaluates it at any
point of the unit cube at the cost of a polynomial.
The points of a design of sbmlsim.simulation.sampling are the image of its
unit cube under the marginals of its targets (Distribution.ppf), and the
value of a target is a monotone function of the coordinate of its own
dimension alone, so an expansion in the coordinates of the unit cube has the
indices of the inputs, whatever their distributions. The basis is therefore
the one of the uniform distribution of the unit cube, the shifted Legendre
polynomials normalized to one, and the design of the analysis needs neither
a transform of the inputs nor a basis per marginal. The inputs must be
independent, which is what the share of a variance means, so a design with a
correlation is refused.
The basis of a degree p over d inputs has (p + d)! / (p! d!) terms,
which a regression needs more points than, so the basis is truncated: the
hyperbolic norm q drops the terms of many inputs at a high degree (Blatman
and Sudret 2010, q = 1 is the full basis of the degree and q = 0.5 keeps
about the terms of one and two inputs) and max_interaction caps the number
of inputs of a term. The degree is not given but chosen per element of the
observable from the corrected leave-one-out error (Chapelle, Vapnik and
Bengio 2002; Blatman and Sudret 2010), which needs no simulation beyond the
ones of the fit and which the result reports as the variable <observable>.loo
of every element, so a fit which the points do not support is visible rather
than silent. The expansions of the candidate degrees share the design matrix
and every element of an observable is fitted at once, one decomposition per
degree.
References
Sudret B. Global sensitivity analysis using polynomial chaos expansions. Reliability Engineering & System Safety. 2008;93(7):964-979.
Blatman G, Sudret B. An adaptive algorithm to build up sparse polynomial chaos expansions for stochastic finite element analysis. Probabilistic Engineering Mechanics. 2010;25(2):183-197.
Chapelle O, Vapnik V, Bengio Y. Model selection for small sample regression. Machine Learning. 2002;48(1):231-241.
PolynomialChaos
dataclass
¶
A polynomial chaos expansion of the elements of an output.
The expansion of every element shares the basis multi_indices, in which
the coefficients of the terms above the degree of an element are zero, so
coefficients is one array whatever the degrees are.
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
tuple[str, ...]
|
the inputs, in the order of the columns of the multi-indices. |
multi_indices |
ndarray
|
the multi-indices of the basis, a row per term. |
coefficients |
ndarray
|
the coefficients over |
loo |
ndarray
|
the corrected leave-one-out error of every element, the share of the variance of its values the expansion does not predict. |
degree |
ndarray
|
the total degree of the basis of every element. |
variance
property
¶
Get the variance of every element, the squares of the other coefficients.
second_order
¶
Get the interaction of every pair of inputs.
Returns:
| Type | Description |
|---|---|
ndarray
|
The indices over |
ndarray
|
|
ndarray
|
Sobol analysis. |
predict
¶
Evaluate the expansion of every element at points of the unit cube.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
the points, a row per point and a column per input. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The values, a row per point and a column per element. |
expansion
¶
Get the multi-indices of a truncated basis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
int
|
the number of inputs. |
required |
degree
|
int
|
the largest total degree, not negative. |
required |
q
|
float
|
the exponent of the hyperbolic truncation, in |
1.0
|
max_interaction
|
int | None
|
the largest number of inputs of a term, every number by default. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The multi-indices, a row per term, ordered by their total degree and |
ndarray
|
then by the inputs they read; the first row is the constant term. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the arguments are out of range or the basis is larger
than |
legendre_values
¶
Evaluate the orthonormal Legendre polynomials of the unit interval.
The polynomials are sqrt(2k + 1) P_k(2u - 1) of the Legendre
polynomials P_k, which are orthonormal on [0, 1] under the uniform
distribution, computed with their recurrence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
the points, a row per point and a column per input. |
required |
max_degree
|
int
|
the largest degree, not negative. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The values over |
design_matrix
¶
Evaluate the basis at the points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
the points, a row per point and a column per input. |
required |
multi_indices
|
ndarray
|
the multi-indices of the basis, a row per term. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The values of the terms, a row per point and a column per term. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the points and the multi-indices have different numbers of inputs. |
fit_chaos
¶
Fit a chaos expansion of every element of an output on the unit cube.
The candidate degrees are 1..degree; every element keeps the one of the
smallest corrected leave-one-out error, the bases of the candidates being
the prefixes of the basis of degree, which are ordered by their total
degree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
ndarray
|
the points of the unit cube, a row per point and a column per input. |
required |
y
|
ndarray
|
the values, a row per point and a column per element. |
required |
degree
|
int
|
the largest total degree of the basis. |
5
|
q
|
float
|
the exponent of the hyperbolic truncation, see |
1.0
|
max_interaction
|
int | None
|
the largest number of inputs of a term. |
None
|
parameters
|
Sequence[str] | None
|
the names of the inputs, |
None
|
Returns:
| Type | Description |
|---|---|
PolynomialChaos
|
The expansion. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the points and the values do not match, or no candidate
degree is supported by the points ( |
pce
¶
pce(
result,
*,
observables=None,
degree=5,
q=1.0,
max_interaction=None,
second_order=False,
dim=None,
tolerance=None,
)
Get the Sobol indices of a scan from a polynomial chaos expansion.
The expansion of every element of every observable is fitted on the points
of the design of the scan, see the module; the indices are the shares of
the variance of its coefficients and need no simulation of their own, so
one sample of a few hundred points gives the first order and total indices
which a Sobol analysis needs n * (d + 2) simulations for.
The variables of the result are S1, ST and, with second_order, S2,
the quality of the fit of every element (loo, the corrected
leave-one-out error, and degree, the total degree of its basis) and the
mean and standard deviation of the expansion (mean, sd, in the unit of
the observable). An element whose values are constant has zero indices and
no fit, an element of a failed point has none (NaN).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ScanResult
|
the result of a scan over a design of |
required |
observables
|
Sequence[str] | None
|
the observables, every one of the result by default. |
None
|
degree
|
int
|
the largest total degree of the basis. |
5
|
q
|
float
|
the exponent of the hyperbolic truncation, see |
1.0
|
max_interaction
|
int | None
|
the largest number of inputs of a term. |
None
|
second_order
|
bool
|
whether to compute the interaction of every pair. |
False
|
dim
|
str | None
|
the dimension of the design, the only one of a design by default. |
None
|
tolerance
|
float | None
|
the tolerance of a constant element, see
|
None
|
Returns:
| Type | Description |
|---|---|
SensitivityResult
|
The sensitivity result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the scan has no such design, the design has a correlation, or no degree is supported by the points. |