Algorithm Search⌘K

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
Properties
randomizednot exactnot intrusive
Origin
Siu Kui Au, James L. Beck, Iason Papaioannou, Daniel Straub, 2001

Subset simulation estimates a small probability Pf=P[g(U)≤0]P_f = \mathbb{P}[g(U) \le 0], where UU is a standard normal vector and gg is a limit state function, much faster than plain Monte Carlo. It writes the failure set FF as the last of a chain of nested sets F1⊃F2⊃⋯⊃Fm=FF_1 \supset F_2 \supset \cdots \supset F_m = F, with Fj={g≤bj}F_j = \{g \le b_j\}, and uses

Pf=P[F1]∏j=2mP[Fj∣Fj−1].P_f = \mathbb{P}[F_1] \prod_{j=2}^{m} \mathbb{P}[F_j \mid F_{j-1}].

Each factor is about p0=0.1p_0 = 0.1, so a probability of 10−610^{-6} needs six factors that are each easy to estimate. The thresholds bjb_j are chosen on the fly as sample quantiles. The samples conditional on Fj−1F_{j-1} come from Markov chains that start at the samples already in Fj−1F_{j-1} 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 1/N1/N.

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 g:Rd→Rg : \mathbb{R}^d \to \mathbb{R} of a standard normal vector UU, with failure for g(U)≤0g(U) \le 0. Physical inputs with other laws are first written as functions of UU, for example by the inverse CDF of each marginal. The parameters are the number of samples per level NN and the level probability p0p_0, with p0Np_0 N an integer that divides NN. The output is an estimate P^f\hat P_f of P[g(U)≤0]\mathbb{P}[g(U) \le 0], the thresholds b1>⋯>bm=0b_1 > \cdots > b_m = 0, and the number of calls to gg. The interesting case is PfP_f between about 10−310^{-3} and 10−910^{-9}, and gg expensive.

The algorithm

  1. SUBSET-SIMULATION(g, d, N, p0)
  2. 1draw N independent standard normal samples u_i; evaluate g(u_i)
  3. 2repeat for j = 1, 2, ...
  4. 3b ← the (p0 N)-th smallest value of g(u_i)
  5. 4if b ≤ 0
  6. 5return P ≈ p0^(j-1) · #{i : g(u_i) ≤ 0} / N
  7. 6record the factor p0 and the threshold b_j = b
  8. 7from each of the p0 N samples with g ≤ b, run a modified Metropolis chain of length 1/p0 inside {g ≤ b}
  9. 8the 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 p0Np_0 N samples lie in Fj={g≤b}F_j = \{g \le b\}. If the threshold is already at or below 0 (line L4), at least p0Np_0 N samples fail, the last factor is the plain fraction of failures, and line L5 multiplies the factors. Otherwise line L6 records the factor p0p_0. Line L7 is the conditional sampling step. Each seed is the first state of a chain of 1/p01/p_0 states. One step of the modified Metropolis method of Au and Beck changes each coordinate uku_k independently: it proposes ξk=uk+Uniform(−w,w)\xi_k = u_k + \text{Uniform}(-w, w) and accepts it with probability min⁡(1,φ(ξk)/φ(uk))\min(1, \varphi(\xi_k)/\varphi(u_k)), where φ\varphi is the standard normal density. Then it evaluates gg at the candidate and moves only if the candidate lies in FjF_j. The chain keeps the standard normal law conditioned on FjF_j 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 g(u)=3−u1g(u) = 3 - u_1 in two dimensions, N=1000N = 1000, p0=0.1p_0 = 0.1, and seed 7. The exact value is Φ(−3)=1.350×10−3\Phi(-3) = 1.350 \times 10^{-3}.

level jj threshold bjb_j factor estimate so far
1 1.666 0.1 0.1
2 0.570 0.1 0.01
3 0 0.193 1.93×10−31.93 \times 10^{-3}

The run used 2692 calls of gg, fewer than 1000+2⋅9001000 + 2 \cdot 900, because a step that rejects every coordinate does not call gg. 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, N=1000N = 1000, p0=0.1p_0 = 0.1 and w=1w = 1. 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, (1−Pf)/(Pfn)\sqrt{(1 - P_f)/(P_f n)}.

limit state dd exact PfP_f mean estimate c.o.v. mean calls Monte Carlo c.o.v.
3−(u1+⋯+ud)/d3 - (u_1 + \cdots + u_d)/\sqrt{d} 20 1.350×10−31.350 \times 10^{-3} 1.458×10−31.458 \times 10^{-3} 0.27 2868 0.51
4.5−u14.5 - u_1 20 3.398×10−63.398 \times 10^{-6} 3.486×10−63.486 \times 10^{-6} 0.79 5500 7.3
3−∣u1∣3 - \lvert u_1 \rvert 10 2.700×10−32.700 \times 10^{-3} 2.725×10−32.725 \times 10^{-3} 0.21 2800 0.36

At Pf=3.4×10−6P_f = 3.4 \times 10^{-6}, Monte Carlo with 5500 runs would usually see no failure at all. The third limit state has two design points, at u1=3u_1 = 3 and u1=−3u_1 = -3. Subset simulation finds both and gets 2Φ(−3)2 \Phi(-3); the first-order reliability method finds one and returns Φ(−3)\Phi(-3), half the answer.

Correctness

Three statements are exact. First, the product formula: if Fm⊂Fm−1⊂⋯⊂F1F_m \subset F_{m-1} \subset \cdots \subset F_1, then P[Fm]=P[F1]∏jP[Fj∣Fj−1]\mathbb{P}[F_m] = \mathbb{P}[F_1] \prod_j \mathbb{P}[F_j \mid F_{j-1}], by the definition of conditional probability, since Fj∩Fj−1=FjF_j \cap F_{j-1} = F_j. Second, the modified Metropolis step satisfies detailed balance for the standard normal law restricted to FjF_j, 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 1/N1/N and the c.o.v. of order 1/N1/\sqrt{N}. For fixed thresholds, the c.o.v. of level jj is δj2=1−pjpjN(1+γj)\delta_j^2 = \frac{1 - p_j}{p_j N}(1 + \gamma_j), where γj≥0\gamma_j \ge 0 measures the correlation of the states of a chain. With mm levels the total c.o.v. is roughly ∑jδj2\sqrt{\sum_j \delta_j^2}, which grows like ∣ln⁡Pf∣\sqrt{|\ln P_f|}, while the c.o.v. of Monte Carlo grows like 1/Pf1/\sqrt{P_f}. The chains are also not proved to explore every part of FjF_j: 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 φ\varphi be the standard normal density on R\mathbb{R} and π(u)=∏k=1dφ(uk)\pi(u) = \prod_{k=1}^{d} \varphi(u_k) the standard normal density on Rd\mathbb{R}^d. For a threshold bb put F={u:g(u)≤b}F = \{u : g(u) \le b\} with P[U∈F]>0\mathbb{P}[U \in F] > 0, and let πF(u)=π(u)1F(u)/P[U∈F]\pi_F(u) = \pi(u) \mathbf{1}_F(u) / \mathbb{P}[U \in F] be the conditional density.

Lemma 1 (product formula). If Fm⊆Fm−1⊆⋯⊆F1F_m \subseteq F_{m-1} \subseteq \cdots \subseteq F_1 and P[Fj]>0\mathbb{P}[F_j] > 0 for all jj, then P[Fm]=P[F1]∏j=2mP[Fj∣Fj−1]\mathbb{P}[F_m] = \mathbb{P}[F_1] \prod_{j=2}^{m} \mathbb{P}[F_j \mid F_{j-1}].

Proof. Since Fj⊆Fj−1F_j \subseteq F_{j-1}, Fj∩Fj−1=FjF_j \cap F_{j-1} = F_j, so P[Fj∣Fj−1]=P[Fj]/P[Fj−1]\mathbb{P}[F_j \mid F_{j-1}] = \mathbb{P}[F_j] / \mathbb{P}[F_{j-1}]. The product telescopes to P[Fm]\mathbb{P}[F_m]. □\square

The sets of the algorithm are nested because the thresholds decrease: bj+1b_{j+1} is a quantile of samples that all satisfy g≤bjg \le b_j (Lemma 3), so bj+1≤bjb_{j+1} \le b_j.

Lemma 2 (the one coordinate kernel). Fix w>0w > 0. The kernel qq on R\mathbb{R} that proposes ξ=x+Uniform(−w,w)\xi = x + \text{Uniform}(-w, w), accepts with probability min⁡(1,φ(ξ)/φ(x))\min(1, \varphi(\xi)/\varphi(x)), and otherwise stays at xx, satisfies detailed balance for φ\varphi: for measurable sets A,B⊆RA, B \subseteq \mathbb{R}, ∫Aφ(x)q(x,B) dx=∫Bφ(y)q(y,A) dy\int_A \varphi(x) q(x, B)\, dx = \int_B \varphi(y) q(y, A)\, dy.

Proof. The proposal density s(x,ξ)=1[∣ξ−x∣<w]/(2w)s(x, \xi) = \mathbf{1}[|\xi - x| < w] / (2w) is symmetric. For x≠yx \neq y the moving part of the kernel has density s(x,y)min⁡(1,φ(y)/φ(x))s(x, y) \min(1, \varphi(y)/\varphi(x)), and φ(x)s(x,y)min⁡(1,φ(y)/φ(x))=s(x,y)min⁡(φ(x),φ(y))\varphi(x) s(x, y) \min(1, \varphi(y)/\varphi(x)) = s(x, y) \min(\varphi(x), \varphi(y)), which is symmetric in xx and yy. The part that stays at xx contributes ∫A∩Bφ(x)r(x) dx\int_{A \cap B} \varphi(x) r(x)\, dx to both sides, where r(x)r(x) is the rejection probability. □\square

Lemma 3 (the modified Metropolis step). Let KK be the kernel of MM-STEP: apply the kernel of Lemma 2 to each coordinate independently to get a candidate cc, then move to cc if c∈Fc \in F and stay otherwise. Then KK satisfies detailed balance for πF\pi_F, so πF\pi_F is stationary for KK. Every state of a chain started in FF lies in FF.

Proof. The candidate kernel Q(u,dc)=∏kq(uk,dck)Q(u, dc) = \prod_k q(u_k, dc_k) is a product of kernels that are reversible for φ\varphi, so QQ is reversible for π\pi: for product sets A=∏AkA = \prod A_k and B=∏BkB = \prod B_k, ∫Aπ(u)Q(u,B) du=∏k∫Akφq(⋅,Bk)=∏k∫Bkφq(⋅,Ak)=∫Bπ(c)Q(c,A) dc\int_A \pi(u) Q(u, B)\, du = \prod_k \int_{A_k} \varphi q(\cdot, B_k) = \prod_k \int_{B_k} \varphi q(\cdot, A_k) = \int_B \pi(c) Q(c, A)\, dc, and product sets determine the measures. Now K(u,B)=Q(u,B∩F)+1B(u)Q(u,Fc)K(u, B) = Q(u, B \cap F) + \mathbf{1}_B(u) Q(u, F^c). For measurable A,B⊆FA, B \subseteq F,

∫AπF(u)K(u,B) du=1P[F](∫Aπ(u)Q(u,B) du+∫A∩Bπ(u)Q(u,Fc) du),\int_A \pi_F(u) K(u, B)\, du = \frac{1}{\mathbb{P}[F]} \Big( \int_A \pi(u) Q(u, B)\, du + \int_{A \cap B} \pi(u) Q(u, F^c)\, du \Big),

since B∩F=BB \cap F = B. The first term is symmetric in AA and BB by the reversibility of QQ, and the second is symmetric because it depends only on A∩BA \cap B. So KK is reversible for πF\pi_F on FF, and integrating over B=FB = F gives stationarity. A move goes only to a candidate in FF, so a chain that starts in FF stays in FF. □\square

Corollary. If a seed uu has law πF\pi_F, then every state of its chain has law πF\pi_F, 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 g≤b′g \le b' estimates P[g(U)≤b′∣U∈F]\mathbb{P}[g(U) \le b' \mid U \in F], with an error that depends on the correlation of the chain.

In the algorithm, the seeds of level j+1j + 1 are the samples of level jj with g≤bjg \le b_j. If the samples of level jj have law πFj−1\pi_{F_{j-1}} and bjb_j were fixed in advance, each such seed would have law πFj\pi_{F_j}, and the corollary would apply. Because bjb_j is a sample quantile of the same samples, this holds only approximately; that is the source of the O(1/N)O(1/N) bias that Au and Beck describe, which is not proved here.

Theorem. SUBSET-SIMULATION stops after at most max_levels levels and at most N+(N−p0N)⋅max_levelsN + (N - p_0 N) \cdot \text{max\_levels} calls of gg. 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 P[g(U)≤0]\mathbb{P}[g(U) \le 0], and each chain state of level j+1j + 1 has the law πFj\pi_{F_j} when its seed does.

Proof. Each level does finitely many steps: a sort, and p0Np_0 N chains of 1/p0−11/p_0 - 1 steps, each with at most one call of gg. The loop runs at most max_levels times, then returns or raises an error. Level 1 makes NN calls and each later level at most N−p0NN - p_0 N. The thresholds are nonincreasing as shown after Lemma 1; the returned factors are p0p_0 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. ■\blacksquare

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 FjF_j. If FjF_j 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 NN calls of gg and O(Nd)O(N d) work for the proposals and the sort, so the total is O(mN(C+d))O(m N (C + d)) with m≈ln⁡Pf/ln⁡p0+1m \approx \ln P_f / \ln p_0 + 1 levels. The extra space is O(Nd)O(N d) for the samples of one level. For Pf=10−6P_f = 10^{-6} and N=1000N = 1000, the cost is about 5500 calls, against 10810^8 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 ∣ln⁡Pf∣\lvert \ln P_f \rvert. Each factor of 1/p01/p_0 in rarity adds one level.
  • No gradients. It uses only values of gg.
  • Works in high dimension. The component-wise proposal keeps the acceptance rate from falling to 0 as dd grows.
  • Global. It finds several failure regions, if the first level samples them all.
  • Small bias. Of order 1/N1/N, from the adaptive thresholds.

Variants and improvements

  • Adaptive proposals. Papaioannou and coauthors tune the spread ww 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. p0p_0 between 0.1 and 0.3 works well; a smaller p0p_0 gives fewer levels but a larger error per level.
  • Error estimate from one run. Estimate γj\gamma_j from the correlation of the chain states and combine the δj\delta_j, 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 PfP_f is small, dd 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 gg per run, more than FORM but far fewer than Monte Carlo. If gg is smooth with one design point, FORM with a second-order correction is cheaper. If each call of gg 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 γj\gamma_j large and the error large, as in the 4.5−u14.5 - u_1 row. Monitor the acceptance rate.
  • Missed failure regions. If no seed of level jj lies near a part of FF, later levels do not find it. Use a larger NN 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 gg. 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.

subset_simulation.pyI0RawGitHub
# 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

  1. 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
  2. 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
  3. 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.

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