Algorithm Search⌘K

Algorithmcore

Saltelli sampling scheme

Also called Saltelli estimator.

Estimates all first order and total Sobol indices from two sample matrices and their column swaps, at N(d + 2) model runs, or N(2d + 2) with second order indices.

Time
O(N d F + N d^2) worst
Space
O(N d) extra
Where
F = the cost of one model run; N = the number of rows of each sample matrix; d = the number of inputs
Properties
randomizednot exactnot iterativerandomized
Origin
Andrea Saltelli, Ilya M. Sobol, Michiel J. W. Jansen, Toshimitsu Homma, 2002

The Saltelli sampling scheme estimates all first order and all total Sobol indices of a model with dd independent inputs from one set of N(d+2)N(d + 2) model runs. It draws two independent sample matrices AA and BB with NN rows, and builds dd more matrices ABiAB_i: the matrix AA with its column ii taken from BB. Two rows that share all inputs but xix_i tell how much the output moves with xix_i alone, and two rows that share only xix_i tell how much of the output is fixed by xix_i. Averages of products and squared differences of the outputs then give unbiased estimates of the conditional variances in the definitions. The scheme is a design of model runs. It is not the Sobol sequence, a low discrepancy point set by the same author, although the rows of AA and BB are often taken from one, which turns the plain Monte Carlo estimate into quasi-Monte Carlo integration.

In plain words

You want to know which inputs of a model matter most. A simple way is slow: fix one input, vary all the others many times, and repeat for many values of the fixed input. The Saltelli scheme gets the same numbers with far fewer runs.

Make two random tables of inputs. Then, for each input, make a mixed table: the first table with that one column copied from the second. Run the model on every row of every table. If changing one column changes the output a lot, the input matters a lot in total. If the second table and the mixed table, which share only that column, give outputs that rise and fall together, the input matters a lot on its own. A few averages turn these comparisons into shares of the output spread.

The problem

The input is a model Q=f(ξ)Q = f(\xi) with independent inputs ξ=(ξ1,…,ξd)\xi = (\xi_1, \ldots, \xi_d) of known laws, and D=Var(Q)>0D = \mathrm{Var}(Q) > 0. The output is estimates of the first order and the total indices

Si=Var(E[Q∣ξi])D,STi=E[Var(Q∣ξ∼i)]D,i=1,…,d,S_i = \frac{\mathrm{Var}(\mathbb{E}[Q \mid \xi_i])}{D}, \qquad S_{Ti} = \frac{\mathbb{E}[\mathrm{Var}(Q \mid \xi_{\sim i})]}{D}, \qquad i = 1, \ldots, d,

where ξ∼i\xi_{\sim i} is the vector of all inputs except ξi\xi_i. The cost is the number of model runs; everything else is cheap.

The algorithm

  1. SALTELLI(f, d, N, DRAW)
  2. 1A, B ← two independent N × d matrices; each row is a draw of ξ by DRAW
  3. 2y_A ← f(rows of A), y_B ← f(rows of B) ▷ 2N runs
  4. 3D ← sample variance of the 2N values y_A, y_B
  5. 4for i = 1..d do
  6. 5AB_i ← A with its column i replaced by column i of B
  7. 6y_ABi ← f(rows of AB_i) ▷ N runs
  8. 7t1_j ← y_B[j] (y_ABi[j] - y_A[j]) for j = 1..N
  9. 8t2_j ← (y_A[j] - y_ABi[j])^2 / 2 for j = 1..N
  10. 9S_i ← mean(t1) / D, S_Ti ← mean(t2) / D
  11. 10return S_1..S_d, S_T1..S_Td and the run count N(d + 2)

Line L5 is the column swap. A row of ABiAB_i shares ξ∼i\xi_{\sim i} with the same row of AA and only ξi\xi_i with the same row of BB. Line L7 is the first order estimator of Saltelli et al. (2010): given ξi\xi_i, the outputs of BB and ABiAB_i are independent with the common mean E[Q∣ξi]\mathbb{E}[Q \mid \xi_i], so the mean of their product is E[E[Q∣ξi]2]\mathbb{E}[\mathbb{E}[Q \mid \xi_i]^2], and subtracting yAy_A removes E[Q]2\mathbb{E}[Q]^2. Line L8 is the total estimator of Jansen (1999): given ξ∼i\xi_{\sim i}, the outputs of AA and ABiAB_i are two independent draws, and half the mean squared difference of two such draws is the conditional variance. Line L3 uses all 2N2N independent outputs for the denominator.

Example

The Ishigami function f(x)=sin⁡x1+7sin⁡2x2+0.1 x34sin⁡x1f(x) = \sin x_1 + 7 \sin^2 x_2 + 0.1\, x_3^4 \sin x_1 with inputs uniform on [−π,π]3[-\pi, \pi]^3 is a standard test. Its exact values are E[Q]=3.5\mathbb{E}[Q] = 3.5, D=13.84459D = 13.84459 and

input SiS_i exact STiS_{Ti} exact
x1x_1 0.3139 0.5576
x2x_2 0.4424 0.4424
x3x_3 0 0.2437

They follow from V1=12(1+0.1π4/5)2V_1 = \frac{1}{2}(1 + 0.1\pi^4/5)^2, V2=49/8V_2 = 49/8 and the interaction V13=0.01 π8(1/18−1/50)V_{13} = 0.01\, \pi^8 (1/18 - 1/50). The input x3x_3 has no effect alone, but acts through its product with sin⁡x1\sin x_1; x2x_2 has no interaction.

A run with random.Random(2002) gives (a measurement):

NN runs S^1,S^2,S^3\widehat{S}_1, \widehat{S}_2, \widehat{S}_3 S^T1,S^T2,S^T3\widehat{S}_{T1}, \widehat{S}_{T2}, \widehat{S}_{T3}
1000 5000 0.3074, 0.4637, -0.0141 0.5011, 0.4624, 0.2546
10000 50000 0.3092, 0.4503, 0.0118 0.5562, 0.4425, 0.2414

At N=10000N = 10000 the standard errors of the first order estimates are about 0.0145, 0.0124 and 0.0112, and those of the total estimates about 0.0151, 0.0050 and 0.0049, so all six estimates are within one or two standard errors of the exact values. The estimate −0.0141-0.0141 at N=1000N = 1000 is a negative estimate of a zero index, which is a normal sampling error. The gap S^T3−S^3\widehat{S}_{T3} - \widehat{S}_3 shows the interaction of x3x_3 at both sizes.

Correctness

The claim is that the means in line L9 are unbiased for the numerators Vi=Var(E[Q∣ξi])V_i = \mathrm{Var}(\mathbb{E}[Q \mid \xi_i]) and VTi=E[Var(Q∣ξ∼i)]V_{Ti} = \mathbb{E}[\mathrm{Var}(Q \mid \xi_{\sim i})], that DD is unbiased for the variance, and that the ratios converge almost surely to SiS_i and STiS_{Ti} as N→∞N \to \infty. The key fact is that a row of ABiAB_i has the law of ξ\xi, because the inputs are independent; it shares exactly the right inputs with the rows of AA and BB, and the two conditional independence arguments above then give the two numerators. The strong law of large numbers gives convergence, and the central limit theorem gives standard errors of order N−1/2N^{-1/2}. The full proof is in the proof file. The ratios themselves have a bias of order 1/N1/N.

Proof: The Saltelli estimators of the first order and total variances are unbiasedfull

We assume exact arithmetic and exact random numbers. The input ξ=(ξ1,…,ξd)\xi = (\xi_1, \ldots, \xi_d) has independent components, and Q=f(ξ)Q = f(\xi) is square integrable with D=Var(Q)>0D = \mathrm{Var}(Q) > 0. For a set uu of indices, ξu\xi_u is the vector of the components in uu, and ∼i\sim i is the set of all indices except ii. The Sobol indices are Si=Vi/DS_i = V_i / D and STi=VTi/DS_{Ti} = V_{Ti} / D with

Vi=Var(E[Q∣ξi]),VTi=E[Var(Q∣ξ∼i)].V_i = \mathrm{Var}\big(\mathbb{E}[Q \mid \xi_i]\big), \qquad V_{Ti} = \mathbb{E}\big[\mathrm{Var}(Q \mid \xi_{\sim i})\big].

One row jj of the sample matrices gives two independent draws aa and bb of ξ\xi and, for each ii, the mixed point c(i)=(a∼i,bi)c^{(i)} = (a_{\sim i}, b_i): the row of AA with its component ii taken from BB. Different rows are independent.

Lemma 1 (a mixed point has the input law). c(i)c^{(i)} has the law of ξ\xi. The pair (b,c(i))(b, c^{(i)}) shares the component ii and nothing else, and the pair (a,c(i))(a, c^{(i)}) shares all components except ii.

Proof. The components of c(i)c^{(i)} are aka_k for k≠ik \ne i and bib_i. They are independent, because they come from different components or from different draws, and each has the law of ξk\xi_k. As the components of ξ\xi are independent, the joint law is the law of ξ\xi. The other two claims hold by construction. □\square

Lemma 2 (the first order numerator). E[f(b)(f(c(i))−f(a))]=Vi\mathbb{E}\big[f(b) \big(f(c^{(i)}) - f(a)\big)\big] = V_i.

Proof. Let gi(x)=E[Q∣ξi=x]g_i(x) = \mathbb{E}[Q \mid \xi_i = x]. Given bib_i, the values f(b)f(b) and f(c(i))f(c^{(i)}) depend on the independent vectors b∼ib_{\sim i} and a∼ia_{\sim i}, so they are conditionally independent with the same conditional mean gi(bi)g_i(b_i). So E[f(b)f(c(i))]=E[gi(bi)2]\mathbb{E}[f(b) f(c^{(i)})] = \mathbb{E}[g_i(b_i)^2]. The draws aa and bb are independent, so E[f(b)f(a)]=E[Q]2=E[gi(ξi)]2\mathbb{E}[f(b) f(a)] = \mathbb{E}[Q]^2 = \mathbb{E}[g_i(\xi_i)]^2. The difference is E[gi2]−E[gi]2=Var(gi(ξi))=Vi\mathbb{E}[g_i^2] - \mathbb{E}[g_i]^2 = \mathrm{Var}(g_i(\xi_i)) = V_i. □\square

Lemma 3 (the total numerator of Jansen). 12E[(f(a)−f(c(i)))2]=VTi\frac{1}{2} \mathbb{E}\big[\big(f(a) - f(c^{(i)})\big)^2\big] = V_{Ti}.

Proof. Given a∼ia_{\sim i}, the values f(a)f(a) and f(c(i))f(c^{(i)}) depend on the independent components aia_i and bib_i, which have the same law. So they are conditionally independent and identically distributed with the variance Var(Q∣ξ∼i=a∼i)\mathrm{Var}(Q \mid \xi_{\sim i} = a_{\sim i}). For two such variables X,X′X, X', 12E[(X−X′)2]=Var(X)\frac{1}{2}\mathbb{E}[(X - X')^2] = \mathrm{Var}(X). Take the expectation over a∼ia_{\sim i}. □\square

Theorem (unbiased numerators, consistent indices). Lines L7 and L8 give the terms t1,j=f(bj)(f(cj(i))−f(aj))t_{1, j} = f(b_j)(f(c^{(i)}_j) - f(a_j)) and t2,j=12(f(aj)−f(cj(i)))2t_{2, j} = \frac{1}{2}(f(a_j) - f(c^{(i)}_j))^2 of rows j=1,…,Nj = 1, \ldots, N. Their means V^i\widehat{V}_i and V^Ti\widehat{V}_{Ti} are unbiased for ViV_i and VTiV_{Ti}. Line L3 gives an unbiased estimate D^\widehat{D} of DD. As N→∞N \to \infty, V^i/D^→Si\widehat{V}_i / \widehat{D} \to S_i and V^Ti/D^→STi\widehat{V}_{Ti} / \widehat{D} \to S_{Ti} almost surely.

Proof. The rows are independent, so the means are unbiased by Lemmas 2 and 3. The 2N2N values f(aj)f(a_j) and f(bj)f(b_j) are independent draws of QQ, so their sample variance with the divisor 2N−12N - 1 is unbiased for DD. The terms of each row are independent and identically distributed with a finite mean (the products and squares of square integrable variables are integrable), so the strong law of large numbers gives almost sure convergence of each mean. A ratio of two convergent sequences converges to the ratio of the limits when the limit of the denominator is D>0D > 0. ■\blacksquare

The ratios are not unbiased for finite NN, because the expectation of a ratio is not the ratio of the expectations. The bias is of order 1/N1/N, smaller than the standard error of order N−1/2N^{-1/2}.

Corollary (an input that the model ignores). If ff does not depend on ξi\xi_i, then f(cj(i))=f(aj)f(c^{(i)}_j) = f(a_j) for every row, so both estimates of input ii are exactly zero, for every NN.

Corollary (the run count). The model runs on the rows of AA, BB and the dd mixed matrices, which is N(d+2)N(d + 2) runs. All dd first order and dd total estimates use these same runs.

Error bars. If f(ξ)2f(\xi)^2 is square integrable, the terms t1,jt_{1, j} and t2,jt_{2, j} have finite variance, and by the central limit theorem V^i\widehat{V}_i is approximately normal with the standard error s(t1)/Ns(t_1)/\sqrt{N}, where ss is the sample standard deviation of the terms. The code returns this standard error divided by D^\widehat{D}, and a relative standard error of D^\widehat{D}. The tests compare the estimates with the exact values within four times the sum of the two parts. These error bars are asymptotic, not bounds.

What is not proved. Lemma 1 needs independent inputs. If the components of ξ\xi are dependent, a mixed point c(i)c^{(i)} does not have the law of ξ\xi, the model is evaluated at inputs that the real system cannot take, and the estimates are not estimates of conditional variances.

Complexity

The scheme makes 2N2N runs in line L2 and NN in each of the dd passes of line L6, which is N(d+2)N(d + 2) runs, or O(NdF)O(N d F) time for a run cost FF. Building each ABiAB_i copies NN rows of length dd, which is O(Nd2)O(N d^2) arithmetic in the real RAM model; a version that changes one entry of a row in place needs only O(Nd)O(N d). Lines L7 to L9 cost O(N)O(N) per input. The matrices AA and BB take O(Nd)O(N d) space, and the outputs O(N)O(N) per pass. A double loop that estimates each ViV_i by an inner and an outer sample needs NouterNinnerN_{\mathrm{outer}} N_{\mathrm{inner}} runs per input instead.

Properties

  • Unbiased numerators. Both numerators are unbiased for every NN; the indices are ratios and are only consistent.
  • Exact zeros. If ff does not depend on ξi\xi_i, then yABi=yAy_{AB_i} = y_A row by row, and both estimates of input ii are exactly 0.
  • One design for all indices. The same runs give all 2d2d indices; adding an input costs NN more runs.
  • Randomized. The estimates are random; negative estimates of small indices and first order estimates above the total estimate happen at small NN.
  • Independent inputs only. The mixed rows are draws of ξ\xi only if the inputs are independent.

Variants and improvements

  • Second order indices. Add the dd matrices BAiBA_i, the matrix BB with its column ii from AA. A row of BAiBA_i and the same row of ABjAB_j share exactly ξi\xi_i and ξj\xi_j, so the mean of yBAiyABjy_{BA_i} y_{AB_j} minus E[Q]2\mathbb{E}[Q]^2 estimates Var(E[Q∣ξi,ξj])\mathrm{Var}(\mathbb{E}[Q \mid \xi_i, \xi_j]), and subtracting ViV_i and VjV_j gives VijV_{ij}. This costs N(2d+2)N(2d + 2) runs for all first order, second order and total indices (Saltelli 2002).
  • Other estimators. Sobol's original first order estimator is the mean of the products of two outputs that share only ξi\xi_i, minus the squared sample mean; it loses precision when ∣E[Q]∣|\mathbb{E}[Q]| is large against the standard deviation. Other total estimators exist, for example that of Homma and Saltelli; Saltelli et al. (2010) compare several and recommend Jansen's.
  • Quasi-random rows. Take the rows of AA and BB from one 2d2d-dimensional Sobol sequence, the first dd coordinates for AA and the last dd for BB. For smooth models the error then falls faster than N−1/2N^{-1/2}.
  • Error bars by bootstrap. Resample the rows with replacement and recompute the indices, to get confidence intervals that include the error of DD.
  • Surrogate models. For an expensive model, compute the indices of a polynomial chaos expansion of it instead; they follow from its coefficients without sampling.

When to use it

Use the Saltelli scheme when you need quantitative first order and total indices with error bars, the inputs are independent, and you can afford N(d+2)N(d + 2) runs with NN in the hundreds to thousands. Use the Morris method first when dd is large and runs are expensive, to screen out the inputs that do not matter. Use the Fourier amplitude sensitivity test when the model is smooth and the cost per index must be lower, and a bias without error bars is acceptable. Use a polynomial chaos expansion when the model is smooth in few inputs and a surrogate fits it well. For dependent inputs, none of these variance splits holds; use a method built for dependence, for example indices based on the Shapley value.

Pitfalls

  • Dependent inputs. Line L5 builds rows with ξi\xi_i from one draw and ξ∼i\xi_{\sim i} from another. With dependent inputs these rows can be inputs that the real system never takes, and the estimates are not conditional variances. Transform to independent inputs first, if the model allows it.
  • The variance of one matrix. Line L3 can use yAy_A alone, but then DD comes from NN values instead of 2N2N, and its sampling error is larger at no saving in runs. Use the pooled values.
  • The original first order estimator with a large mean. Replacing line L7 by the mean of yB yABiy_B\, y_{AB_i} minus the squared sample mean subtracts two large numbers when ∣E[Q]∣|\mathbb{E}[Q]| is large, and the estimate loses digits. Line L7 subtracts yAy_A inside the sum, which is robust to a shift of ff.
  • Swapping the roles of A and B. Line L7 pairs ABiAB_i with BB (shared ξi\xi_i) and line L8 pairs it with AA (shared ξ∼i\xi_{\sim i}). If the matrix is built as BB with column ii from AA, the two pairings must swap too, or the first order estimator estimates the total one and the other way round.
  • Reading noise as a result. A small negative S^i\widehat{S}_i, or S^i>S^Ti\widehat{S}_i > \widehat{S}_{Ti}, is sampling error at small NN. Report the indices with their standard errors.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

saltelli_sampling_scheme.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/saltelli-sampling-scheme/. The authors are listed in prov/SEW99Y.jsonl.
"""First order and total Sobol indices by the Saltelli sampling scheme.

Two independent N by d sample matrices A and B give d more matrices AB_i:
the matrix A with its column i taken from B. The model runs on all rows of A,
B and AB_1, ..., AB_d, which is N (d + 2) runs. The estimators are those of
Saltelli et al. 2010: the first order numerator

    V_i = (1/N) sum_j f(B)_j (f(AB_i)_j - f(A)_j)

and the total numerator of Jansen 1999

    VT_i = (1/(2N)) sum_j (f(A)_j - f(AB_i)_j)^2,

both divided by the sample variance of the 2N values f(A) and f(B).

The inputs must be independent. The caller gives the map from the unit cube
to the input law, one coordinate at a time.
"""

import math
import random
from typing import Callable, Sequence

Model = Callable[[Sequence[float]], float]


def ishigami(x: Sequence[float], a: float = 7.0, b: float = 0.1) -> float:
    """The Ishigami function sin x1 + a sin^2 x2 + b x3^4 sin x1, inputs uniform on [-pi, pi]^3."""
    return math.sin(x[0]) + a * math.sin(x[1]) ** 2 + b * x[2] ** 4 * math.sin(x[0])


def ishigami_exact(a: float = 7.0, b: float = 0.1) -> dict:
    """The exact mean, variance, first order and total indices of the Ishigami function."""
    pi = math.pi
    v1 = 0.5 * (1 + b * pi**4 / 5) ** 2
    v2 = a * a / 8
    v13 = b * b * pi**8 * (1 / 18 - 1 / 50)
    v = v1 + v2 + v13
    return {
        "mean": a / 2,
        "variance": v,
        "S": [v1 / v, v2 / v, 0.0],
        "ST": [(v1 + v13) / v, v2 / v, v13 / v],
    }


def saltelli(f: Model, d: int, n: int, rng: random.Random, to_input: Callable[[float, int], float]) -> dict:
    """Estimate S_i and ST_i for i = 1..d with N (d + 2) model runs.

    to_input(u, i) maps a uniform number u in [0, 1) to coordinate i of the input.
    Returns the indices, their standard errors (with the variance taken as exact)
    and the number of model runs.
    """
    a = [[to_input(rng.random(), i) for i in range(d)] for _ in range(n)]  # @line L1
    b = [[to_input(rng.random(), i) for i in range(d)] for _ in range(n)]
    fa = [f(row) for row in a]  # @line L2
    fb = [f(row) for row in b]
    runs = 2 * n
    both = fa + fb
    mean = sum(both) / (2 * n)
    var = sum((y - mean) ** 2 for y in both) / (2 * n - 1)  # @line L3
    s, st, s_err, st_err = [], [], [], []
    for i in range(d):  # @line L4
        fab = []
        for j in range(n):
            row = list(a[j])  # @line L5
            row[i] = b[j][i]
            fab.append(f(row))  # @line L6
        runs += n
        t1 = [fb[j] * (fab[j] - fa[j]) for j in range(n)]  # @line L7
        t2 = [0.5 * (fa[j] - fab[j]) ** 2 for j in range(n)]  # @line L8
        s.append(sum(t1) / n / var)  # @line L9
        st.append(sum(t2) / n / var)
        s_err.append(_std_error(t1) / var)
        st_err.append(_std_error(t2) / var)
    sq = [((y - mean) ** 2 - var) ** 2 for y in both]
    var_rel_err = math.sqrt(sum(sq) / (2 * n - 1) / (2 * n)) / var
    return {"S": s, "ST": st, "S_err": s_err, "ST_err": st_err, "runs": runs, "variance": var, "variance_rel_err": var_rel_err}  # @line L10


def _std_error(t: Sequence[float]) -> float:
    n = len(t)
    m = sum(t) / n
    return math.sqrt(sum((x - m) ** 2 for x in t) / (n - 1) / n)


def brute_force_first_order(f: Model, d: int, i: int, n_outer: int, n_inner: int, rng: random.Random, to_input) -> float:
    """Var(E[Q | x_i]) by a double loop: n_outer values of x_i, n_inner samples of the rest for each.

    The inner means carry noise of variance about Var(Q | x_i) / n_inner, which this subtracts.
    """
    cond_means, cond_vars = [], []
    for _ in range(n_outer):
        xi = to_input(rng.random(), i)
        ys = []
        for _ in range(n_inner):
            x = [to_input(rng.random(), k) for k in range(d)]
            x[i] = xi
            ys.append(f(x))
        m = sum(ys) / n_inner
        cond_means.append(m)
        cond_vars.append(sum((y - m) ** 2 for y in ys) / (n_inner - 1))
    mm = sum(cond_means) / n_outer
    var_of_means = sum((m - mm) ** 2 for m in cond_means) / (n_outer - 1)
    return var_of_means - sum(cond_vars) / n_outer / n_inner
test_saltelli_sampling_scheme.py 64 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/saltelli-sampling-scheme/. The authors are listed in prov/SEW99Y.jsonl.
import math
import random

from saltelli_sampling_scheme import brute_force_first_order, ishigami, ishigami_exact, saltelli


def unif_pi(u, i):
    return -math.pi + 2 * math.pi * u


def unit(u, i):
    return u


def tolerance(res, key, i):
    """Four standard errors of the numerator, plus four of the variance in the denominator."""
    return 4 * (res[key + "_err"][i] + abs(res[key][i]) * res["variance_rel_err"])


def test_ishigami_exact_values():
    ex = ishigami_exact()
    assert abs(ex["variance"] - 13.84459) < 1e-5
    assert [round(x, 4) for x in ex["S"]] == [0.3139, 0.4424, 0.0]
    assert [round(x, 4) for x in ex["ST"]] == [0.5576, 0.4424, 0.2437]


def test_ishigami_indices_within_four_standard_errors():
    ex = ishigami_exact()
    res = saltelli(ishigami, 3, 10000, random.Random(2002), unif_pi)
    assert res["runs"] == 10000 * (3 + 2)
    for i in range(3):
        assert abs(res["S"][i] - ex["S"][i]) < tolerance(res, "S", i)
        assert abs(res["ST"][i] - ex["ST"][i]) < tolerance(res, "ST", i)
    # x3 acts only through its interaction with x1
    assert res["ST"][2] - res["S"][2] > 0.15


def test_linear_model_has_equal_first_order_and_total_indices():
    c = [1.0, 2.0, 3.0]
    f = lambda x: sum(ci * xi for ci, xi in zip(c, x))  # noqa: E731
    res = saltelli(f, 3, 5000, random.Random(5), unit)
    total = sum(ci * ci for ci in c)
    for i in range(3):
        exact = c[i] ** 2 / total
        assert abs(res["S"][i] - exact) < tolerance(res, "S", i)
        assert abs(res["ST"][i] - exact) < tolerance(res, "ST", i)


def test_an_input_that_the_model_ignores_gets_exactly_zero():
    f = lambda x: x[0] ** 2 + math.sin(x[0])  # noqa: E731
    res = saltelli(f, 3, 500, random.Random(8), unit)
    assert res["S"][1] == 0.0 and res["ST"][1] == 0.0
    assert res["S"][2] == 0.0 and res["ST"][2] == 0.0
    assert abs(res["ST"][0] - 1.0) < tolerance(res, "ST", 0)


def test_first_order_agrees_with_the_double_loop_estimate():
    ex = ishigami_exact()
    res = saltelli(ishigami, 3, 4000, random.Random(13), unif_pi)
    v1 = brute_force_first_order(ishigami, 3, 0, 300, 100, random.Random(17), unif_pi)
    s1_brute = v1 / ex["variance"]
    assert abs(res["S"][0] - s1_brute) < 0.08

History

Sobol published the Monte Carlo estimate of first order indices with two independent samples in Russian in 1990; the English translation appeared in 1993. Homma and Saltelli introduced the total sensitivity index in 1996, with its estimate. Jansen gave the estimator of the total variance from squared differences in 1999. Saltelli showed in 2002 how one design of N(d+2)N(d + 2) runs gives all first order and total indices, and N(2d+2)N(2d + 2) runs also all second order ones. Saltelli and coauthors compared the estimators in 2010 and recommended the forms of lines L7 and L8. Ishigami and Homma had proposed the test function of the example in 1990.

References

  1. Andrea Saltelli, Making best use of model evaluations to compute sensitivity indices, Computer Physics Communications 145(2), 2002, 280-297, the design with the matrices A, B and the column swaps, N(d + 2) runs for first order and total indices and N(2d + 2) runs with second order indices
  2. Andrea Saltelli, Paola Annoni, Ivano Azzini, Francesca Campolongo, Marco Ratto and Stefano Tarantola, Variance based sensitivity analysis of model output. Design and estimator for the total sensitivity index, Computer Physics Communications 181(2), 2010, 259-270, the comparison of estimators, the first order estimator f(B)(f(AB_i) - f(A)) and the recommendation of the Jansen total estimator
  3. Michiel J. W. Jansen, Analysis of variance designs for model output, Computer Physics Communications 117(1-2), 1999, 35-43, the estimator of the total variance from squared differences of runs that differ in one input
  4. Toshimitsu Homma and Andrea Saltelli, Importance measures in global sensitivity analysis of nonlinear models, Reliability Engineering and System Safety 52(1), 1996, 1-17, the total sensitivity index and its Monte Carlo estimate
  5. Ilya M. Sobol, Sensitivity estimates for nonlinear mathematical models, Mathematical Modeling and Computational Experiment 1(4), 1993, 407-414, the Monte Carlo estimate of the first order indices with two independent samples (translation of the 1990 Russian paper)
  6. Andrea Saltelli, Marco Ratto, Terry Andres, Francesca Campolongo, Jessica Cariboni, Debora Gatelli, Michaela Saisana and Stefano Tarantola, Global Sensitivity Analysis, The Primer, Wiley, 2008, Chapter 4 (variance-based methods and the computation of first order and total indices)
  7. Tsutomu Ishigami and Toshimitsu Homma, An importance quantification technique in uncertainty analysis for computer models, Proceedings of the First International Symposium on Uncertainty Modeling and Analysis (ISUMA 1990), IEEE, 1990, 398-403, the test function sin x1 + a sin^2 x2 + b x3^4 sin x1

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example