Algorithmadvanced
Fourier amplitude sensitivity test
Varies all inputs along a curve with distinct frequencies and reads each input's share of variance from the Fourier spectrum of the output.
- Time
- O(d R n (F + d + n)) worst
- Space
- O(d n) extra
- Where
- F = the cost of one model run; R = the number n_r of curves per input; d = the number of inputs; n = the number n_s of points per curve
- Model
- Real RAM
- Properties
- randomizednot exactnot iterativerandomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- R. I. Cukier, C. M. Fortuin, Kurt E. Shuler, A. G. Petschek, J. H. Schaibly, Andrea Saltelli, Stefano Tarantola, Karen Chan, 1973
The Fourier amplitude sensitivity test (FAST) estimates the Sobol indices of a model by moving all inputs together along one periodic curve through the input space, each input at its own integer frequency. The output along the curve is a periodic signal, and the discrete Fourier transform of that signal splits its variance by frequency: the power at the frequency of an input and its first few harmonics is the variance due to that input alone. The extended form (eFAST) gives one input a high frequency and all others low ones, so that the same spectrum also gives the total index. The cost is model runs for inputs, and the method is exact only for models whose spectrum fits in the bands it reads.
In plain words
Turn every knob of a model back and forth at the same time, each knob at its own speed. One knob turns fast, and the others turn slowly. Record the output over one full cycle.
If the output wiggles at the fast speed, the fast knob is causing it. If the output only drifts slowly, the slow knobs are causing it. A frequency analysis of the recording tells how much of the output's spread sits at the fast speed and how much sits at the slow speeds. The share at the fast speed is what the fast knob does alone. The share at the slow speeds is what the other knobs do without it, so everything else belongs to the fast knob, alone or together with others.
Do this once for each knob, and each time make that knob the fast one.
The problem
The input is a model with independent inputs, each uniform on after a transformation, and a budget of model runs. The output is an estimate of the first order and total Sobol indices
where is all inputs except . Inputs with other laws are handled by the inverse transform of inverse transform sampling.
The algorithm
For input , the curve is
with and low frequencies for . Each is a triangle wave, and it is uniform on when is uniform. is the number of harmonics read, usually 4, and is odd. The power at frequency is , where and are the cosine and sine coefficients of the samples.
EFAST(f, d, ω_max, M, n_r, n_s)- 1
for i = 1..d do ▷ input i is the fast one - 2
ω ← ω_max for input i, and d - 1 low frequencies, spread over 1..⌊ω_max / (2M)⌋, for the others - 3
repeat n_r times, with new phases φ_k uniform on [0, 2π): - 4
x^(j) ← the curve at s_j = π(2j - n_s - 1) / n_s, j = 1..n_s - 5
y_j ← f(x^(j)) for j = 1..n_s - 6
Λ_p ← (A_p^2 + B_p^2) / 2 for p = 1..(n_s - 1) / 2 - 7
D ← Σ_p Λ_p ▷ the variance of the y_j - 8
D_i ← Σ_{q=1..M} Λ_(q ω_max) ▷ the harmonics of input i - 9
D_~i ← Σ_{p=1..⌊ω_max/2⌋} Λ_p ▷ the band of the other inputs - 10
S_i, S_Ti ← the averages over the n_r curves of D_i / D and 1 - D_~i / D return S, S_T and the run count d n_r n_s
Line L5 is the only step that runs the model. Lines L6 to L9 read the spectrum: the first order part at the multiples of up to , and the part of the other inputs in the low band. Line L10 averages over the random phases. The classic FAST of Cukier and coauthors uses one curve for all inputs, with a set of frequencies chosen so that their low harmonics do not collide, and reads only the first order indices.
Example
By hand. Let with uniform on . Its Hoeffding-Sobol terms are , and with variances , and , so , , , and . With , , and one curve per input, the frequencies are for input 1 and for input 2. A run with random.Random(1) gives, as a measurement:
| index | exact | eFAST |
|---|---|---|
| 0.1875 | 0.1856 | |
| 0.75 | 0.7535 | |
| 0.25 | 0.2457 | |
| 0.8125 | 0.8084 |
The cost is runs. The small errors are not sampling noise: along the curve is a triangle wave, whose harmonics decay like and go on above , so some power falls outside the bands of lines L8 and L9 or aliases above .
The Ishigami function. With on , the same parameters, the low frequencies 1 and 8, and random.Random(1), eFAST gives, as a measurement:
| input | exact | eFAST | exact | eFAST |
|---|---|---|---|---|
| 0.3139 | 0.3126 | 0.5576 | 0.5365 | |
| 0.4424 | 0.4437 | 0.4424 | 0.4890 | |
| 0 | 0.0221 | 0.2437 | 0.2433 |
The run count is . The first order indices are close, and the gap shows the interaction of with . The total indices carry a band bias of a few hundredths, which more phases do not remove.
Correctness
The proof file shows four facts. Each is uniform on . For odd , the sum of line L7 is exactly the sample variance of the (the discrete Parseval theorem). Along the curve, the main effect depends on only through , so all its power is at the multiples of . And is a pure harmonic. From these, the theorem: if is even and is an additive sum of cosines with , and the frequencies are distinct, then eFAST returns the exact and from one curve. For a general model, three errors remain: the power of above (truncation), the power of interaction terms that falls on the harmonics of line L8 or in the band of line L9 (interference), and aliasing of frequencies above . The method is consistent only in the band-limited sense of the theorem, and it gives no error bar.
Proof: The search curve has uniform marginals, the spectrum splits the variance, and eFAST is exact for band-limited modelsfull
We assume exact arithmetic. The inputs are independent and uniform on ; other laws are reached by a map of each component. For input , the algorithm uses the frequency for and integer frequencies for the other inputs, random phases , and the curve
It evaluates at the points , , with odd and . The power at the frequency is with and . With , line L7 sets , line L8 sets , and line L9 sets . The estimates are and .
Lemma 1 (uniform marginals). If is uniform on , each is uniform on , for every integer and every phase.
Proof. The angle modulo is uniform on one period, because covers full periods at constant speed. The map is the triangle wave: on and on . On each half period it is a bijection onto with slope , so is uniform on , and is uniform on .
Lemma 2 (discrete Parseval). For odd , is the population variance of the values.
Proof. With , , which is zero unless is a multiple of . For , the numbers are multiples of only when (or ), so the functions , , are orthogonal on the points, with the squared norms . They are orthogonal vectors in , so they are a basis, and . Then .
So line L7 needs no second pass over the data, and the Parseval theorem of the discrete Fourier transform is the reason why the spectrum splits the variance.
Lemma 3 (cosine inputs are pure harmonics). For an integer , .
Proof. With , , so . On the half period where this is . On the other one and .
Lemma 4 (the main effect along the curve). Let be the first order term of the Hoeffding-Sobol decomposition. Along the curve, is a function of alone, so its Fourier series has only the frequencies , and, for uniform on , its total power is .
Proof. depends on only through , so has the period , and a function with this period has Fourier modes only at multiples of . By Lemma 1, the mean square of over is , and its mean is zero. The total power is the mean square, by the Parseval theorem for Fourier series.
Theorem (exact for band-limited models). Let be even and
Assume that the numbers , , , are distinct. Then exactly, for every choice of phases.
Proof. By Lemma 3, along the curve . The terms of input sit at the frequencies , , which are among the harmonics , , of line L8. The terms of the other inputs sit at , so they are inside the band of line L9 and below . All the frequencies are at most . By the distinctness assumption and Lemma 2, each term contributes exactly its own power to one . So , and . By Lemma 1 and the orthogonality of on , these are the exact variance of the terms of input , the exact variance of the other terms and the exact total variance. The model is additive, so , and the estimates are equal to it.
The general case. For a model that is not band-limited, three errors appear, and none of them goes to zero as the number of random phases grows.
- Truncation. Lemma 4 puts all of at the harmonics , but line L8 keeps only . The power at is lost from and aliases into other frequencies. For a smooth the lost part decays fast in .
- Interference. The harmonics of the low frequencies of the other inputs, and their sums and differences, can land on a frequency and change in either direction. With the cut , the first harmonics of each other input stay below ; higher harmonics and combinations of several inputs can still reach .
- The band of the other inputs. Line L9 assumes that all power of the terms without is at frequencies up to and that all terms with are above it. A term with has frequencies , which are above if the combinations are small. Power of the other inputs above counts as part of the total effect of , so tends to be too large in that case.
The random phases average the interference over different curves. They do not remove the band errors, which come from the frequencies themselves. So eFAST is a consistent method only in the band-limited sense of the theorem. For a general model it has a bias that depends on , and the frequency choice, and it gives no error bar.
What is not proved. The code places the low frequencies evenly in . This choice is a heuristic, as is the choice . If two other inputs get the same frequency, which happens when there are more than of them, their terms share a frequency and add with phases that depend on the curve, so the variance along one curve can differ from , and both estimates of input change with it.
Complexity
The method makes model runs, with , for example for the Ishigami example. Building one point costs , and the spectrum of line L6 by direct sums costs per curve, so the total time is in the real RAM model. A fast Fourier transform reduces the spectrum to , but the model runs dominate in practice. The extra space is for the points of one curve. The run count does not depend on the number of interactions, and it is comparable to the runs of the Saltelli sampling scheme for close to .
Properties
- First order and total indices from one spectrum. eFAST reads and from the same runs of curve .
- Deterministic sampling. The points are on a curve, not random; only the phases are random.
- Exact for band-limited additive models, as in the theorem of the proof file.
- Biased for general models. The truncation and interference errors are systematic; averaging over phases reduces only the part that changes with the phases.
- Inputs must be independent. The variance split uses the Hoeffding-Sobol decomposition, which needs independent inputs.
Variants and improvements
- Classic FAST. Cukier and coauthors (1973) use one curve with incommensurate, or in practice integer and interference-free, frequencies for all inputs and read only the first order indices. The needed grows fast with , which limits classic FAST to a few tens of inputs.
- Extended FAST. Saltelli, Tarantola and Chan (1999) give each input its own curve with one high frequency, read the total index from the low band, and repeat with random phases.
- Random balance designs. One curve with the same frequency for all inputs, with the points permuted independently for each input; the first order indices of all inputs come from runs in total.
- Other curves. The curve of Cukier and coauthors was with a transformation chosen for the input law; the triangle wave of eFAST makes the marginals exactly uniform.
When to use it
Use eFAST when the model has a few to a few tens of independent inputs, runs are cheap enough for a few thousand evaluations, and the first order and total indices are both needed. The Saltelli sampling scheme has error bars by the central limit theorem and no band bias, so it is the safer choice when an error estimate matters. With many inputs, screen first with the Morris method. With a smooth model, a polynomial chaos expansion gives all Sobol indices from its coefficients.
Pitfalls
- Low frequencies too close. If the low frequencies of the other inputs are small and close, the curve covers their subcube badly and their interference changes with the phases. For the Ishigami function with low frequencies 1 and 2, came out between 0.35 and 0.40 depending on the phases, against 0.4424, a measurement; spreading them to 1 and 8 in line L2 fixed it.
- An even number of points. With even, the frequency has only a cosine term, and the sum of line L7 is no longer the sample variance. Keep odd.
- Too few points. If , the harmonics alias onto lower frequencies, and line L8 reads the wrong power.
- Too few harmonics. A main effect with strong harmonics above loses that power from , so is too low. Raise and together.
- Reading the error as noise. The gaps in the examples are biases from the bands, not sampling error. More phases () do not reduce them; only a larger and with more points do.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fourier-amplitude-sensitivity-test/. The authors are listed in prov/VVPHQA.jsonl.
"""The Fourier amplitude sensitivity test in its extended form (eFAST, Saltelli, Tarantola and Chan 1999).
For each input i, all inputs move along one search curve in the unit cube,
x_j(s) = 1/2 + arcsin(sin(omega_j s + phi_j)) / pi, s in (-pi, pi),
with a high frequency omega_i for input i and low frequencies for the others.
Each x_j(s) is uniform on [0, 1] when s is uniform. The output y(s) = f(x(s))
is periodic in s, and its Fourier spectrum splits the variance: the power at
the harmonics q omega_i, q = 1..M, is the first order part D_i, and the power at
the frequencies up to omega_i / 2 belongs to the complementary inputs, so that
1 - D_(~i) / D is the total index. The phases phi_j are random, and the run is
repeated n_r times (resampling) to reduce the error from the curve.
The classic FAST of Cukier et al. 1973 uses one curve with a frequency set
for all inputs at once and gives the first order indices only.
The cost is d n_r n_s model runs, with n_s >= 2 M omega_max + 1 points per curve.
"""
import math
import random
from typing import Callable, Sequence
Model = Callable[[Sequence[float]], float]
def frequencies(d: int, i: int, omega_max: int, m: int) -> list[int]:
"""omega_i = omega_max, and the other inputs get frequencies in 1..floor(omega_max / (2 M)).
If there is room, the d - 1 low frequencies are spread evenly over that range,
else they cycle through it. Spread frequencies make the curve fill more of the
subcube of the other inputs.
"""
top = omega_max // (2 * m)
if top < 1:
raise ValueError("omega_max must be at least 2 M")
rest = d - 1
if rest == 1:
low = [1]
elif top >= rest:
low = [1 + (top - 1) * k // (rest - 1) for k in range(rest)]
else:
low = [1 + k % top for k in range(rest)]
out = list(low)
out.insert(i, omega_max)
return out
def search_points(omegas: Sequence[int], phases: Sequence[float], n_s: int) -> list[list[float]]:
"""The n_s points of the curve at s_k = pi (2k - n_s - 1) / n_s, k = 1..n_s, in the unit cube."""
pts = []
for k in range(1, n_s + 1):
s = math.pi * (2 * k - n_s - 1) / n_s
pts.append([0.5 + math.asin(math.sin(w * s + ph)) / math.pi for w, ph in zip(omegas, phases)])
return pts
def spectrum(y: Sequence[float], n_s: int) -> list[float]:
"""The power Lambda_p = (A_p^2 + B_p^2) / 2 for p = 0..(n_s - 1) / 2 (Lambda_0 is unused).
For odd n_s, the sum of Lambda_p over p >= 1 is the population variance of y (discrete Parseval).
"""
half = (n_s - 1) // 2
s = [math.pi * (2 * k - n_s - 1) / n_s for k in range(1, n_s + 1)]
out = [0.0]
for p in range(1, half + 1):
a = 2.0 / n_s * sum(yk * math.cos(p * sk) for yk, sk in zip(y, s))
b = 2.0 / n_s * sum(yk * math.sin(p * sk) for yk, sk in zip(y, s))
out.append(0.5 * (a * a + b * b))
return out
def efast(f: Model, d: int, omega_max: int, m: int, n_r: int, rng: random.Random, n_s: int = 0) -> dict:
"""First order and total indices of the d inputs of f on the unit cube [0, 1]^d."""
if n_s == 0:
n_s = 2 * m * omega_max + 1
if n_s < 2 * m * omega_max + 1 or n_s % 2 == 0:
raise ValueError("n_s must be odd and at least 2 M omega_max + 1")
s_first, s_total, runs = [], [], 0
for i in range(d): # @line L1
first = total = 0.0
omegas = frequencies(d, i, omega_max, m) # @line L2
for _ in range(n_r): # @line L3
phases = [2 * math.pi * rng.random() for _ in range(d)]
pts = search_points(omegas, phases, n_s) # @line L4
y = [f(x) for x in pts] # @line L5
runs += n_s
lam = spectrum(y, n_s) # @line L6
var = sum(lam[1:]) # @line L7
d_i = sum(lam[q * omega_max] for q in range(1, m + 1)) # @line L8
d_rest = sum(lam[1 : omega_max // 2 + 1]) # @line L9
first += d_i / var
total += 1.0 - d_rest / var
s_first.append(first / n_r) # @line L10
s_total.append(total / n_r)
return {"S": s_first, "ST": s_total, "runs": runs, "n_s": n_s}
fourier_amplitude_sensitivity_test.py 8 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fourier-amplitude-sensitivity-test/. The authors are listed in prov/VVPHQA.jsonl.
"""Entry point named after the slug. The code lives in efast.py, because tools treat
a file whose name ends in _test.py as a test file and skip its line markers."""
from efast import efast, frequencies, search_points, spectrum
__all__ = ["efast", "frequencies", "search_points", "spectrum"]
test_fourier_amplitude_sensitivity_test.py 70 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fourier-amplitude-sensitivity-test/. The authors are listed in prov/VVPHQA.jsonl.
import math
import random
import pytest
from fourier_amplitude_sensitivity_test import efast, frequencies, search_points, spectrum
def ishigami_unit(u):
x = [-math.pi + 2 * math.pi * v for v in u]
return math.sin(x[0]) + 7 * math.sin(x[1]) ** 2 + 0.1 * x[2] ** 4 * math.sin(x[0])
ISHIGAMI_S = [0.3139, 0.4424, 0.0]
ISHIGAMI_ST = [0.5576, 0.4424, 0.2437]
def test_frequencies_put_the_high_one_at_input_i():
assert frequencies(3, 1, 64, 4) == [1, 64, 8]
assert frequencies(5, 0, 64, 4) == [64, 1, 3, 5, 8]
with pytest.raises(ValueError):
frequencies(3, 0, 7, 4)
def test_search_curve_has_uniform_marginals():
pts = search_points([1, 11, 4], [0.3, 1.1, 2.0], 2001)
for j in range(3):
col = sorted(p[j] for p in pts)
assert all(0.0 <= v <= 1.0 for v in col)
assert abs(sum(col) / len(col) - 0.5) < 0.01
assert abs(col[len(col) // 4] - 0.25) < 0.01
def test_spectrum_power_sums_to_the_variance():
rng = random.Random(3)
n_s = 257
y = [rng.random() for _ in range(n_s)]
m = sum(y) / n_s
assert abs(sum(spectrum(y, n_s)[1:]) - sum((v - m) ** 2 for v in y) / n_s) < 1e-12
def test_cosine_model_is_exact():
# cos(2 pi x_j) along the curve is a pure harmonic at 2 omega_j, so no power leaks
c = [1.0, 2.0, 0.0, 3.0]
f = lambda x: sum(cj * math.cos(2 * math.pi * xj) for cj, xj in zip(c, x)) # noqa: E731
res = efast(f, 4, 32, 4, 2, random.Random(11))
assert res["runs"] == 4 * 2 * res["n_s"]
total = sum(cj * cj for cj in c)
for i in range(4):
assert abs(res["S"][i] - c[i] ** 2 / total) < 1e-9
assert abs(res["ST"][i] - c[i] ** 2 / total) < 1e-9
def test_ishigami_first_order_and_total_indices():
res = efast(ishigami_unit, 3, 64, 4, 1, random.Random(1))
assert res["runs"] == 3 * 513
for i in range(3):
assert abs(res["S"][i] - ISHIGAMI_S[i]) < 0.03
assert abs(res["ST"][i] - ISHIGAMI_ST[i]) < 0.06
# x3 acts only through its interaction with x1
assert res["ST"][2] - res["S"][2] > 0.15
def test_even_or_short_curves_are_rejected():
with pytest.raises(ValueError):
efast(ishigami_unit, 3, 16, 4, 1, random.Random(0), n_s=128)
with pytest.raises(ValueError):
efast(ishigami_unit, 3, 16, 4, 1, random.Random(0), n_s=101)
History
Cukier, Fortuin, Shuler, Petschek and Schaibly proposed FAST in 1973 in the Journal of Chemical Physics, to measure how uncertain rate constants change the concentrations of coupled chemical reactions. Schaibly and Shuler and later Cukier, Levine and Shuler developed the frequency choices and the theory in the 1970s. Saltelli, Tarantola and Chan (1999) showed how to get the total index from the low band and introduced the triangle wave curve and the random phases, which is the extended FAST in common use.
References
- R. I. Cukier, C. M. Fortuin, K. E. Shuler, A. G. Petschek and J. H. Schaibly, Study of the sensitivity of coupled reaction systems to uncertainties in rate coefficients. I Theory, Journal of Chemical Physics 59(8), 1973, 3873-3878, the search curve with incommensurate frequencies and the partial variances from the Fourier coefficients at the harmonics of each frequency
- A. Saltelli, S. Tarantola and K. P.-S. Chan, A quantitative model-independent method for global sensitivity analysis of model output, Technometrics 41(1), 1999, 39-56, the extended FAST, the search curve 1/2 + arcsin(sin(omega s + phi))/pi, the total index from the low frequency band, the frequency rules and the resampling with random phases
- 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 (FAST and the extended FAST among the variance-based methods)
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag VVPHQA Edit this page History Report an error Markdown