Skip to content
Back to exploration
General mathematics / English

Improved cross-entropy and original cross-entropy methods

Patrick Laub · YouTube · 6:00

Open original
READ & KEEP

The explanation, unpacked.

Reviewed learning material · Video analysis · English
Read the full overview

This 150-second segment demonstrates the improved cross-entropy method on the concrete problem of estimating P(X>5)P(X>5) for X∼Normal(0,1)X\sim\mathrm{Normal}(0,1). The notebook first defines the zero-variance density g∗g^* as the conditional law of XX given the rare event, then obtains samples from g∗g^* by rejection sampling 5×1085\times 10^8 standard-normal draws and retaining only 152 exceedances. Those retained samples are used to fit a Normal importance-sampling proposal via maximum likelihood, with μ\mu set to the sample mean and σ\sigma to the square root of the sample second central moment. The final cell draws 10610^6 samples from the fitted proposal, computes likelihood ratios times the event indicator, averages them to form L^\hat{L}, and reports a symmetric interval using `1.96 * oHat / sqrt(R)`. The printed result is an ICE estimate of about 2.85×10−72.85\times 10^{-7} with half-width about 8.28×10−108.28\times 10^{-10}, compared against a theoretical value of about 2.87×10−72.87\times 10^{-7}. This 150-second clip explains the original cross-entropy method as an adaptive alternative to direct rejection sampling for rare-event estimation. Using a Jupyter notebook example, it estimates P(X>5)P(X>5) for X~Normal(0,1). The speaker first argues that directly sampling from an ideal proposal is usually too slow, then walks through the cross-entropy loop: draw samples from the current proposal, compute the 95% elite threshold, stop if it reaches gamma, keep elite samples, weight them by likelihood ratios, and update the proposal parameters. After convergence, the video performs a final importance-sampling estimate from the learned proposal and compares the result to the exact normal survival probability. This 60-second clip shows a notebook-based explanation of a cross-entropy rare-event estimator and then shifts to visualizing the proposal distributions generated by the method. The opening seconds display code that samples from a normal proposal, forms likelihood ratios, weights them by the indicator `(normals > γ)`, and prints a CE estimate with confidence bounds plus a theoretical value. The remainder explains that the CE method stored parameter vectors in a list `vs`; by looping over `vs` and evaluating normal PDFs on a grid `xs`, one can plot the whole sequence of proposal densities. The speaker also constructs the target curve `gStar` on the tail region `x>γx > γ` using the known normalizing constant `l = stats.norm.sf(γ)`. The final executed figure shows several colored bell-shaped proposal curves shifting rightward and narrowing, together with a gray dashed vertical line marking the threshold.

Use the learning inspector for key ideas and moments, or open the reading tabs for the complete notes.

Chapters

0:00Problem statement: estimate a standard-normal tail probability0:19Scroll to imports and package versions0:35Define g∗g^* and perform rejection sampling1:27Fit the Normal proposal by maximum likelihood1:43Run importance sampling and report estimate with confidence interval2:30Motivation: why direct rejection sampling is not enough2:48Idea of the original cross-entropy method3:06Notation: u, v, and vs3:28Inside the cross-entropy loop4:35Final importance-sampling estimate and numerical result5:00Displayed CE estimate and confidence bounds5:05Scroll to proposal-visualization code5:10Explanation of stored proposal vectors `vs`5:32Role of `enumerate` in the loop5:45Target density `gStar` and normalizing constant `l`5:54Executed plot of proposal distributions

Learning script

Generated from the video's visuals and explanation; not verbatim speech.

The segment opens with a Jupyter notebook headed `Improved cross-entropy method`. The visible problem statement says to estimate P(X>γ)P(X>\gamma) where X∼Normal(0,1)X\sim\mathrm{Normal}(0,1) and γ=5\gamma=5, using importance-sampling distributions of the form Normal(μ,σ2)\mathrm{Normal}(\mu,\sigma^2). The narration matches this exactly: it introduces a simple rare-event example and says the goal is to find the best importance-sampling density inside the normal family.

The presenter briefly scrolls upward to earlier cells showing Python imports and package versions. This part contains no new mathematics; it only establishes the computational environment (`numpy`, `scipy`, `matplotlib`) used for the rest of the notebook.

Returning to the main example, the notebook states the key conceptual step: to sample from g∗(x)=P(X=x∣X>γ)g^*(x)=\mathbb{P}(X=x\mid X>\gamma), one can sample many ordinary XX values and keep only those with X>γX>\gamma. The narration calls g∗g^* the zero-variance density and explains that it is precisely the distribution of XX conditioned on the rare event. The corresponding code creates a seeded generator, sets `R=5∗10R = 5 * 10**8`, draws `Xs = rng.normal(size=R)`, and filters with `Xs = Xs[Xs > gamma]`. This is explicitly named rejection sampling in the audio.

After execution, the output shows `Number of g* samples: 152` and `Wall time: 12.6 s`. The narrator emphasizes the rarity of the event by noting that from five by ten to the eighth raw samples, only 152 were retained. Mathematically, this output is the empirical consequence of conditioning a standard normal variable on exceeding the high threshold 5.

The next cell fits the importance-sampling proposal to those retained samples. The code computes `mu = np.mean(Xs)` and `sigma = np.sqrt(np.mean((Xs-mu)**2))`, while the narration describes this as finding maximum likelihood estimates for μ\mu and σ\sigma given the samples. In other words, the Normal proposal is centered at the empirical mean of the exceedance sample and given the empirical root second central moment as its scale.

The final cell carries out the actual importance-sampling estimate. It resets `R=10R = 10**6`, draws `normals = rng.normal(mu, sigma, R)` from the fitted proposal, and computes likelihood ratios as `stats.norm.pdf(normals, 0, 1) / stats.norm.pdf(normals, mu, sigma)`. These ratios are multiplied by `(normals > gamma)` to form `ests`, then averaged into `lHat`. The narrator says the improved cross-entropy algorithm is now complete and has supplied a good proposal distribution, after which they proceed with a normal importance-sampling estimation and print the estimate and confidence intervals.

The output block gives the numerical conclusion: `ICE estimate: 2.8499557494141556e-07 (+/- 8.28267698086911e-10)`, `ICE low bound: 2.841672802433268e-07`, `ICE upp bound: 2.8582381563950423e-07`, and `Theoretical: 2.866515718791933e-07`. The code also computes `oHat = ests.std()` and `widthCI = 1.96 * oHat / np.sqrt(R)`, so the printed interval is symmetric around `lHat`. The narration summarizes this as a rare-event probability of about 2.8×10−72.8\times 10^{-7} with interval width on the order of 10−1010^{-10}, calling the precision impressively small.

The clip opens by contrasting the present method with a previous example. The speaker says that earlier approach “kind of cheated,” because the rare event was not very rare, so one could sample directly from g∗g^* by rejection sampling. The mathematical point is that direct sampling from an ideal proposal is not generally scalable for rarer events.

To avoid that bottleneck, the video introduces the original cross-entropy method. The core idea is adaptive: instead of guessing one perfect proposal immediately, build a sequence of proposal distributions that improve step by step until one is good enough for the rare-event region.

The notebook notation is then clarified. The vector `u` stores the parameters of the original distribution, here the standard normal (0,1)(0,1), while `v` stores the current proposal parameters and `vs` records the sequence of proposals over iterations. This establishes the distinction between the target law and the adaptive sampling law.

Inside the loop, the algorithm first draws R=105R=10^5 samples from the current proposal Normal(v[0],v[1])\mathrm{Normal}(v[0],v[1]). It then computes the iteration threshold γi\gamma_i as the empirical 95%95\% quantile, equivalently the (1−p)(1-p)-quantile with p=0.05p=0.05. If γi≥γ=5\gamma_i\ge \gamma=5, the adaptation stops; otherwise the samples above γi\gamma_i are treated as elites.

For those elite samples, the code forms likelihood ratios eliteLRs=fu(x)/fv(x)\text{eliteLRs}= f_u(x)/f_v(x), where fuf_u is the original standard normal density and fvf_v is the current proposal density. These weights are essential: the update is not a plain average of elites, but a likelihood-ratio-weighted refinement of the proposal parameters.

The proposal is then updated to v=(μi,σi)v=(\mu_i,\sigma_i), with μi\mu_i computed as a weighted average of the elites and σi\sigma_i computed from a weighted second-moment expression. The speaker describes this as a maximum likelihood update from elite samples, although the displayed variance formula centers on `eliteXs.mean()` rather than `mu_i`; that distinction should be checked against the intended textbook derivation.

After the cross-entropy loop finishes, the method switches from adaptation to estimation. One million fresh samples are drawn from the final proposal, likelihood ratios are recomputed, and the rare-event probability is estimated by averaging lrs⋅1{normals>γ}\text{lrs}\cdot \mathbf{1}_{\{\text{normals}>\gamma\}}. This is a standard importance-sampling estimator built on the proposal discovered by the cross-entropy search.

The printed result gives a CE estimate of about 2.84×10−72.84\times 10^{-7} with an approximate half-width around 1.1×10−81.1\times 10^{-8}, compared with the theoretical value 2.8665×10−72.8665\times 10^{-7} from `stats.norm.sf(5)`. The speaker emphasizes that the estimate is close in magnitude to the truth, but the confidence interval width is relatively wide on the order of 10−810^{-8}.

The clip opens on a notebook cell implementing a cross-entropy style estimator. The visible code draws `R=10R = 10**6` samples from a normal proposal with parameters `v[0]` and `v[1]`, computes likelihood ratios between normal densities with parameters `u` and `v`, multiplies those ratios by the rare-event indicator `(normals > γ)`, and then averages the result to obtain `fHat`. A confidence half-width is formed as `widthCI = 1.96 * oHat / np.sqrt(R)`. The output block reports `CE estimate: 2.8433488092847927e-07 (+/- 1.1057152778688466e-08)` and `Theoretical: 2.866515718791933e-07`, so the numerical example directly compares the Monte Carlo estimate with a theoretical benchmark.

The page then scrolls down to a new code cell whose purpose is geometric rather than numerical. This transition signals that the discussion is moving from a single estimated probability to the shape and evolution of the proposal distributions used by the method.

The speaker says, “Let’s visualize the sequence of proposal distributions that the CE method constructed.” The code below creates a grid `xs = np.linspace(-2, 6.5, 500)` and allocates `ys = np.empty((len(xs), len(vs)))`. The key mathematical idea is that each stored parameter vector `v` defines one normal proposal density, and evaluating that density on a common x-grid makes the different proposals directly comparable in one plot.

The explanation continues that during the CE run, the algorithm stored the `v` vectors in a list named `vs`. Therefore `vs` is not just auxiliary bookkeeping; it is the record of the adaptive sequence of proposal laws. Looping over `vs` reconstructs the path taken by the method through parameter space.

Inside the loop, the code uses `for i, v in enumerate(vs): ys[:,i] = stats.norm.pdf(xs, v[0], v[1])`. Mathematically, column `i` of `ys` is the function x↦ϕ(x;v[0],v[1])x \mapsto \phi(x; v[0], v[1]) sampled on the grid `xs`, where ϕ\phi denotes the normal PDF with mean `v[0]` and standard deviation `v[1]`. Plotting all columns together therefore overlays the entire sequence of proposal densities.

The speaker explicitly clarifies the programming construct: `enumerate` returns both the index `i` and the element `v`. This matters here because the index labels which iteration of the CE method produced which proposal vector, allowing the visual sequence to be ordered correctly.

The final part of the code cell constructs the target curve for comparison. First the grid is restricted to the tail region with `xOverGamma = xs[xs > γ]`. Then the normalizing constant is set to `l = stats.norm.sf(γ)`, and the plotted target density is `gStar = stats.norm.pdf(xOverGamma) / l`. In words, the target shown in the figure is the standard normal density conditioned to the region above `γ` and renormalized so that it integrates to one on that tail domain.

When the cell is executed, a figure appears below the code. It contains several colored bell-shaped curves corresponding to successive proposal distributions, plus a gray dashed vertical line marking the threshold `γ`. Visually, the curves move rightward and become narrower as the sequence progresses, illustrating how the cross-entropy method adapts its proposals toward the rare-event region. The normalized target curve is plotted on the same tail region, enabling direct comparison between the learned proposals and the target density.

Knowledge cards

01

Problem setup: estimate a normal tail probability

The worked example asks for P(X>γ)P(X>\gamma) when X∼Normal(0,1)X\sim\mathrm{Normal}(0,1) and γ=5\gamma=5. The method searches within Normal proposals Normal(μ,σ2)\mathrm{Normal}(\mu,\sigma^2) for an importance-sampling density suitable for this rare-event probability.

P(X>γ),X∼Normal(0,1),γ=5P(X > \gamma),\quad X \sim \mathrm{Normal}(0,1),\quad \gamma=5
02

Zero-variance density g∗g^*

The notebook defines the ideal density as g∗(x)=P(X=x∣X>γ)g^*(x)=\mathbb{P}(X=x\mid X>\gamma), i.e. the conditional distribution of XX given that the rare event occurs. This is the density that would make the importance-sampling estimator have zero variance.

g∗(x)=P(X=x∣X>γ)g^*(x)=\mathbb{P}(X=x\mid X>\gamma)
03

Rejection sampling to obtain g∗g^* samples

Because g∗g^* is just the original law conditioned on X>γX>\gamma, the video samples many standard-normal variates and keeps only those exceeding the threshold. In code this is `Xs = rng.normal(size=R)` followed by `Xs = Xs[Xs > gamma]`, with R=5×108R=5\times 10^8.

Keep {Xi:Xi>γ},Xi∼Normal(0,1)\text{Keep } \{X_i:X_i>\gamma\},\quad X_i\sim\mathrm{Normal}(0,1)
04

Result of the rejection stage

The executed notebook reports that only 152 samples survived the filter from the 5×1085\times 10^8 raw draws. This tiny acceptance count illustrates why direct simulation is inefficient for such a rare event.

05

Fitting the Normal proposal by maximum likelihood

The retained g∗g^* samples are used to fit the proposal distribution. The code sets `mu = np.mean(Xs)` and `sigma = np.sqrt(np.mean((Xs-mu)**2))`, and the narration identifies these as maximum likelihood estimates for the Normal proposal parameters.

μ^=1n∑i=1nXi∗,σ^=1n∑i=1n(Xi∗−μ^)2\hat{\mu}=\frac{1}{n}\sum_{i=1}^{n}X_i^{*},\qquad \hat{\sigma}=\sqrt{\frac{1}{n}\sum_{i=1}^{n}(X_i^{*}-\hat{\mu})^2}
06

Importance-sampling estimator

With the fitted proposal, the final cell draws 10610^6 samples from Normal(μ^,σ^2)\mathrm{Normal}(\hat{\mu},\hat{\sigma}^2), computes likelihood ratios f/qf/q, multiplies by the indicator of the event X>γX>\gamma, and averages the result to obtain `lHat`.

L^=1R∑j=1Rf(Zj)q(Zj)1{Zj>γ}\hat{L}=\frac{1}{R}\sum_{j=1}^{R}\frac{f(Z_j)}{q(Z_j)}\mathbf{1}_{\{Z_j>\gamma\}}
07

Confidence interval reported by the notebook

The code computes `oHat = ests.std()` and `widthCI = 1.96 * oHat / np.sqrt(R)`, then prints bounds as `lHat-widthCI` and `lHat+widthCI`. Thus `widthCI` is the half-width of a symmetric interval around the estimate.

L^±1.96 o^R\hat{L}\pm 1.96\,\frac{\hat{o}}{\sqrt{R}}
08

Numerical outcome and theoretical check

The printed estimate is about 2.85×10−72.85\times 10^{-7} with half-width about 8.28×10−108.28\times 10^{-10}, while the theoretical standard-normal survival probability at 5 is about 2.87×10−72.87\times 10^{-7}. The narration highlights the very small interval width as evidence of the method's efficiency.

09

Why direct rejection sampling is insufficient

The video begins by saying the earlier example “cheated” because the rare event was not very rare, allowing direct sampling from g∗g^* by rejection sampling. For genuinely rare events, that route would generally take too long, motivating an adaptive method instead.

10

Core idea of the original cross-entropy method

The original cross-entropy method constructs a sequence of proposal distributions that improve iteratively. The process stops once a proposal is good enough for estimating the rare-event probability P(X>γ)\mathbb{P}(X>\gamma).

11

Roles of u, v, and vs in the notebook

`u` stores the parameters of the original distribution, here (0,1)(0,1) for the standard normal. `v` stores the current proposal parameters, and `vs` accumulates the successive proposal vectors during the cross-entropy iterations.

u=(0,1),v←(μi,σi),vs=[v0,v1,… ]u=(0,1),\quad v\leftarrow(\mu_i,\sigma_i),\quad vs=[v_0,v_1,\dots]
12

Cross-entropy loop: sampling and elite threshold

At each iteration, draw RR samples from the current proposal Normal(v[0],v[1])\mathrm{Normal}(v[0],v[1]). Compute γi\gamma_i as the empirical (1−p)(1-p)-quantile, with p=0.05p=0.05, so this is the 95% threshold. If γi≥γ\gamma_i\ge \gamma, stop; otherwise keep the samples above γi\gamma_i as elites.

γi=Q1−p(Xs),p=0.05\gamma_i = Q_{1-p}(X_s),\quad p=0.05
13

Likelihood-ratio weighting of elite samples

For elite samples, compute weights as the ratio of the original density to the current proposal density. The speaker explicitly warns that these likelihood ratios must be used when updating the proposal parameters.

w(x)=fu(x)fv(x)w(x)=\frac{f_u(x)}{f_v(x)}
14

Proposal update from weighted elites

The next proposal mean and scale are computed from weighted elite summaries. The mean is a weighted average of elites; the scale is a weighted standard-deviation-type quantity. The spoken description calls this a maximum likelihood update, while the displayed variance formula uses `eliteXs.mean()` inside the squared deviation.

μi=avg⁡w(x),σi=avg⁡w((x−xˉelite)2)\mu_i=\operatorname{avg}_w(x),\quad \sigma_i=\sqrt{\operatorname{avg}_w\big((x-\bar{x}_{\text{elite}})^2\big)}
15

Final importance-sampling estimator after CE

Once the cross-entropy loop ends, the converged proposal is used for ordinary importance sampling. Draw fresh samples from the final proposal, multiply the rare-event indicators by likelihood ratios, and average to estimate the tail probability.

p^=1R∑j=1Rfu(Yj)fv(Yj)1{Yj>γ}\hat{p}=\frac{1}{R}\sum_{j=1}^{R}\frac{f_u(Y_j)}{f_v(Y_j)}\mathbf{1}_{\{Y_j>\gamma\}}
16

Numerical result for P(X>5)P(X>5)

For X∼Normal(0,1)X\sim\mathrm{Normal}(0,1) and γ=5\gamma=5, the displayed estimate is about 2.84×10−72.84\times10^{-7} with an approximate confidence half-width around 1.1×10−81.1\times10^{-8}, compared with the theoretical value 2.8665×10−72.8665\times10^{-7} from the normal survival function.

p^≈2.8433×10−7,ptheory≈2.8665×10−7\widehat{p}\approx 2.8433\times10^{-7},\quad p_{\text{theory}}\approx 2.8665\times10^{-7}
17

Cross-entropy weighted estimator shown in code

The opening notebook cell implements a rare-event estimator by sampling from a normal proposal, computing likelihood ratios between two normal densities, and multiplying by the indicator of the event `normals > γ`. The estimate is the sample mean of these weighted indicators, and the code also reports an approximate confidence half-width using `1.96 * oHat / np.sqrt(R)`. The printed output compares the estimate with a theoretical value.

ests=lrs∗(normals>γ);fHat=ests.mean();widthCI=1.96∗oHat/np.sqrt(R)ests = lrs * (normals > γ); fHat = ests.mean(); widthCI = 1.96 * oHat / np.sqrt(R)
18

Numerical CE estimate versus theoretical value

The visible output gives `CE estimate: 2.8433488092847927e-07 (+/- 1.1057152778688466e-08)` and `Theoretical: 2.866515718791933e-07`. This example shows both the stochastic estimate and a deterministic benchmark for the same rare-event probability.

CEestimate:2.8433488092847927e−07;Theoretical:2.866515718791933e−07CE estimate: 2.8433488092847927e-07; Theoretical: 2.866515718791933e-07
19

Stored proposal vectors `vs` record the CE path

The speaker explains that as the CE method ran, it stored the parameter vectors `v` in a list named `vs`. Each element of `vs` represents one proposal distribution in the adaptive sequence, so looping over `vs` reconstructs the method’s evolution over iterations.

20

Evaluating each proposal PDF on a common grid

To visualize the proposals, the code builds a grid `xs = np.linspace(-2, 6.5, 500)` and fills a matrix `ys` whose columns are the normal PDFs corresponding to each stored vector `v`. The loop `for i, v in enumerate(vs): ys[:,i] = stats.norm.pdf(xs, v[0], v[1])` therefore converts parameter history into comparable density curves.

fori,vinenumerate(vs):ys[:,i]=stats.norm.pdf(xs,v[0],v[1])for i, v in enumerate(vs): ys[:,i] = stats.norm.pdf(xs, v[0], v[1])
21

Meaning of `enumerate` in the plotting loop

The narration explicitly states that `enumerate` is a convenience function returning both the index `i` and the element `v`. In this context, the index identifies the position of a proposal in the stored sequence, while `v` supplies its normal-distribution parameters.

22

Construction of the normalized target density `gStar`

The target curve plotted in the figure is built only on the tail region `x>γx > γ`. The code first selects `xOverGamma = xs[xs > γ]`, then computes `l = stats.norm.sf(γ)`, and finally defines `gStar = stats.norm.pdf(xOverGamma) / l`. The speaker identifies `l` as the known normalizing constant in this simple case.

xOverGamma=xs[xs>γ];l=stats.norm.sf(γ);gStar=stats.norm.pdf(xOverGamma)/lxOverGamma = xs[xs > γ]; l = stats.norm.sf(γ); gStar = stats.norm.pdf(xOverGamma) / l
23

Final plot shows evolving proposals and threshold

After execution, the figure displays multiple colored bell-shaped proposal curves together with a gray dashed vertical line at the threshold. The visual pattern shows the proposals shifting rightward and narrowing, illustrating adaptation toward the rare-event region and enabling comparison with the target density on the same axes.

Detailed learning notes

Explore conditions, steps and evidence. Supplementary explanations are labeled separately from content shown in the video.

Symbols · 46

γ\gamma

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The notebook text states `gamma = 5` and the problem statement uses `P(X > gamma)`.

  2. Audio
    Observation

    The narrator says the example estimates when a standard normal variable exceeds a large threshold gamma.

Symbol

γ\gamma

Meaning

Threshold defining the rare event X>γX>\gamma.

Domain

Real number; in this example γ=5\gamma=5.

X

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The notebook states `X ~ Normal(0, 1)`.

  2. Audio
    Observation

    The narrator refers to a standard normal variable.

Symbol

X

Meaning

Random variable whose exceedance probability is being estimated.

Domain

X∼Normal(0,1)X \sim \mathrm{Normal}(0,1).

g^*

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The notebook writes `g∗(x)=Pg*(x) = P(X=xX = x | X > gamma)`.

  2. Audio
    Observation

    The narrator calls it the zero-variance density g∗g^* and explains it as the distribution of XX conditioned on the rare event happening.

Uncertainties
  1. The displayed notation uses `P(X=xX = x | X > gamma)` for a continuous random variable; the video does not discuss this notational issue.

Symbol

g^*

Meaning

Zero-variance importance-sampling density, equal to the conditional distribution of XX given X>γX>\gamma.

Domain

Density over x>γx>\gamma.

μ\mu

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `mu = np.mean(Xs)` under the comment about fitting the IS proposal distribution.

  2. Audio
    Observation

    The narrator says the proposal density is created by finding maximum likelihood estimates for mu and sigma.

Symbol

μ\mu

Meaning

Mean parameter of the fitted Normal importance-sampling proposal distribution.

Domain

Real number estimated from the retained g∗g^* samples.

σ\sigma

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `sigma = np.sqrt(np.mean((Xs-mu)**2))`.

  2. Audio
    Observation

    The narrator says the proposal density is created by finding maximum likelihood estimates for mu and sigma.

Symbol

σ\sigma

Meaning

Standard deviation parameter of the fitted Normal importance-sampling proposal distribution.

Domain

Positive real number estimated from the retained g∗g^* samples.

R

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The first simulation cell sets `R=5∗10R = 5 * 10**8` before drawing `rng.normal(size=R)`.

  2. Audio
    Observation

    The narrator says they simulate five by ten to the eighth samples of X's.

Symbol

R

Meaning

Number of raw standard-normal draws used for rejection sampling to obtain g∗g^* samples.

Domain

In the first cell, R=5×108R=5\times 10^8.

R

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The final estimation cell sets `R=10R = 10**6` before drawing `normals = rng.normal(mu, sigma, R)`.

Uncertainties
  1. The same symbol name `R` is reused with a different value in a later cell.

Symbol

R

Meaning

Number of samples drawn from the fitted importance-sampling proposal distribution.

Domain

In the final cell, R=106R=10^6.

lrs

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `lrs = stats.norm.pdf(normals, 0, 1) / stats.norm.pdf(normals, mu, sigma)`.

  2. Audio
    Observation

    The narrator says they proceed with a normal importance sampling estimation.

Symbol

lrs

Meaning

Likelihood ratios (importance weights) f(x)/g(x)f(x)/g(x) evaluated at proposal samples.

Domain

Positive real values for each sampled `normals` point.

ests

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `ests = lrs * (normals > gamma)`.

Symbol

ests

Meaning

Weighted indicator estimates for the rare event, equal to the likelihood ratio when the proposal sample exceeds γ\gamma and zero otherwise.

Domain

Nonnegative real array.

L^\hat{L}

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `lHat = ests.mean()` and prints `ICE estimate`.

  2. Audio
    Observation

    The narrator says they print out the probability estimate L hat.

Symbol

L^\hat{L}

Meaning

Importance-sampling estimate of P(X>γ)P(X>\gamma), computed as the sample mean of `ests`.

Domain

Real number; printed value is approximately 2.8499557494141556×10−72.8499557494141556\times 10^{-7}.

o^\hat{o}

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `oHat = ests.std()`.

Symbol

o^\hat{o}

Meaning

Sample standard deviation of the weighted estimator array `ests`, used to form the confidence-interval half-width.

Domain

Nonnegative real number.

widthCI

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `widthCI = 1.96 * oHat / np.sqrt(R)`.

  2. Audio
    Observation

    The narrator says the estimate has a confidence interval width in the order of ten to the minus ten.

Uncertainties
  1. The code labels this quantity `widthCI`, but numerically it is the half-width of a symmetric interval because it is added to and subtracted from `lHat`.

Symbol

widthCI

Meaning

Half-width of the reported confidence interval for the importance-sampling estimate.

Domain

Positive real number; printed value is approximately 8.28267698086911×10−108.28267698086911\times 10^{-10}.

Knowledge points · 13

Problem setup for rare-event estimation

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The notebook heading reads `Improved cross-entropy method` and the text states `Use the improved cross-entropy method to estimate P(X > gamma) where X ~ Normal(0, 1) and gamma = 5. Consider importance sampling distributions of the form Normal(mu, sigma^2).`

  2. Audio
    Observation

    The narrator introduces a simple example estimating the probability that a standard normal variable exceeds a large threshold gamma, and says they will find the best importance sampling density within the family of normal distributions.

Definition
Explanation

The segment defines the target quantity as the exceedance probability P(X>γ)P(X>\gamma) for a standard normal random variable, with γ=5\gamma=5, and restricts the importance-sampling proposal family to Normal distributions parameterized by (μ,σ2)(\mu,\sigma^2).

Formula
P(X>γ),X∼Normal(0,1),γ=5,q(x)=Normal(μ,σ2)P(X > \gamma),\quad X \sim \mathrm{Normal}(0,1),\quad \gamma=5,\quad q(x)=\mathrm{Normal}(\mu,\sigma^2)
Conditions
  1. The original distribution is standard normal.

  2. The rare event is X>γX>\gamma.

  3. The proposal family is restricted to Normal distributions.

Zero-variance density as the conditional law given the rare event

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The notebook text states `First, to sample from g∗(x)=Pg*(x) = P(X=xX = x | X > gamma), just sample lots of X's and extract those X > gamma.`

  2. Audio
    Observation

    The narrator says the first step is to sample from the zero-variance density g∗g^*, which is the distribution of XX conditioned on the rare event happening.

Uncertainties
  1. The displayed formula uses `P(X=xX = x | X > gamma)` for a continuous variable; the video does not clarify this notation.

Definition
Explanation

The video identifies the ideal importance-sampling density g∗g^* as the conditional distribution of XX given that the rare event occurs, i.e. given X>γX>\gamma. This is the density that would make the importance-sampling estimator have zero variance.

Formula
g∗(x)=P(X=x∣X>γ)g^*(x)=\mathbb{P}(X=x\mid X>\gamma)
Conditions
  1. Applies to the rare-event probability P(X>γ)P(X>\gamma).

  2. g∗g^* is supported only on the event region x>γx>\gamma.

Prerequisites
  1. Problem setup for rare-event estimation

Rejection sampling to obtain samples from g∗g^*

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code cell performs `Xs = rng.normal(size=R)` followed by `Xs = Xs[Xs > gamma]`.

  2. Audio
    Observation

    The narrator says they can sample lots of X's and just keep those which exceed the threshold, and explicitly names this procedure rejection sampling.

Method
Explanation

Because g∗g^* is the conditional law of XX given X>γX>\gamma, the video obtains approximate g∗g^* samples by drawing many raw standard-normal variates and retaining only those larger than the threshold. The retained subset is then treated as samples from g∗g^*.

Formula
Draw X1,…,XR∼Normal(0,1),keep {Xi:Xi>γ}\text{Draw } X_1,\dots,X_R \sim \mathrm{Normal}(0,1),\quad \text{keep } \{X_i:X_i>\gamma\}
Conditions
  1. Requires direct sampling from the original distribution X∼Normal(0,1)X\sim\mathrm{Normal}(0,1).

  2. The acceptance rule is Xi>γX_i>\gamma.

  3. The retained samples are used to estimate the parameters of the proposal distribution.

Prerequisites
  1. Zero-variance density as the conditional law given the rare event

Maximum likelihood fit of the Normal proposal to the g∗g^* samples

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `mu = np.mean(Xs)` and `sigma = np.sqrt(np.mean((Xs-mu)**2))` under the comment `# Fit our IS proposal distribution to these g* samples`.

  2. Audio
    Observation

    The narrator says they create the importance sampling proposal density by finding the maximum likelihood estimates for mu and sigma given these samples.

Method
Explanation

After obtaining samples from g∗g^*, the video fits a Normal importance-sampling proposal by setting its mean to the sample mean and its standard deviation to the square root of the sample second central moment of those retained samples.

Formula
μ^=1n∑i=1nXi∗,σ^=1n∑i=1n(Xi∗−μ^)2\hat{\mu}=\frac{1}{n}\sum_{i=1}^{n}X_i^{*},\qquad \hat{\sigma}=\sqrt{\frac{1}{n}\sum_{i=1}^{n}(X_i^{*}-\hat{\mu})^2}
Conditions
  1. The fitted proposal family is Normal.

  2. The data used for fitting are the retained samples satisfying X>γX>\gamma.

  3. The estimator for σ\sigma uses division by nn, matching the code `np.mean((Xs-mu)**2)` rather than an unbiased sample variance.

Prerequisites
  1. Rejection sampling to obtain samples from g∗g^*
  2. Problem setup for rare-event estimation

Normal importance-sampling estimator for P(X>γ)P(X>\gamma)

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `lrs = stats.norm.pdf(normals, 0, 1) / stats.norm.pdf(normals, mu, sigma)`, then `ests = lrs * (normals > gamma)`, then `lHat = ests.mean()`.

  2. Audio
    Observation

    The narrator says the improved cross-entropy algorithm is complete and supplies a good importance sampling proposal distribution, after which they proceed with a normal importance sampling estimation and print the probability estimate L hat.

Formula
Explanation

Using the fitted proposal density, the video estimates the rare-event probability by averaging likelihood ratios times the rare-event indicator over samples drawn from the proposal. This is the standard importance-sampling estimator specialized to the indicator event X>γX>\gamma.

Formula
L^=1R∑j=1Rf(Zj)q(Zj)1{Zj>γ},Zj∼q=Normal(μ^,σ^2)\hat{L}=\frac{1}{R}\sum_{j=1}^{R}\frac{f(Z_j)}{q(Z_j)}\mathbf{1}_{\{Z_j>\gamma\}},\quad Z_j\sim q=\mathrm{Normal}(\hat{\mu},\hat{\sigma}^2)
Conditions
  1. ff is the standard normal density.

  2. qq is the fitted Normal proposal density.

  3. Samples ZjZ_j are drawn from qq, not from ff.

  4. The event indicator is 1{Zj>γ}\mathbf{1}_{\{Z_j>\gamma\}}.

Prerequisites
  1. Maximum likelihood fit of the Normal proposal to the g∗g^* samples
  2. Problem setup for rare-event estimation

Reported confidence interval for the importance-sampling estimate

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `oHat = ests.std()` and `widthCI = 1.96 * oHat / np.sqrt(R)`, then prints low and upper bounds as `lHat-widthCI` and `lHat+widthCI`.

Uncertainties
  1. The video does not verbally justify the use of 1.96 or state the normal approximation assumption behind the interval.

Formula
Explanation

The notebook reports a symmetric interval around the estimate using 1.96 times the sample standard deviation of the weighted estimator divided by the square root of the number of proposal samples. The printed bounds are therefore L^±\hat{L}\pm `widthCI`.

Formula
L^±1.96 o^R,o^=std⁡(ests)\hat{L}\pm 1.96\,\frac{\hat{o}}{\sqrt{R}},\qquad \hat{o}=\operatorname{std}(\text{ests})
Conditions
  1. Uses the sample standard deviation of `ests`.

  2. Uses the same RR as the number of proposal samples in the final cell.

  3. The interval is presented as a numerical summary; the video does not derive its coverage properties.

Prerequisites
  1. Normal importance-sampling estimator for P(X>γ)P(X>\gamma)

Purpose of the original cross-entropy method

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker introduces the original cross-entropy method as a way around the problem that direct rejection sampling would take too long.

  2. Formula
    Observation

    Markdown heading reads `Cross-entropy method` and states `Use the cross-entropy method to estimate P(X > gamma) where X ~ Normal(0, 1) and gamma = 5`.

Definition
Explanation

The video presents the original cross-entropy method as an adaptive Monte Carlo strategy for rare-event probability estimation. Instead of sampling directly from a target proposal distribution, it constructs a sequence of proposal distributions that improve iteratively until one is good enough for estimating P(X>γ)\mathbb{P}(X>\gamma).

Formula
Conditions
  1. Used when direct sampling from a good proposal distribution is impractical or too slow.

  2. Applied here to estimate a tail probability for a normal random variable.

Iterative construction of proposal distributions

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says the idea is to construct a sequence of proposal distributions which get better and better, and to stop when we get a proposal distribution which is good enough.

Method
Explanation

The cross-entropy method builds a sequence of proposal distributions rather than relying on one fixed proposal. Each iteration refines the parameters so the proposal becomes more effective for the rare-event region, and the process stops once the proposal is deemed sufficient.

Formula
Conditions
  1. Requires an update rule for proposal parameters.

  2. Stopping criterion is based on whether the iteration threshold reaches the target rare-event level.

Prerequisites
  1. Purpose of the original cross-entropy method

Normal tail-probability estimation example

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Markdown states `Use the cross-entropy method to estimate P(X > gamma) where X ~ Normal(0, 1) and gamma = 5`.

  2. Formula
    Observation

    Code sets `u=(0,1)u = (0, 1)` and compares against `stats.norm.sf(gamma)`.

Method
Explanation

The worked example estimates the upper-tail probability P(X>5)\mathbb{P}(X>5) for X∼Normal(0,1)X\sim\mathrm{Normal}(0,1). The original distribution is encoded by `u=(0,1)u=(0,1)`, and the theoretical benchmark is computed with `stats.norm.sf(gamma)`.

Formula
P(X>γ),X∼Normal(0,1),γ=5\mathbb{P}(X>\gamma),\quad X\sim\mathrm{Normal}(0,1),\quad \gamma=5
Conditions
  1. Original distribution is standard normal.

  2. Target event is exceedance of a fixed threshold γ\gamma.

Prerequisites
  1. Purpose of the original cross-entropy method

Final estimation step after cross-entropy adaptation

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says once CE has finished, they take the proposal distribution it has found and run a normal important sampling estimation.

  2. Formula
    Observation

    Second code cell samples `normals = rng.normal(v[0], v[1], R)` and computes `ests = lrs * (normals > gamma)`.

Method
Explanation

After the cross-entropy loop identifies a proposal distribution, the video performs a separate importance-sampling estimate from that proposal. Samples are drawn from the converged normal proposal, likelihood ratios relative to the original distribution are computed, and the indicator of the rare event is averaged with those weights.

Formula
p^=1R∑j=1Rfu(Xj)fv(Xj)1{Xj>γ},Xj∼fv\widehat{p}=\frac{1}{R}\sum_{j=1}^{R} \frac{f_u(X_j)}{f_v(X_j)}\mathbf{1}_{\{X_j>\gamma\}},\quad X_j\sim f_v
Conditions
  1. Uses the final proposal parameters stored in `v` after the CE loop.

  2. Requires computing likelihood ratios between original and proposal densities.

Prerequisites
  1. Iterative construction of proposal distributions
  2. Normal tail-probability estimation example

Cross-entropy weighted estimator and confidence interval

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Visible code computes `lrs`, then `ests = lrs * (normals > γ)`, then `fHat = ests.mean()` and `widthCI = 1.96 * oHat / np.sqrt(R)`.

  2. Formula
    Observation

    Output prints `CE estimate`, `CE low bound`, `CE upp bound`, and `Theoretical`.

Method
Explanation

This clip shows a Monte Carlo implementation in which samples are drawn from a normal proposal, likelihood ratios between two normal densities are computed, and those ratios are multiplied by the indicator of the rare event `normals > γ`. The estimator is the sample mean of these weighted indicators, and an approximate confidence interval is built from the sample standard deviation divided by `sqrt(R)` and multiplied by `1.96`.

Formula
ests=lrs∗(normals>γ);fHat=ests.mean();widthCI=1.96∗oHat/np.sqrt(R)ests = lrs * (normals > γ); fHat = ests.mean(); widthCI = 1.96 * oHat / np.sqrt(R)
Conditions
  1. Samples are drawn from a normal proposal with parameters `v[0]`, `v[1]`.

  2. Likelihood ratios use normal densities with parameters `u` and `v`.

  3. The rare event is defined by the threshold `γ`.

  4. `R` is the number of samples.

Visualizing the sequence of CE proposal distributions

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    Speaker says, 'Let's visualize the sequence of proposal distributions that the CE method constructed.'

  2. Formula
    Observation

    Code loops over `vs` and assigns `ys[:,i] = stats.norm.pdf(xs, v[0], v[1])`.

  3. Diagram
    Observation

    A plot later displays multiple colored bell-shaped curves shifting rightward and narrowing.

Method
Explanation

The speaker explains that the cross-entropy method stores each parameter vector `v` in a list called `vs`. By looping through `vs` and evaluating `stats.norm.pdf(xs, v[0], v[1])` on a common grid `xs`, one can plot the entire sequence of proposal densities generated during the algorithm.

Formula
fori,vinenumerate(vs):ys[:,i]=stats.norm.pdf(xs,v[0],v[1])for i, v in enumerate(vs): ys[:,i] = stats.norm.pdf(xs, v[0], v[1])
Conditions
  1. `vs` contains the stored proposal parameter vectors.

  2. `xs` is a fixed grid of x-values.

Prerequisites
  1. Cross-entropy weighted estimator and confidence interval
Claims and conditions · 6

Completion of the improved cross-entropy construction

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The narrator says: `The improved cross entropy algorithm is now complete, and it has supplied us with a good importance sampling proposal distribution.`

Uncertainties
  1. The claim that the proposal is `good` is qualitative and not accompanied by a formal criterion in this clip.

Proposition
Statement

After fitting (μ^,σ^)(\hat{\mu},\hat{\sigma}) to the retained g∗g^* samples, the improved cross-entropy procedure has produced the importance-sampling proposal distribution used for estimation.

Hypotheses
  1. The rare-event model is X∼Normal(0,1)X\sim\mathrm{Normal}(0,1) and the target is P(X>γ)P(X>\gamma).

  2. Samples from g∗g^* have been obtained by rejection sampling.

  3. A Normal proposal has been fitted by maximum likelihood to those samples.

Quantifiers

For the worked example in this notebook segment.

Numerical result for the rare-event probability and interval width

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The output block prints `ICE estimate: 2.8499557494141556e-07 (+/- 8.28267698086911e-10)` and `Theoretical: 2.866515718791933e-07`.

  2. Audio
    Observation

    The narrator says the rare event has probability two point eight by ten to the minus seven and the estimate has a confidence interval width in the order of ten to the minus ten.

Uncertainties
  1. The spoken `two point eight by ten to the minus seven` rounds the displayed value; the exact displayed estimate is visible on screen.

Proposition
Statement

For this example, the importance-sampling estimate of the rare-event probability is about 2.85×10−72.85\times 10^{-7}, with reported half-width about 8.28×10−108.28\times 10^{-10}, and the theoretical benchmark is about 2.87×10−72.87\times 10^{-7}.

Hypotheses
  1. γ=5\gamma=5.

  2. The proposal was fitted as described in the notebook.

  3. The final estimate uses R=106R=10^6 proposal samples.

Quantifiers

For the specific simulation shown in the output cells.

Direct rejection sampling from a good proposal is generally too slow

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says that in the earlier example they kind of cheated because the rare event was not very rare, so they could sample from g star directly using rejection sampling, but in general this would take too long.

Proposition
Statement

When the rare event is sufficiently rare, directly sampling from the ideal proposal distribution by rejection sampling is computationally impractical.

Hypotheses
  1. The target event is rare enough that direct acceptance from the ideal proposal is inefficient.

Quantifiers

General practical claim stated verbally without formal proof.

Cross-entropy stopping condition in the displayed implementation

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says the threshold for this iteration is set to be the 95% threshold of the X samples, and if this is above the overall goal of gamma, they stop iterating.

  2. Formula
    Observation

    Code shows `gamma_i = np.quantile(Xs, 1-p)` and `if gamma_i >= gamma: break` with `p=0.05p = 0.05`.

Proposition
Statement

In this implementation, the iteration stops when the empirical elite threshold γi\gamma_i is at least the target threshold γ\gamma.

Hypotheses
  1. Samples `Xs` are drawn from the current proposal.

  2. `p=0.05p = 0.05`, so `1−p=0.951-p = 0.95`.

  3. The target threshold is `gamma = 5`.

Quantifiers

For each iteration ii, if γi≥γ\gamma_i\ge \gamma, then break.

Proposal parameters are updated from weighted elite samples

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says they update the v parameters to be the maximum likelihood estimates of the elite samples, and must weight the samples by their likelihood ratios.

  2. Formula
    Observation

    Code shows weighted averages for `mu_i` and `sigma_i` using `weights=eliteLRs`.

Uncertainties
  1. The spoken justification says maximum likelihood estimates, but the displayed variance formula centers on `eliteXs.mean()` rather than `mu_i`.

Proposition
Statement

The next proposal parameters are obtained from the elite samples using likelihood-ratio weights, with the mean updated by a weighted average and the scale updated by a weighted standard-deviation-type expression.

Hypotheses
  1. Elite samples are those with values above γi\gamma_i.

  2. Likelihood ratios are computed as original density divided by proposal density.

Quantifiers

Applied at each cross-entropy iteration before updating `v`.

The target density has a known normalizing constant in this example

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    Speaker says, 'since in this very simple case we do know its normalizing constant l'.

  2. Formula
    Observation

    Code sets `l = stats.norm.sf(γ)`.

Proposition
Statement

For the target distribution plotted here, the normalizing constant is known and equals `l = stats.norm.sf(γ)`.

Hypotheses
  1. The example uses a standard normal baseline density.

  2. The target is restricted to the tail region `x>γx > γ`.

Quantifiers

In this specific simple case.

Derivations and proofs · 7

Derivation of the rejection-sampling step for g∗g^*

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The notebook text says `to sample from g∗(x)=Pg*(x) = P(X=xX = x | X > gamma), just sample lots of X's and extract those X > gamma`.

  2. Audio
    Observation

    The narrator explains that because g∗g^* is the distribution of XX conditioned on the rare event happening, one can sample many XX's and keep only those exceeding the threshold.

Intuitive argument
Steps
  1. Expression
    Explanation

    Start from the definition of the zero-variance density as the conditional law of XX given the rare event.

    Justification

    Notebook text and narration identify g∗(x)=P(X=x∣X>γ)g^*(x)=\mathbb{P}(X=x\mid X>\gamma).

    Shown in the video
  2. Expression
    Explanation

    Draw a large batch of unconditioned standard-normal samples Xi∼Normal(0,1)X_i\sim\mathrm{Normal}(0,1).

    Justification

    This is implemented by `Xs = rng.normal(size=R)`.

    Shown in the video
  3. Expression
    Explanation

    Retain only the samples satisfying Xi>γX_i>\gamma.

    Justification

    This is implemented by `Xs = Xs[Xs > gamma]` and described verbally as keeping those which exceed the threshold.

    Shown in the video
  4. Expression
    Explanation

    Treat the retained samples as samples from g∗g^*.

    Justification

    By definition, conditioning a random variable on the event X>γX>\gamma yields exactly the distribution of accepted draws under this rejection rule.

    Derived from the video
Conclusion

Rejection sampling from the original standard normal law produces samples from the conditional density g∗g^* needed to fit the proposal.

From fitted proposal to importance-sampling estimate and interval

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code first computes `mu = np.mean(Xs)` and `sigma = np.sqrt(np.mean((Xs-mu)**2))`, then samples `normals = rng.normal(mu, sigma, R)`, computes `lrs`, `ests`, `lHat`, `oHat`, and `widthCI`.

  2. Audio
    Observation

    The narrator says the proposal density is created by maximum likelihood estimates for mu and sigma, then says they proceed with a normal importance sampling estimation and print the estimate and confidence intervals.

Uncertainties
  1. The video does not explicitly write the likelihood function being maximized; the MLE interpretation is inferred from the narration plus the sample-mean and sample-second-moment formulas.

Intuitive argument
Steps
  1. Expression
    Explanation

    Use the retained g∗g^* samples to estimate the Normal proposal parameters by sample mean and sample root second central moment.

    Justification

    The code implements `mu = np.mean(Xs)` and `sigma = np.sqrt(np.mean((Xs-mu)**2))`; the narration calls these maximum likelihood estimates.

    Shown in the video
  2. Expression
    Explanation

    Draw R=106R=10^6 samples from the fitted Normal proposal Normal(μ^,σ^2)\mathrm{Normal}(\hat{\mu},\hat{\sigma}^2).

    Justification

    Implemented by `normals = rng.normal(mu, sigma, R)`.

    Shown in the video
  3. Expression
    Explanation

    For each proposal sample, compute the likelihood ratio f(Zj)/q(Zj)f(Z_j)/q(Z_j) using the standard normal density in the numerator and the fitted normal density in the denominator.

    Justification

    Implemented by `lrs = stats.norm.pdf(normals, 0, 1) / stats.norm.pdf(normals, mu, sigma)`.

    Shown in the video
  4. Expression
    Explanation

    Multiply each likelihood ratio by the indicator that the sample exceeds the threshold, forming `ests = lrs * (normals > gamma)`.

    Justification

    This is the importance-sampling integrand for the event probability P(X>γ)P(X>\gamma).

    Shown in the video
  5. Expression
    Explanation

    Average `ests` to obtain `lHat`, and use its sample standard deviation together with `1.96 / sqrt(R)` to form the reported interval half-width.

    Justification

    Implemented by `lHat = ests.mean()`, `oHat = ests.std()`, and `widthCI = 1.96 * oHat / np.sqrt(R)`.

    Shown in the video
Conclusion

The fitted proposal is then used in a standard importance-sampling estimator, and the notebook reports both the point estimate and a symmetric confidence interval.

Step-by-step derivation of the displayed cross-entropy iteration

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker walks through the loop: sample from the current proposal, compute the iteration threshold, stop if it exceeds gamma, otherwise extract elite samples, compute likelihood ratios, and update v.

  2. Formula
    Observation

    Code block shows the full loop from `for i in range(maxIter):` through `vs.append(v)`.

Proof
Steps
  1. Expression
    Xs∼Normal(v[0],v[1]),∣Xs∣=RX_s \sim \mathrm{Normal}(v[0], v[1]),\quad |X_s|=R
    Explanation

    At iteration ii, draw a batch of RR samples from the current proposal distribution parameterized by `v`.

    Justification

    Observed in code as `Xs = rng.normal(v[0], v[1], R)` and described verbally as sampling from the current proposal distribution.

    Shown in the video
  2. Expression
    γi=Q1−p(Xs)\gamma_i = Q_{1-p}(X_s)
    Explanation

    Compute the iteration-specific threshold as the empirical (1−p)(1-p)-quantile of the sampled batch.

    Justification

    Observed in code as `gamma_i = np.quantile(Xs, 1-p)`; the speaker identifies this as the 95% threshold because `p=0.05p = 0.05`.

    Shown in the video
  3. Expression
    if γi≥γ, stop\text{if } \gamma_i \ge \gamma,\ \text{stop}
    Explanation

    If the elite threshold has reached or exceeded the target rare-event level, terminate the adaptation loop.

    Justification

    Observed in code as `if gamma_i >= gamma: break` and stated verbally as the stopping rule.

    Shown in the video
  4. Expression
    eliteXs={x∈Xs:x>γi}\text{eliteXs} = \{x\in X_s : x > \gamma_i\}
    Explanation

    Otherwise, select the elite samples, namely those current samples lying above the iteration threshold.

    Justification

    Observed in code as `eliteXs = Xs[Xs > gamma_i]` and described verbally as pulling out the elite Xs above gamma i.

    Shown in the video
  5. Expression
    w(x)=fu(x)fv(x)w(x)=\frac{f_u(x)}{f_v(x)}
    Explanation

    For each elite sample, compute the likelihood ratio between the original distribution and the current proposal distribution.

    Justification

    Observed in code as `eliteLRs = stats.norm.pdf(eliteXs, u[0], u[1]) / stats.norm.pdf(eliteXs, v[0], v[1])`; the speaker explicitly calls these likelihood ratios.

    Shown in the video
  6. Expression
    μi=∑x∈eliteXsw(x)x∑x∈eliteXsw(x)\mu_i = \frac{\sum_{x\in \text{eliteXs}} w(x)x}{\sum_{x\in \text{eliteXs}} w(x)}
    Explanation

    Update the proposal mean as the weighted average of elite samples.

    Justification

    Observed in code as `mu_i = np.average(eliteXs, weights=eliteLRs)` and justified verbally as a maximum likelihood estimate from elite samples.

    Shown in the video
  7. Expression
    σi=∑x∈eliteXsw(x)(x−xˉelite)2∑x∈eliteXsw(x)\sigma_i = \sqrt{\frac{\sum_{x\in \text{eliteXs}} w(x)(x-\bar{x}_{\text{elite}})^2}{\sum_{x\in \text{eliteXs}} w(x)}}
    Explanation

    Update the proposal scale from a weighted second moment of the elite samples.

    Justification

    Observed in code as `sigma_i = np.sqrt(np.average((eliteXs-eliteXs.mean())**2, weights=eliteLRs))`.

    Shown in the video
  8. Expression
    v←(μi,σi),vs←vs∪{v}v \leftarrow (\mu_i,\sigma_i),\quad vs\leftarrow vs\cup\{v\}
    Explanation

    Replace the current proposal parameters by the updated pair and record the new parameter vector in the history list.

    Justification

    Observed in code as `v = (mu_i, sigma_i)` followed by `vs.append(v)`.

    Shown in the video
Conclusion

The displayed algorithm iteratively adapts a normal proposal toward the rare-event region by thresholding samples, weighting elite points by likelihood ratios, and updating the proposal parameters until the elite threshold reaches the target level.

Derivation of the final importance-sampling estimator and confidence interval

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says once CE has finished, they take the proposal distribution it has found and run a normal important sampling estimation.

  2. Formula
    Observation

    Second code cell computes `normals`, `lrs`, `ests`, `fHat`, `oHat`, and `widthCI`, then prints them along with `stats.norm.sf(gamma)`.

Proof
Steps
  1. Expression
    Yj∼Normal(v[0],v[1]),j=1,…,RY_j \sim \mathrm{Normal}(v[0], v[1]),\quad j=1,\dots,R
    Explanation

    After adaptation, draw a fresh sample batch from the final proposal distribution stored in `v`.

    Justification

    Observed in code as `normals = rng.normal(v[0], v[1], R)` and described verbally as running a normal important sampling estimation.

    Shown in the video
  2. Expression
    ℓj=fu(Yj)fv(Yj)\ell_j = \frac{f_u(Y_j)}{f_v(Y_j)}
    Explanation

    Compute likelihood ratios for the fresh samples under the original versus final proposal densities.

    Justification

    Observed in code as `lrs = stats.norm.pdf(normals, u[0], u[1]) / stats.norm.pdf(normals, v[0], v[1])`.

    Shown in the video
  3. Expression
    Zj=ℓj1{Yj>γ}Z_j = \ell_j\mathbf{1}_{\{Y_j>\gamma\}}
    Explanation

    Form the weighted rare-event contributions by multiplying each likelihood ratio by the indicator that the sample exceeds the target threshold.

    Justification

    Observed in code as `ests = lrs * (normals > gamma)`.

    Shown in the video
  4. Expression
    p^=1R∑j=1RZj\hat{p} = \frac{1}{R}\sum_{j=1}^{R} Z_j
    Explanation

    Estimate the rare-event probability as the sample mean of the weighted indicators.

    Justification

    Observed in code as `fHat = ests.mean()`.

    Shown in the video
  5. Expression
    SE^=sZR,widthCI=1.96 SE^\widehat{\mathrm{SE}} = \frac{s_Z}{\sqrt{R}},\quad \text{widthCI}=1.96\,\widehat{\mathrm{SE}}
    Explanation

    Report an approximate 95% confidence half-width using the sample standard deviation of the weighted terms.

    Justification

    Observed in code as `oHat = ests.std()` and `widthCI = 1.96 * oHat / np.sqrt(R)`.

    Shown in the video
  6. Expression
    ptheory=P(X>γ)=stats.norm.sf(gamma)p_{\text{theory}} = \mathbb{P}(X>\gamma)=\texttt{stats.norm.sf(gamma)}
    Explanation

    Compare the Monte Carlo estimate against the exact survival function of the standard normal distribution.

    Justification

    Observed in code as `print(f"Theoretical:\t{stats.norm.sf(gamma)}")`.

    Shown in the video
Conclusion

The final numerical estimate is produced by ordinary importance sampling from the converged proposal, with an approximate confidence interval and a direct comparison to the theoretical tail probability.

Derivation of the displayed CE estimate from the visible code

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code lines show sampling, likelihood-ratio computation, weighting by `(normals > γ)`, averaging, standard deviation, and CI width.

  2. Formula
    Observation

    Output lines show numerical values for `CE estimate`, bounds, and `Theoretical`.

Numerical verification
Steps
  1. Expression
    normals=rng.normal(v[0],v[1],R)normals = rng.normal(v[0], v[1], R)
    Explanation

    Draw `R` samples from the proposal normal distribution with mean `v[0]` and standard deviation `v[1]`.

    Justification

    Directly shown in the code cell.

    Shown in the video
  2. Expression
    lrs=stats.norm.pdf(normals,u[0],u[1])/stats.norm.pdf(normals,v[0],v[1])lrs = stats.norm.pdf(normals, u[0], u[1]) / stats.norm.pdf(normals, v[0], v[1])
    Explanation

    Compute the likelihood ratio between the normal density with parameters `u` and the proposal density with parameters `v` at each sampled point.

    Justification

    Directly shown in the code cell.

    Shown in the video
  3. Expression
    ests=lrs∗(normals>γ)ests = lrs * (normals > γ)
    Explanation

    Multiply each likelihood ratio by the indicator of the rare event `normals > γ`.

    Justification

    Directly shown in the code cell.

    Shown in the video
  4. Expression
    fHat=ests.mean();oHat=ests.std();widthCI=1.96∗oHat/np.sqrt(R)fHat = ests.mean(); oHat = ests.std(); widthCI = 1.96 * oHat / np.sqrt(R)
    Explanation

    Take the sample mean as the probability estimate, the sample standard deviation for variability, and form an approximate 95% confidence half-width.

    Justification

    Directly shown in the code cell.

    Shown in the video
  5. Expression
    CEestimate:2.8433488092847927e−07(+/−1.1057152778688466e−08);Theoretical:2.866515718791933e−07CE estimate: 2.8433488092847927e-07 (+/- 1.1057152778688466e-08); Theoretical: 2.866515718791933e-07
    Explanation

    The printed output gives the numerical estimate, interval half-width, and theoretical comparison value.

    Justification

    Directly visible in the output block.

    Shown in the video
Conclusion

The visible code implements a likelihood-ratio-weighted Monte Carlo estimator and reports both the estimate and a theoretical comparison value.

How the proposal-density plot is constructed

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    Speaker says, 'If we loop through this list, we can calculate the PDF of each proposal distribution over some grid of x values.'

  2. Formula
    Observation

    Code shows `xs = np.linspace(-2, 6.5, 500)`, `ys = np.empty((len(xs), len(vs)))`, and `ys[:,i] = stats.norm.pdf(xs, v[0], v[1])`.

Visual argument
Steps
  1. Expression
    xs=np.linspace(−2,6.5,500)xs = np.linspace(-2, 6.5, 500)
    Explanation

    Create a fixed grid of 500 x-values spanning roughly -2 to 6.5.

    Justification

    Directly shown in the code cell.

    Shown in the video
  2. Expression
    ys=np.empty((len(xs),len(vs)))ys = np.empty((len(xs), len(vs)))
    Explanation

    Allocate a matrix to store one column of PDF values per proposal distribution.

    Justification

    Directly shown in the code cell.

    Shown in the video
  3. Expression
    fori,vinenumerate(vs):ys[:,i]=stats.norm.pdf(xs,v[0],v[1])for i, v in enumerate(vs): ys[:,i] = stats.norm.pdf(xs, v[0], v[1])
    Explanation

    For each stored parameter vector `v`, evaluate its normal PDF on the same grid and store the result in column `i`.

    Justification

    Directly shown in the code cell and explained in the audio.

    Shown in the video
  4. Expression
    plt.plot(xs,ys)plt.plot(xs, ys)
    Explanation

    Plot all stored columns against the common x-grid, producing multiple overlaid proposal curves.

    Justification

    Directly shown in the code cell.

    Shown in the video
Conclusion

The plot of proposal distributions is obtained by evaluating each stored normal density on a shared x-grid and drawing all curves together.

How the target curve g* is constructed for plotting

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code shows `xOverGamma = xs[xs > γ]`, `l = stats.norm.sf(γ)`, `gStar = stats.norm.pdf(xOverGamma) / l`, and `plt.plot(xOverGamma, gStar)`.

  2. Audio
    Observation

    Speaker says they will plot the target distribution `g star` because its normalizing constant `l` is known.

Visual argument
Steps
  1. Expression
    xOverGamma=xs[xs>γ]xOverGamma = xs[xs > γ]
    Explanation

    Restrict the plotting grid to the tail region where `x>γx > γ`.

    Justification

    Directly shown in the code cell.

    Shown in the video
  2. Expression
    l=stats.norm.sf(γ)l = stats.norm.sf(γ)
    Explanation

    Compute the normalizing constant as the standard normal survival function at `γ`.

    Justification

    Directly shown in the code cell and identified in the audio as the known normalizing constant.

    Shown in the video
  3. Expression
    gStar=stats.norm.pdf(xOverGamma)/lgStar = stats.norm.pdf(xOverGamma) / l
    Explanation

    Normalize the standard normal density on the tail region by dividing by `l`.

    Justification

    Directly shown in the code cell.

    Shown in the video
  4. Expression
    plt.plot(xOverGamma,gStar)plt.plot(xOverGamma, gStar)
    Explanation

    Plot the resulting normalized target density over the tail region.

    Justification

    Directly shown in the code cell.

    Shown in the video
Conclusion

The target curve shown in the figure is the standard normal density restricted to `x>γx > γ` and normalized by `l = stats.norm.sf(γ)`.

Worked examples · 3

Worked example: estimating a standard-normal tail probability with improved cross-entropy

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The notebook states the full worked example: estimate `P(X > gamma)` where `X ~ Normal(0, 1)` and `gamma = 5`, using proposals of the form `Normal(mu, sigma^2)`.

  2. Audio
    Observation

    The narrator introduces this as a very simple example demonstrating the improved cross-entropy method.

Problem

Estimate P(X>γ)P(X>\gamma) for X∼Normal(0,1)X\sim\mathrm{Normal}(0,1) with γ=5\gamma=5 using the improved cross-entropy method and Normal importance-sampling proposals.

Given
  1. X∼Normal(0,1)X\sim\mathrm{Normal}(0,1).

  2. γ=5\gamma=5.

  3. Proposal family is Normal(μ,σ2)\mathrm{Normal}(\mu,\sigma^2).

  4. First rejection-sampling batch size is R=5×108R=5\times 10^8.

  5. Final importance-sampling batch size is R=106R=10^6.

Goal

Obtain a numerical estimate of the rare-event probability and a confidence interval, and compare with the theoretical value.

Steps
  1. Expression
    Explanation

    Set the threshold to γ=5\gamma=5.

    Justification

    Shown in the notebook cell `gamma = 5`.

    Shown in the video
  2. Expression
    Explanation

    Generate 5×1085\times 10^8 standard-normal samples and keep only those greater than 55.

    Justification

    Implemented by `Xs = rng.normal(size=R)` and `Xs = Xs[Xs > gamma]`; the narrator calls this rejection sampling.

    Shown in the video
  3. Expression
    Explanation

    The retained sample count is 152.

    Justification

    Output line reads `Number of g* samples: 152`.

    Shown in the video
  4. Expression
    Explanation

    Fit a Normal proposal to those 152 retained samples using their sample mean and sample root second central moment.

    Justification

    Implemented by `mu = np.mean(Xs)` and `sigma = np.sqrt(np.mean((Xs-mu)**2))`; narration identifies this as maximum likelihood estimation.

    Shown in the video
  5. Expression
    Explanation

    Draw 10610^6 samples from the fitted Normal proposal.

    Justification

    Implemented by `R=10R = 10**6` and `normals = rng.normal(mu, sigma, R)`.

    Shown in the video
  6. Expression
    Explanation

    Compute likelihood ratios and weighted indicators, then average them to get the estimate.

    Justification

    Implemented by `lrs = stats.norm.pdf(normals, 0, 1) / stats.norm.pdf(normals, mu, sigma)`, `ests = lrs * (normals > gamma)`, and `lHat = ests.mean()`.

    Shown in the video
  7. Expression
    Explanation

    Report the estimate, interval bounds, and theoretical benchmark.

    Justification

    Output lines show `ICE estimate`, `ICE low bound`, `ICE upp bound`, and `Theoretical`.

    Shown in the video
Answer

The notebook prints `ICE estimate: 2.8499557494141556e-07 (+/- 8.28267698086911e-10)`, `ICE low bound: 2.841672802433268e-07`, `ICE upp bound: 2.8582381563950423e-07`, and `Theoretical: 2.866515718791933e-07`.

Verification

The estimate is compared directly against the theoretical standard-normal survival probability printed in the same output block.

Worked example: estimating P(X>5)P(X>5) for X~Normal(0,1) by the original cross-entropy method

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Markdown states the task: estimate `P(X > gamma)` where `X ~ Normal(0, 1)` and `gamma = 5`.

  2. Formula
    Observation

    First code cell implements the cross-entropy loop with `R=10R = 10**5`, `p=0.05p = 0.05`, `maxIter = 50`, `u=(0,1)u = (0, 1)`, and `v=uv = u`.

  3. Formula
    Observation

    Second code cell performs final importance sampling with `R=10R = 10**6` and prints the results.

  4. Audio
    Observation

    The speaker explains the loop, the stopping rule, the likelihood ratios, the parameter update, and the final importance-sampling estimate.

Uncertainties
  1. The exact intermediate proposal parameters after convergence are not shown numerically in the visible output within this clip.

  2. The displayed variance update uses `eliteXs.mean()` rather than `mu_i`, creating a small mismatch with the verbal description of maximum likelihood estimation.

Problem

Use the cross-entropy method to estimate the rare-event probability P(X>γ)\mathbb{P}(X>\gamma) where X∼Normal(0,1)X\sim\mathrm{Normal}(0,1) and γ=5\gamma=5.

Given
  1. Original distribution parameters `u=(0,1)u = (0, 1)`.

  2. Initial proposal `v=uv = u`.

  3. Cross-entropy loop sample size `R=10R = 10**5`.

  4. Elite fraction `p=0.05p = 0.05`.

  5. Maximum iterations `maxIter = 50`.

  6. Final importance-sampling sample size `R=10R = 10**6`.

  7. Target threshold `gamma = 5`.

Goal

Compute a Monte Carlo estimate of P(X>5)\mathbb{P}(X>5), obtain an approximate confidence interval, and compare with the theoretical value.

Steps
  1. Expression
    v0←u=(0,1)v_0 \leftarrow u=(0,1)
    Explanation

    Initialize the proposal distribution to the original standard normal distribution.

    Justification

    Observed in code as `v=uv = u` after `u=(0,1)u = (0, 1)`.

    Shown in the video
  2. Expression
    repeat for i=0,…,49\text{repeat for } i=0,\dots,49
    Explanation

    Run up to 50 adaptive iterations.

    Justification

    Observed in code as `for i in range(maxIter):` with `maxIter = 50`.

    Shown in the video
  3. Expression
    Xs∼Normal(v[0],v[1]), ∣Xs∣=105X_s \sim \mathrm{Normal}(v[0],v[1]),\ |X_s|=10^5
    Explanation

    Draw 100,000 samples from the current proposal at each iteration.

    Justification

    Observed in code as `Xs = rng.normal(v[0], v[1], R)` with `R=10R = 10**5`.

    Shown in the video
  4. Expression
    γi=Q0.95(Xs)\gamma_i = Q_{0.95}(X_s)
    Explanation

    Set the elite cutoff to the empirical 95th percentile of the current sample batch.

    Justification

    Observed in code as `gamma_i = np.quantile(Xs, 1-p)` with `p=0.05p = 0.05`; the speaker calls this the 95% threshold.

    Shown in the video
  5. Expression
    if γi≥5, extbreak\text{if }\gamma_i\ge 5,\ ext{break}
    Explanation

    Stop adapting once the elite cutoff reaches the target threshold.

    Justification

    Observed in code as `if gamma_i >= gamma: break`.

    Shown in the video
  6. Expression
    eliteXs={x∈Xs:x>γi}\text{eliteXs}=\{x\in X_s:x>\gamma_i\}
    Explanation

    Keep only the elite samples above the iteration cutoff.

    Justification

    Observed in code as `eliteXs = Xs[Xs > gamma_i]`.

    Shown in the video
  7. Expression
    w(x)=ϕ(x;0,1)ϕ(x;v[0],v[1])w(x)=\frac{\phi(x;0,1)}{\phi(x;v[0],v[1])}
    Explanation

    Compute likelihood ratios between the original standard normal density and the current proposal density on the elite samples.

    Justification

    Observed in code as `eliteLRs = stats.norm.pdf(eliteXs, u[0], u[1]) / stats.norm.pdf(eliteXs, v[0], v[1])`.

    Shown in the video
  8. Expression
    v←(μi,σi)v \leftarrow (\mu_i,\sigma_i)
    Explanation

    Update the proposal parameters from weighted elite-sample summaries and store the new pair in the history list.

    Justification

    Observed in code as `mu_i = np.average(...)`, `sigma_i = np.sqrt(np.average(...))`, `v = (mu_i, sigma_i)`, and `vs.append(v)`.

    Shown in the video
  9. Expression
    Yj∼Normal(v[0],v[1]), j=1,…,106Y_j \sim \mathrm{Normal}(v[0],v[1]),\ j=1,\dots,10^6
    Explanation

    After convergence, draw one million fresh samples from the final proposal distribution.

    Justification

    Observed in the second code cell as `normals = rng.normal(v[0], v[1], R)` with `R=10R = 10**6`.

    Shown in the video
  10. Expression
    p^=1106∑j=1106ϕ(Yj;0,1)ϕ(Yj;v[0],v[1])1{Yj>5}\hat{p}=\frac{1}{10^6}\sum_{j=1}^{10^6}\frac{\phi(Y_j;0,1)}{\phi(Y_j;v[0],v[1])}\mathbf{1}_{\{Y_j>5\}}
    Explanation

    Estimate the tail probability by averaging likelihood-ratio-weighted rare-event indicators.

    Justification

    Observed in code as `lrs = ...`, `ests = lrs * (normals > gamma)`, and `fHat = ests.mean()`.

    Shown in the video
  11. Expression
    widthCI=1.96s106\text{widthCI}=1.96\frac{s}{\sqrt{10^6}}
    Explanation

    Report an approximate 95% confidence half-width from the sample standard deviation of the weighted terms.

    Justification

    Observed in code as `oHat = ests.std()` and `widthCI = 1.96 * oHat / np.sqrt(R)`.

    Shown in the video
Answer

The visible printed result is `CE estimate: 2.8433488092847927e-07 (+/- 1.1057152778688466e-08)`, with bounds `2.732772014979008e-07` and `2.9539203370716776e-07`, compared to `Theoretical: 2.866515718791933e-07`.

Verification

The example is checked against the exact standard-normal survival probability `stats.norm.sf(5)`, which is printed as `2.866515718791933e-07`; the speaker also remarks that the estimate is about `2.8 by 10 to the minus 7` but the confidence interval width is much wider.

Numerical CE estimate compared with theoretical value

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Output block shows `CE estimate: 2.8433488092847927e-07 (+/- 1.1057152778688466e-08)`, `CE low bound: 2.732772014979008e-07`, `CE upp bound: 2.953920337016776e-07`, and `Theoretical: 2.866515718791933e-07`.

  2. Formula
    Observation

    Code above computes these quantities from `normals`, `lrs`, and `ests`.

Problem

Estimate the rare-event probability using the displayed cross-entropy/importance-sampling style code and compare it with the theoretical value.

Given
  1. `R=10R = 10**6`

  2. Proposal samples drawn from `rng.normal(v[0], v[1], R)`

  3. Likelihood ratio uses `stats.norm.pdf(normals, u[0], u[1]) / stats.norm.pdf(normals, v[0], v[1])`

  4. Rare-event indicator is `(normals > γ)`

Goal

Obtain the CE estimate, confidence bounds, and theoretical comparison.

Steps
  1. Expression
    ests=lrs∗(normals>γ)ests = lrs * (normals > γ)
    Explanation

    Form weighted rare-event contributions.

    Justification

    Shown in the code cell.

    Shown in the video
  2. Expression
    fHat=ests.mean()fHat = ests.mean()
    Explanation

    Average the weighted contributions to get the estimate.

    Justification

    Shown in the code cell.

    Shown in the video
  3. Expression
    widthCI=1.96∗oHat/np.sqrt(R)widthCI = 1.96 * oHat / np.sqrt(R)
    Explanation

    Compute the approximate confidence half-width.

    Justification

    Shown in the code cell.

    Shown in the video
  4. Expression
    CEestimate:2.8433488092847927e−07(+/−1.1057152778688466e−08)CE estimate: 2.8433488092847927e-07 (+/- 1.1057152778688466e-08)
    Explanation

    Read the reported estimate and uncertainty from the output.

    Justification

    Visible in the output block.

    Shown in the video
  5. Expression
    Theoretical:2.866515718791933e−07Theoretical: 2.866515718791933e-07
    Explanation

    Read the theoretical comparison value from the output.

    Justification

    Visible in the output block.

    Shown in the video
Answer

CE estimate = 2.8433488092847927e-07 with half-width 1.1057152778688466e-08; theoretical value = 2.866515718791933e-07.

Verification

The printed low and upper bounds match `fHat +/- widthCI` as shown in the output block.

Visual events · 7

Scrolling to imports and back

Clear evidence
Shown in the video
Evidence
  1. Animation
    Observation

    The screen scrolls upward from the main example to earlier import cells and then back down.

  2. Audio
    Observation

    The narrator says they will quickly scroll up to show the import statements and package versions.

Objects
  1. Jupyter notebook cells

  2. import statements

  3. version output block

Changes
  1. View moves upward from the `Improved cross-entropy method` section to earlier cells.

  2. Version information becomes visible.

  3. View returns to the main example.

Invariants
  1. The mathematical problem statement remains the same before and after scrolling.

Interpretation

This visual action only exposes software dependencies and does not alter the mathematical content of the example.

Execution output for the rejection-sampling stage

Clear evidence
Shown in the video
Evidence
  1. Animation
    Observation

    After execution, the first simulation cell displays `Number of g* samples: 152` and `Wall time: 12.6 s`.

Objects
  1. Code cell

  2. output text

Changes
  1. The cell changes from unexecuted to executed.

  2. The number of retained samples appears as 152.

Invariants
  1. The threshold remains γ=5\gamma=5 and the raw draw count remains 5×1085\times 10^8.

Interpretation

The output quantifies how few samples survive the rare-event filter, motivating the need for an importance-sampling proposal.

Execution output for the final importance-sampling estimate

Clear evidence
Shown in the video
Evidence
  1. Animation
    Observation

    The final cell output shows the ICE estimate, low bound, upper bound, theoretical value, and wall time.

Objects
  1. Code cell

  2. numeric output lines

Changes
  1. The estimate and interval values become visible.

  2. The theoretical benchmark appears below the estimate.

Invariants
  1. The same fitted proposal parameters from the previous cell are used.

Interpretation

The visual output confirms the numerical result of the improved cross-entropy workflow and its closeness to the theoretical tail probability.

Notebook view of the cross-entropy implementation and results

Clear evidence
Shown in the video
Evidence
  1. Animation
    Observation

    The screen recording scrolls through a Jupyter notebook showing markdown text, Python code cells, and printed outputs.

Objects
  1. Markdown heading `Cross-entropy method`.

  2. Problem statement `Use the cross-entropy method to estimate P(X > gamma) where X ~ Normal(0, 1) and gamma = 5`.

  3. First code cell implementing the adaptive loop.

  4. Second code cell implementing final importance sampling.

  5. Printed numeric outputs including CE estimate, bounds, theoretical value, and wall time.

Changes
  1. The view begins near the top of the first code cell.

  2. It scrolls downward to reveal the loop body and parameter update lines.

  3. It continues to the second code cell and its printed output.

  4. The final visible state shows the numerical estimate and theoretical comparison.

Invariants
  1. The target remains the same throughout: estimating P(X>5)\mathbb{P}(X>5) for a standard normal variable.

  2. The original distribution parameters remain `u=(0,1)u = (0, 1)`.

  3. The target threshold remains `gamma = 5`.

Interpretation

The visual progression mirrors the algorithmic order: first define the adaptive cross-entropy search, then use the resulting proposal for a final importance-sampling estimate and compare with theory.

Initial notebook view with CE code and numerical output

Clear evidence
Shown in the video
Evidence
  1. Diagram
    Observation

    A Jupyter notebook cell with Python code is visible above an output block containing numerical results and `Wall time: 428 ms`.

Objects
  1. Python code cell

  2. Output text block

  3. Mouse cursor

Changes
  1. The screen remains static on the code and output during the opening seconds.

Invariants
  1. The displayed code and numerical output do not change within this interval.

Interpretation

This segment establishes the implemented estimator and its numerical result before the notebook scrolls to the visualization code.

Scroll from estimator output to proposal-visualization code

Clear evidence
Shown in the video
Evidence
  1. Animation
    Observation

    The page scrolls downward from the first code/output cell to a new code cell beginning with `xs = np.linspace(-2, 6.5, 500)`.

Objects
  1. Notebook page

  2. New code cell

  3. Heading `Compare to crude Monte Carlo`

Changes
  1. The first output block moves upward out of view.

  2. A new code cell for plotting proposal distributions comes into view.

  3. The heading `Compare to crude Monte Carlo` becomes visible below.

Invariants
  1. The interface remains a notebook with code cells and text headings.

Interpretation

The visual transition marks a shift from numerical estimation to geometric inspection of the proposal distributions.

Generated plot of proposal distributions and target-related elements

Clear evidence
Shown in the video
Evidence
  1. Animation
    Observation

    After execution, a plot appears below the code cell.

  2. Diagram
    Observation

    The figure shows several colored bell-shaped curves and a gray dashed vertical line near x≈4.5.

Uncertainties
  1. Exact colors of every curve are not fully stable across frames, but multiple distinct colored curves are clearly present.

Objects
  1. Multiple colored normal-like curves

  2. Gray dashed vertical line

  3. Coordinate axes

  4. Plot frame

Changes
  1. A blank area below the code is replaced by a rendered figure.

  2. Several proposal curves appear together on the same axes.

  3. A vertical dashed line marks the threshold region.

Invariants
  1. All curves are drawn over the same horizontal axis range.

  2. The dashed vertical line remains fixed at the threshold location.

Interpretation

The figure visualizes how the stored proposal distributions evolve across iterations and situates them relative to the threshold and target region.

Misconceptions · 5

`widthCI` is used as a half-width, not the full interval width

Clear evidence
Supplementary explanation
Evidence
  1. Formula
    Observation

    The code names the quantity `widthCI = 1.96 * oHat / np.sqrt(R)` and then prints bounds as `lHat-widthCI` and `lHat+widthCI`.

Misconception

One might read the variable name `widthCI` as the total width of the confidence interval.

Clarification

In the displayed code, the printed lower and upper bounds subtract and add the same quantity to `lHat`, so `widthCI` functions as the half-width of a symmetric interval.

The symbol `R` is reused with different meanings in different cells

Clear evidence
Supplementary explanation
Evidence
  1. Formula
    Observation

    The first cell sets `R=5∗10R = 5 * 10**8`; the final cell resets `R=10R = 10**6`.

Misconception

A reader may assume `R` denotes one fixed sample size throughout the notebook.

Clarification

In this segment, `R` first denotes the number of raw standard-normal draws for rejection sampling, and later denotes the number of proposal draws for the importance-sampling estimate.

Mistaking a tractable toy example for a generally feasible direct-sampling strategy

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says, `In the example above, we kind of cheated.` and explains that because the rare event was not very rare, they could sample from g star directly using rejection sampling, but in general this would take too long.

Misconception

One may think it is acceptable to sample directly from the ideal proposal distribution whenever a rare-event problem is presented.

Clarification

The video explicitly warns that this worked only because the earlier example's rare event was not very rare; in general, direct rejection sampling from such a proposal would take too long, motivating the adaptive cross-entropy method.

Forgetting likelihood-ratio weighting in the proposal update

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says, `Don't forget we must weight the samples by their likelihood ratios.`

Misconception

One might update the proposal parameters using the elite samples as though they were drawn from the original distribution directly.

Clarification

The video stresses that the elite samples must be weighted by their likelihood ratios when computing the updated parameters.

What `enumerate` provides in the loop

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    Speaker says, 'Note, enumerate is just a nice convenience function in Python which gives us each element v in our list as well as its index i.'

Misconception

One might think the loop variable pair in `for i, v in enumerate(vs)` is arbitrary or mathematically meaningful beyond indexing.

Clarification

The speaker explicitly explains that `enumerate` returns both the index `i` and the corresponding element `v` from the list `vs`.

Concept relations · 11

Zero-variance density as the conditional law given the rare event → Problem setup for rare-event estimation

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The notebook explicitly writes `g∗(x)=Pg*(x) = P(X=xX = x | X > gamma)`.

  2. Audio
    Observation

    The narrator says g∗g^* is the distribution of XX conditioned on the rare event happening.

Special case
Explanation

The zero-variance density is the conditional version of the original model specialized to the rare-event region X>γX>\gamma.

Rejection sampling to obtain samples from g∗g^* → Zero-variance density as the conditional law given the rare event

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The text says to sample from g∗g^* by sampling lots of XX's and extracting those X>γX>\gamma.

  2. Audio
    Observation

    The narrator names this procedure rejection sampling.

Application
Explanation

Rejection sampling is the practical method used in the video to generate samples from the conditional density g∗g^*.

Maximum likelihood fit of the Normal proposal to the g∗g^* samples → Rejection sampling to obtain samples from g∗g^*

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The fitting cell operates on `Xs`, the retained samples from the previous cell.

  2. Audio
    Observation

    The narrator says the proposal density is created from these samples by maximum likelihood estimation.

Proof dependency
Explanation

The Normal proposal fit depends on the retained samples produced by the rejection-sampling stage.

Normal importance-sampling estimator for P(X>γ)P(X>\gamma) → Maximum likelihood fit of the Normal proposal to the g∗g^* samples

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The final cell samples from `rng.normal(mu, sigma, R)` using the previously computed `mu` and `sigma`.

  2. Audio
    Observation

    The narrator says the improved cross-entropy algorithm has supplied a good proposal distribution and then they proceed with normal importance sampling estimation.

Application
Explanation

The importance-sampling estimator is applied using the proposal parameters fitted in the preceding step.

Reported confidence interval for the importance-sampling estimate → Normal importance-sampling estimator for P(X>γ)P(X>\gamma)

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    `oHat` and `widthCI` are computed directly from `ests`, whose mean is `lHat`.

Contains
Explanation

The confidence-interval calculation is a summary attached to the importance-sampling estimator output.

Iterative construction of proposal distributions → Final estimation step after cross-entropy adaptation

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says once CE has finished, they take the proposal distribution it has found and run a normal important sampling estimation.

  2. Formula
    Observation

    Second code cell uses the final `v` in `rng.normal(v[0], v[1], R)` and then computes importance weights.

Application
Explanation

The adaptive proposal produced by the cross-entropy iterations is applied as the sampling distribution in the final importance-sampling estimator.

Purpose of the original cross-entropy method → Step-by-step derivation of the displayed cross-entropy iteration

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker introduces the original cross-entropy method and then explains the loop mechanics.

  2. Formula
    Observation

    The code implements exactly the iterative procedure described.

Contains
Explanation

The general purpose of the cross-entropy method is instantiated in the displayed iterative loop for constructing better proposal distributions.

Worked example: estimating P(X>5)P(X>5) for X~Normal(0,1) by the original cross-entropy method → Normal tail-probability estimation example

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The second code cell prints both the CE estimate and `Theoretical: stats.norm.sf(gamma)`.

Application
Explanation

The worked numerical example applies the normal tail-probability setup and validates the Monte Carlo result against the exact survival function.

Visualizing the sequence of CE proposal distributions → Cross-entropy weighted estimator and confidence interval

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    Speaker says the CE method stored the `v` vectors inside a list named `vs`.

  2. Formula
    Observation

    Visualization code loops over `vs`.

Prerequisite
Explanation

The proposal-sequence visualization depends on the earlier CE procedure having stored the parameter vectors `v` in `vs`.

Constructing the normalized target density g* → Visualizing the sequence of CE proposal distributions

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    `gStar = stats.norm.pdf(xOverGamma) / l` is plotted with `plt.plot(xOverGamma, gStar)`.

  2. Audio
    Observation

    Speaker says they will plot the target distribution `g star` because its normalizing constant `l` is known.

Application
Explanation

The normalized target density construction is applied in the same plotting workflow that visualizes the proposal distributions.

The target density has a known normalizing constant in this example → Constructing the normalized target density g*

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    Speaker states that in this simple case the normalizing constant `l` is known.

  2. Formula
    Observation

    Code uses `l = stats.norm.sf(γ)` to define `gStar`.

Proof dependency
Explanation

The definition of `gStar` in this clip relies on the stated fact that the normalizing constant `l` is known for the example.

Find an answer · 17

What is the zero-variance density g∗g^* in this improved cross-entropy example?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The notebook defines `g∗(x)=Pg*(x) = P(X=xX = x | X > gamma)`.

Knowledge points
  1. Zero-variance density as the conditional law given the rare event

Why does the video use rejection sampling to get samples from g∗g^*?

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The narrator explains that because g∗g^* is the conditional distribution given the rare event, one can sample many XX's and keep only those above the threshold.

Knowledge points
  1. Rejection sampling to obtain samples from g∗g^*
  2. Zero-variance density as the conditional law given the rare event

How are the Normal proposal parameters chosen from the retained samples?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `mu = np.mean(Xs)` and `sigma = np.sqrt(np.mean((Xs-mu)**2))`.

Knowledge points
  1. Maximum likelihood fit of the Normal proposal to the g∗g^* samples

What does `lHat` represent in the final cell?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `lrs`, `ests`, and `lHat = ests.mean()`.

Knowledge points
  1. Normal importance-sampling estimator for P(X>γ)P(X>\gamma)

How is the reported confidence interval constructed from the importance-sampling estimates?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code computes `widthCI = 1.96 * oHat / np.sqrt(R)` and prints bounds around `lHat`.

Knowledge points
  1. Reported confidence interval for the importance-sampling estimate

What numerical estimate and theoretical benchmark are shown for P(X>5)P(X>5)?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The output prints the ICE estimate, bounds, and theoretical value.

Knowledge points
  1. Numerical result for the rare-event probability and interval width
  2. Worked example: estimating a standard-normal tail probability with improved cross-entropy

Why does the video say the earlier example 'cheated' by sampling directly from g star?

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker explains that direct sampling from g star via rejection sampling was possible only because the rare event was not very rare, and would generally take too long.

Knowledge points
  1. Purpose of the original cross-entropy method
  2. Mistaking a tractable toy example for a generally feasible direct-sampling strategy

How is the iteration threshold gamma_i defined and when does the cross-entropy loop stop?

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says the threshold for this iteration is the 95% threshold of the X samples and that iteration stops if it is above gamma.

  2. Formula
    Observation

    Code shows `gamma_i = np.quantile(Xs, 1-p)` and `if gamma_i >= gamma: break`.

Knowledge points
  1. Iterative construction of proposal distributions
  2. Cross-entropy stopping condition in the displayed implementation

Why are elite samples weighted by likelihood ratios when updating the proposal parameters?

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says likelihood ratios are calculated between the original and actual distributions, and that the samples must be weighted by their likelihood ratios.

  2. Formula
    Observation

    Code shows `eliteLRs = stats.norm.pdf(eliteXs, u[0], u[1]) / stats.norm.pdf(eliteXs, v[0], v[1])` and weighted averages for `mu_i` and `sigma_i`.

Knowledge points
  1. Proposal parameters are updated from weighted elite samples
  2. Forgetting likelihood-ratio weighting in the proposal update

What is the final estimator after the cross-entropy loop finishes, and how is its confidence interval computed?

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says they take the proposal distribution found by CE and run a normal important sampling estimation.

  2. Formula
    Observation

    Code shows `ests = lrs * (normals > gamma)`, `fHat = ests.mean()`, and `widthCI = 1.96 * oHat / np.sqrt(R)`.

Knowledge points
  1. Final estimation step after cross-entropy adaptation
  2. Derivation of the final importance-sampling estimator and confidence interval

What numerical estimate and theoretical comparison are shown for P(X>5)P(X>5)?

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The speaker says the estimate is about 2.8 by 10 to the minus 7 but the confidence interval width is much wider.

  2. Formula
    Observation

    Output shows `CE estimate: 2.8433488092847927e-07 (+/- 1.1057152778688466e-08)` and `Theoretical: 2.866515718791933e-07`.

Knowledge points
  1. Worked example: estimating P(X>5)P(X>5) for X~Normal(0,1) by the original cross-entropy method

What does `fHat` represent in the displayed cross-entropy estimate?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code shows `fHat = ests.mean()` and output labels `CE estimate`.

Knowledge points
  1. Cross-entropy weighted estimator and confidence interval
Coverage and review notes

Covered · Problem statement and goal are introduced in audio and notebook text.

Covered · Screen scrolls to imports and version information; no new mathematics beyond software setup.

Covered · Definition of g∗g^* and rejection-sampling implementation, ending with output `Number of g* samples: 152`.

Covered · Fitting the Normal proposal by sample mean and sample second central moment, described as maximum likelihood estimation.

Covered · Final importance-sampling estimate, confidence interval, theoretical comparison, and concluding narration.

Covered · Opening narration explains why direct rejection sampling from g star was only feasible in the previous example and motivates the original cross-entropy method.

Covered · The speaker defines the cross-entropy idea as building improving proposal distributions and identifies the roles of u, v, and vs in the notebook code.

Covered · The loop body is explained line by line: sampling from the current proposal, computing the 95% threshold, stopping if it exceeds gamma, extracting elite samples, forming likelihood ratios, and updating v with weighted estimates.

Covered · Brief pause and scrolling transition between the end of the cross-entropy loop and the final estimation cell; no new mathematical content beyond the already covered loop.

Covered · The final importance-sampling estimator is described, the printed numerical estimate and confidence interval are discussed, and the result is compared with the theoretical tail probability.

Covered · Static notebook view showing the CE/importance-sampling style code and its numerical output.

Covered · Page scroll transitions from the estimator output to the visualization code cell.

Covered · Speaker explains looping over stored proposal vectors and constructing the normalized target density while the code cell remains visible.

Covered · Executed plot appears, showing multiple proposal curves and a dashed vertical threshold line.

Explore the knowledge in this video

Reviewed subject paths

Questions this video answers

Find a method

↗
Meet the concept

↗
Understand why

↗
Understand why

↗
Find a method

↗
Understand why

↗
Find a method

↗
Meet the concept

↗