Algorithmadvanced
Subset simulation
Also called SuS, subset simulation by Markov chain Monte Carlo.
Writes a rare failure probability as a product of larger conditional probabilities of nested events, each sampled by MCMC.
- Time
- O(m N (C + d)) worst
- Space
- O(N d) extra
- Where
- C = the cost of one evaluation of the limit state function; N = the number of samples per level; d = the number of random inputs; m = the number of levels
- Model
- Real RAM
- Properties
- randomizednot exactnot intrusive
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Siu Kui Au, James L. Beck, Iason Papaioannou, Daniel Straub, 2001
Subset simulation estimates a small probability , where is a standard normal vector and is a limit state function, much faster than plain Monte Carlo. It writes the failure set as the last of a chain of nested sets , with , and uses
Each factor is about , so a probability of needs six factors that are each easy to estimate. The thresholds are chosen on the fly as sample quantiles. The samples conditional on come from Markov chains that start at the samples already in and stay in it, by a Metropolis method that works one coordinate at a time. The method needs no gradient and no design point, it works in hundreds of dimensions, and it finds failure regions in several directions at once. Its result is random, with a small bias of order .
In plain words
A failure that happens once in a million runs is hard to see by random runs. So take it in steps. Run 1000 random cases and keep the 100 that came closest to failure. That defines a first "near failure" set, which holds about one case in ten. From each of the 100 kept cases, take small random walks that never leave the set, until you have 1000 cases spread over it. Again keep the 100 closest to failure. Each step moves the cases a factor of ten closer to the real failure set. When a step reaches it, count the failures and multiply the fractions of all steps.
The problem
The input is a limit state function of a standard normal vector , with failure for . Physical inputs with other laws are first written as functions of , for example by the inverse CDF of each marginal. The parameters are the number of samples per level and the level probability , with an integer that divides . The output is an estimate of , the thresholds , and the number of calls to . The interesting case is between about and , and expensive.
The algorithm
SUBSET-SIMULATION(g, d, N, p0)- 1
draw N independent standard normal samples u_i; evaluate g(u_i) - 2
repeat for j = 1, 2, ... - 3
b ← the (p0 N)-th smallest value of g(u_i) - 4
if b ≤ 0 - 5
return P ≈ p0^(j-1) · #{i : g(u_i) ≤ 0} / N - 6
record the factor p0 and the threshold b_j = b - 7
from each of the p0 N samples with g ≤ b, run a modified Metropolis chain of length 1/p0 inside {g ≤ b} - 8
the N chain states are the samples of level j + 1
Line L1 is plain Monte Carlo. Line L3 picks the threshold as a sample quantile, so that exactly samples lie in . If the threshold is already at or below 0 (line L4), at least samples fail, the last factor is the plain fraction of failures, and line L5 multiplies the factors. Otherwise line L6 records the factor . Line L7 is the conditional sampling step. Each seed is the first state of a chain of states. One step of the modified Metropolis method of Au and Beck changes each coordinate independently: it proposes and accepts it with probability , where is the standard normal density. Then it evaluates at the candidate and moves only if the candidate lies in . The chain keeps the standard normal law conditioned on invariant, so its states are (dependent) samples of the next level. Line L8 replaces the samples; the reference code also stops with an error after a fixed number of levels.
Example
One run. Let in two dimensions, , , and seed 7. The exact value is .
| level | threshold | factor | estimate so far |
|---|---|---|---|
| 1 | 1.666 | 0.1 | 0.1 |
| 2 | 0.570 | 0.1 | 0.01 |
| 3 | 0 | 0.193 |
The run used 2692 calls of , fewer than , because a step that rejects every coordinate does not call . One run has a large error; the next table shows the spread.
Many runs. Each row repeats the method 40 times, with seeds 0 to 39, , and . The coefficient of variation (c.o.v.) is the standard deviation over the mean. The last column is the c.o.v. that plain Monte Carlo would have with the same mean number of calls, .
| limit state | exact | mean estimate | c.o.v. | mean calls | Monte Carlo c.o.v. | |
|---|---|---|---|---|---|---|
| 20 | 0.27 | 2868 | 0.51 | |||
| 20 | 0.79 | 5500 | 7.3 | |||
| 10 | 0.21 | 2800 | 0.36 |
At , Monte Carlo with 5500 runs would usually see no failure at all. The third limit state has two design points, at and . Subset simulation finds both and gets ; the first-order reliability method finds one and returns , half the answer.
Correctness
Three statements are exact. First, the product formula: if , then , by the definition of conditional probability, since . Second, the modified Metropolis step satisfies detailed balance for the standard normal law restricted to , so that law is a stationary distribution of the chain. A chain started from a sample of the conditional law therefore stays in that law at every step; the test file checks this for the truncated normal law. Third, the algorithm stops, because the number of levels is bounded.
The estimate is not exactly unbiased, because the thresholds are random and depend on the same samples. Au and Beck showed that the bias is of order and the c.o.v. of order . For fixed thresholds, the c.o.v. of level is , where measures the correlation of the states of a chain. With levels the total c.o.v. is roughly , which grows like , while the c.o.v. of Monte Carlo grows like . The chains are also not proved to explore every part of : if a part of the failure set is not reached by any seed of an earlier level, the estimate misses it.
Proof: The product formula is exact, the modified Metropolis step keeps the conditional law invariant, and subset simulation stopsfull
Let be the standard normal density on and the standard normal density on . For a threshold put with , and let be the conditional density.
Lemma 1 (product formula). If and for all , then .
Proof. Since , , so . The product telescopes to .
The sets of the algorithm are nested because the thresholds decrease: is a quantile of samples that all satisfy (Lemma 3), so .
Lemma 2 (the one coordinate kernel). Fix . The kernel on that proposes , accepts with probability , and otherwise stays at , satisfies detailed balance for : for measurable sets , .
Proof. The proposal density is symmetric. For the moving part of the kernel has density , and , which is symmetric in and . The part that stays at contributes to both sides, where is the rejection probability.
Lemma 3 (the modified Metropolis step). Let be the kernel of MM-STEP: apply the kernel of Lemma 2 to each coordinate independently to get a candidate , then move to if and stay otherwise. Then satisfies detailed balance for , so is stationary for . Every state of a chain started in lies in .
Proof. The candidate kernel is a product of kernels that are reversible for , so is reversible for : for product sets and , , and product sets determine the measures. Now . For measurable ,
since . The first term is symmetric in and by the reversibility of , and the second is symmetric because it depends only on . So is reversible for on , and integrating over gives stationarity. A move goes only to a candidate in , so a chain that starts in stays in .
Corollary. If a seed has law , then every state of its chain has law , by induction with Lemma 3. The states of one chain are dependent, but each one has the correct marginal law. So the fraction of chain states with estimates , with an error that depends on the correlation of the chain.
In the algorithm, the seeds of level are the samples of level with . If the samples of level have law and were fixed in advance, each such seed would have law , and the corollary would apply. Because is a sample quantile of the same samples, this holds only approximately; that is the source of the bias that Au and Beck describe, which is not proved here.
Theorem. SUBSET-SIMULATION stops after at most max_levels levels and at most calls of . When it returns, the thresholds are nonincreasing, the last threshold is 0, and the estimate is the product of the recorded factors. With fixed nested thresholds, the product of the exact factors is , and each chain state of level has the law when its seed does.
Proof. Each level does finitely many steps: a sort, and chains of steps, each with at most one call of . The loop runs at most max_levels times, then returns or raises an error. Level 1 makes calls and each later level at most . The thresholds are nonincreasing as shown after Lemma 1; the returned factors are for each recorded level and the failure fraction for the last. The product statement is Lemma 1, and the law of the chain states is the corollary of Lemma 3.
The theorem does not bound the error of one run. The c.o.v. formula of Au and Beck needs the correlation factors of the chains and an assumption that the chains mix over all of . If has parts that no seed reaches, the chains never sample them, and the estimate is too small.
Complexity
In the real RAM model, each level costs at most calls of and work for the proposals and the sort, so the total is with levels. The extra space is for the samples of one level. For and , the cost is about 5500 calls, against for Monte Carlo at a c.o.v. of 0.1.
Properties
- Randomized. The estimate is random; repeated runs give its spread.
- Cost grows like . Each factor of in rarity adds one level.
- No gradients. It uses only values of .
- Works in high dimension. The component-wise proposal keeps the acceptance rate from falling to 0 as grows.
- Global. It finds several failure regions, if the first level samples them all.
- Small bias. Of order , from the adaptive thresholds.
Variants and improvements
- Adaptive proposals. Papaioannou and coauthors tune the spread of each level toward an acceptance rate near 0.44, and use conditional sampling with a correlated normal proposal in standard normal space, which needs no rejection per coordinate.
- Other level probabilities. between 0.1 and 0.3 works well; a smaller gives fewer levels but a larger error per level.
- Error estimate from one run. Estimate from the correlation of the chain states and combine the , as Au and Beck did.
- Subset simulation for design. The samples of each level are samples of the inputs given near failure, so they also give conditional means, sensitivity and the failure probability as a function of a threshold, at no extra cost.
- Related methods. The cross-entropy method adapts an importance sampling density with a similar sequence of quantile levels. Multilevel splitting and sequential Monte Carlo use the same nested structure with resampling.
When to use it
Use subset simulation when is small, is large or the limit state is strongly nonlinear, there are no gradients, or the failure set may have several parts. It needs a few thousand calls of per run, more than FORM but far fewer than Monte Carlo. If is smooth with one design point, FORM with a second-order correction is cheaper. If each call of is very expensive, fit a surrogate first and run subset simulation on it.
Pitfalls
- Correlated chains. A proposal that is too narrow or too wide makes large and the error large, as in the row. Monitor the acceptance rate.
- Missed failure regions. If no seed of level lies near a part of , later levels do not find it. Use a larger when there may be separated regions.
- One run is not enough. The c.o.v. of one run can be 0.3 or more. Report an error estimate.
- Bad input map. The method assumes independent standard normal inputs. Map other laws to that space first, or the modified Metropolis step samples the wrong law.
- Ties in . A limit state with flat regions makes the quantile ill defined. Break ties, or use a level set with a little noise.
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/subset-simulation/. The authors are listed in prov/2D3RV8.jsonl.
"""Subset simulation of Au and Beck for a small failure probability P[g(U) <= 0].
U is a standard normal vector in R^d; map physical inputs to U first, for
example by the inverse CDF of each marginal. The failure set F = {g <= 0} is
reached through nested sets F_j = {g <= b_j} with b_1 > b_2 > ... > b_m = 0.
Each threshold b_j is the p0 quantile of the current samples, so every
conditional probability P[F_j | F_(j-1)] is about p0. The samples of the next
level are Markov chains, by the component-wise modified Metropolis method,
started from the samples that already lie in F_j.
"""
import math
import random
from typing import Callable
Vector = list[float]
def mm_step(g: Callable[[Vector], float], u: Vector, gu: float, b: float, rng: random.Random, width: float = 1.0) -> tuple[Vector, float, bool]:
"""One modified Metropolis step whose stationary law is the standard normal law conditioned on g <= b.
Returns the next state, its g value, and whether g was called.
"""
cand = list(u)
moved = False
for k, uk in enumerate(u):
xi = uk + rng.uniform(-width, width)
if rng.random() < math.exp(0.5 * (uk * uk - xi * xi)):
cand[k] = xi
moved = True
if not moved:
return u, gu, False
gc = g(cand)
if gc <= b:
return cand, gc, True
return u, gu, True
def subset_simulation(g: Callable[[Vector], float], d: int, rng: random.Random, n: int = 1000, p0: float = 0.1, max_levels: int = 30, width: float = 1.0) -> dict:
"""Estimate P[g(U) <= 0]; returns the estimate, the thresholds, the level probabilities and the number of g calls."""
nc = round(p0 * n)
if not 0 < nc < n or abs(nc - p0 * n) > 1e-9 or n % nc != 0:
raise ValueError("p0 n must be an integer that divides n")
chain_len = n // nc
us = [[rng.gauss(0.0, 1.0) for _ in range(d)] for _ in range(n)] # @line L1
gs = [g(u) for u in us]
calls = n
thresholds: list[float] = []
probs: list[float] = []
for _ in range(max_levels): # @line L2
order = sorted(range(n), key=lambda i: gs[i])
b = gs[order[nc - 1]] # @line L3
if b <= 0.0: # @line L4
probs.append(sum(1 for v in gs if v <= 0.0) / n)
thresholds.append(0.0)
return {"pf": math.prod(probs), "thresholds": thresholds, "probs": probs, "calls": calls} # @line L5
thresholds.append(b)
probs.append(p0) # @line L6
new_u: list[Vector] = []
new_g: list[float] = []
for i in order[:nc]: # @line L7
u, gu = us[i], gs[i]
new_u.append(u)
new_g.append(gu)
for _ in range(chain_len - 1):
u, gu, called = mm_step(g, u, gu, b, rng, width)
calls += called
new_u.append(u)
new_g.append(gu)
us, gs = new_u, new_g # @line L8
raise RuntimeError("the failure set was not reached within max_levels levels")
test_subset_simulation.py 93 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/subset-simulation/. The authors are listed in prov/2D3RV8.jsonl.
import math
import random
import statistics
import pytest
from subset_simulation import mm_step, subset_simulation
def phi(t):
return 0.5 * math.erfc(-t / math.sqrt(2.0))
def run_many(g, d, seeds, **kw):
return [subset_simulation(g, d, random.Random(s), **kw) for s in seeds]
def test_linear_limit_state_in_twenty_dimensions():
g = lambda u: 3.0 - sum(u) / math.sqrt(len(u))
est = [r["pf"] for r in run_many(g, 20, range(20))]
m = statistics.mean(est)
se = statistics.stdev(est) / math.sqrt(len(est))
assert abs(m - phi(-3.0)) < 4.0 * se
assert abs(m / phi(-3.0) - 1.0) < 0.3
def test_two_design_points_are_both_found():
est = [r["pf"] for r in run_many(lambda u: 3.0 - abs(u[0]), 5, range(20))]
m = statistics.mean(est)
se = statistics.stdev(est) / math.sqrt(len(est))
assert abs(m - 2.0 * phi(-3.0)) < 4.0 * se
assert m > 1.5 * phi(-3.0)
def test_estimate_is_the_product_of_the_level_probabilities():
r = subset_simulation(lambda u: 3.0 - u[0], 3, random.Random(5))
assert r["pf"] == pytest.approx(math.prod(r["probs"]), rel=1e-15)
assert all(p == 0.1 for p in r["probs"][:-1])
assert 0.0 < r["probs"][-1] <= 1.0
th = r["thresholds"]
assert th[-1] == 0.0 and all(a > b for a, b in zip(th, th[1:]))
assert r["calls"] <= 1000 + 900 * (len(r["probs"]) - 1)
def test_large_probability_is_plain_monte_carlo():
rng = random.Random(3)
r = subset_simulation(lambda u: 0.5 - u[0], 2, rng)
assert len(r["probs"]) == 1 and r["calls"] == 1000
rng2 = random.Random(3)
us = [[rng2.gauss(0.0, 1.0) for _ in range(2)] for _ in range(1000)]
assert r["pf"] == sum(1 for u in us if 0.5 - u[0] <= 0.0) / 1000
def test_modified_metropolis_keeps_the_conditional_law():
rng = random.Random(11)
g = lambda u: 1.0 - u[0]
p1 = phi(-1.0)
us = []
for _ in range(4000):
t = rng.random()
x = -statistics.NormalDist().inv_cdf(p1 * t)
us.append([x, rng.gauss(0.0, 1.0)])
gs = [g(u) for u in us]
for _ in range(3):
nxt = [mm_step(g, u, gu, 0.0, rng) for u, gu in zip(us, gs)]
us = [s[0] for s in nxt]
gs = [s[1] for s in nxt]
assert all(v <= 0.0 for v in gs)
mean_x = statistics.mean(u[0] for u in us)
assert abs(mean_x - math.exp(-0.5) / math.sqrt(2.0 * math.pi) / p1) < 0.04
assert abs(statistics.mean(u[1] for u in us)) < 0.06
assert abs(statistics.pvariance([u[1] for u in us]) - 1.0) < 0.08
def test_same_seed_same_result():
g = lambda u: 3.0 - u[1]
a = subset_simulation(g, 4, random.Random(9))
b = subset_simulation(g, 4, random.Random(9))
assert a == b
def test_bad_sizes_are_rejected():
with pytest.raises(ValueError):
subset_simulation(lambda u: 1.0 - u[0], 1, random.Random(0), n=1000, p0=0.15)
with pytest.raises(ValueError):
subset_simulation(lambda u: 1.0 - u[0], 1, random.Random(0), n=100, p0=0.003)
def test_unreachable_failure_set_raises():
with pytest.raises(RuntimeError):
subset_simulation(lambda u: 50.0 - u[0], 1, random.Random(0), n=100, max_levels=3)
History
Au and Beck introduced subset simulation in 2001 for small failure probabilities of structures with many random inputs, and gave the modified Metropolis algorithm, which works one coordinate at a time because the plain Metropolis method rejects almost every move in high dimensions. The method became a standard tool of structural reliability. Papaioannou, Betz, Zwirglmaier and Straub compared MCMC samplers for it in 2015 and gave adaptive proposals. Au and Wang wrote a book on the method in 2014.
References
- Siu-Kui Au and James L. Beck, Estimation of small failure probabilities in high dimensions by subset simulation, Probabilistic Engineering Mechanics 16(4), 2001, 263-277, the product of conditional probabilities over nested failure sets, the component-wise modified Metropolis algorithm, and the coefficient of variation of the estimate with the correlation factor of the chains
- Iason Papaioannou, Wolfgang Betz, Kilian Zwirglmaier and Daniel Straub, MCMC algorithms for subset simulation, Probabilistic Engineering Mechanics 41, 2015, 89-103, the comparison of MCMC samplers for subset simulation in standard normal space, and the adaptive scaling of the proposal spread toward a target acceptance rate
- Siu-Kui Au and Yu Wang, Engineering Risk Assessment with Subset Simulation, Wiley, 2014, the full treatment of the algorithm, the choice of the level probability, and the error estimate of the result
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 2D3RV8 Edit this page History Report an error Markdown