Appendix DComputational Specifications of the Simulators and Records of Checks
The chapters of this book embed ten simulators, in which you move parameters and watch the results. This appendix records, so that readers can judge for themselves, what each simulator computes (the formulas and algorithms) and how far it has been checked (against what, how many cases, and with what tolerance). Before you quote a number shown on a simulator’s screen in a report or in research, please read the relevant section.
Section D.1 describes the design common to all simulators (operating environment, random numbers, display of equations, embedding, computation limits), and Sections D.2–D.11 list the same items for each simulator in turn. Section D.12 summarizes what has not been checked and the known limitations. “Checked” as written here refers only to the tests actually run on November 12–13, 2026. It does not guarantee correct behavior under conditions not described here (other browsers, other devices, parameter combinations not included in the tests).
The checking methods are divided into the following four kinds. Analytical solution: comparison with quantities that are determined by a closed-form expression or a hand calculation. Full enumeration: comparison with the value obtained by counting all possible cases. Independent implementation: comparison with the value computed for the same quantity by a Python program (NumPy, SciPy, PyTorch, and so on) written independently of the simulator. Statistical check: a test, with a stated tolerance, of whether a quantity that uses random numbers follows the theoretical distribution. Writing $a$ for the value being compared (the simulator) and $b$ for the reference, the tolerance takes the form $\abs{a-b}\le \mathrm{atol}+\mathrm{rtol}\,\abs{b}$ (absolute tolerance atol, relative tolerance rtol).
In December 2026, each simulator was divided into two pages. The simulator page (sim/NAME-simulator.html) has two levels: the simple view, in which you grasp what is happening through pictures and motion, and the detailed view, which keeps the screen of the simulator as originally made. The explanation page (sim/NAME-derivation.html) now holds the explanation that used to be below the simulator’s screen (procedure, the formulas being computed, conditions of the data and random numbers, simplifications, conditions for instability, questions), with an added explanation of what the pictures of the simple view compute. What is embedded in the main text is the detailed view, and the “Operate and Observe” part of the boxes in the main text is written for the detailed view. Opening a former URL (sim/NAME.html) moves to the new simulator page, passing on the attached parameters (the parts after ? and after #) as they are. Unless otherwise stated, the records of computations and checks in Sections D.2–D.11 refer to the detailed view (the simulator as originally made). The scenes of the simple view and the checks of the computations added for them are described under “Corresponding chapters, sections, and tabs” and “How and to what extent the numbers were checked” in each section, and what was checked when the pages were divided is described in D.1.8.
D.1 Common Design
D.1.1 List of simulators
| Simulator | Files (simulator, explanation) | Tabs of the detailed view (key) | Scenes of the simple view (key) | Corresponding chapters | Default seed |
|---|---|---|---|---|---|
| S01 Probability Distributions | distributions-simulator.html distributions-derivation.html | shape, mean | board, dice, light | Chapter 3 | 20261112 |
| S02 Bayesian Updating | bayes-update-simulator.html bayes-update-derivation.html | beta, gauss | coin, scale | Chapter 4 | 20261112 |
| S03 Regression and Overfitting | regression-simulator.html regression-derivation.html | fit, biasvar, bayes | overfit, shake, band | Chapters 6, 8 | 20261112 |
| S04 Classification and Kernels | classifier-simulator.html classifier-derivation.html | logistic, svm | line, road | Chapters 9–11 | 20261112 |
| S05 Neural Networks | neural-net-simulator.html neural-net-derivation.html | trace, train, gradcheck | learn, flow | Chapters 14, 15 | 20261112 (two: initial values and data) |
| S06 Gaussian Processes and Bayesian Optimization | gp-bo-simulator.html gp-bo-derivation.html | gp, bo, compare | predict, search | Chapters 12, 13 | 20261112 |
| S07 Latent Variables | latent-simulator.html latent-derivation.html | em, pca | group, axis | Chapters 17, 18 | data 20261113, initial value 1 |
| S08 Approximate Inference and MCMC | inference-mcmc-simulator.html inference-mcmc-derivation.html | approx, mh | walk, trace | Chapters 20, 21 | 20261112 |
| S09 Sequence Models | hmm-simulator.html hmm-derivation.html | hmm, kalman | guess, track | Chapter 22 | 20261112 |
| S10 Attention and Next-Token Generation | attention-simulator.html attention-derivation.html | attn, model | look, write | Chapters 24–26 | 20261112 |
D.1.2 Operating environment and communication with the outside
- The simulators run on static HTML, CSS, and JavaScript only. Each simulator consists of a file for the simulator’s screen (
sim/NAME-simulator.html), a file containing the screen of the simple view and the computations added for it (sim/NAME.easy.js; the computation functions do not touch elements of the screen), a file containing only the computation (sim/NAME.model.js, pure functions that do not touch elements of the screen), a shared numerical computation library (sim/lib/mlcore.js), and shared screen components (sim/lib/mlui.js,sim/lib/mlsim.css). The explanation page (sim/NAME-derivation.html) is a static page with no controls; it reads only the stylesheet for explanations (sim/lib/mlderiv.css) and reads no scripts. The former screen file (sim/NAME.html) is a short file whose only purpose is to move to the new simulator page. The simulator page reads the shared screen components in the formmlui.js?v=2andmlsim.css?v=2(so that the new version is read even if an earlier version remains in the reader’s browser). Only S10 also reads the trained weights (sim/data/tinygpt.js) and the table of the bigram model (sim/data/tinygpt_bigram.js). - The computation was separated from the screen so that the same computation file can be run as it is in Node.js and compared numerically with a Python reference computation (the tests of D.1.7). The scripts use only the classic loading by
<script src>, so they are built to work even when the file is opened directly (file://) without starting a server. We checked that there are no console errors when opening withfile://for all ten simulators, but only S09 and S10 were operated through the whole script overfile://; for the other eight, only the display right after opening was checked (Table D.3, D.12). - No external inference API, API key, external font, or CDN is used. The small model of S10 also computes its forward propagation inside the browser (it does not query a server). The scripts of the simulators contain neither commands that communicate (
fetch,XMLHttpRequest, and so on) nor storage in the browser (localStorage, and so on). The values you enter are not sent outside and do not remain after the page is closed. The only thing sent to the parent page when embedding is the display height (in pixels). For the files after the division in December 2026 (the simulator and explanation pages,sim/NAME.easy.js, and the shared screen components), we also confirmed by string search that they contain nofetch,XMLHttpRequest,localStorage,sessionStorage, or URLs pointing outside. - The chapter pages (the main text) load MathJax from a CDN to display equations, but the pages of each simulator (the simulator page and the explanation page) do not.
D.1.3 Random numbers
- All simulators use only mulberry32 (a small pseudorandom number generator with a 32-bit state) as the random number generator. The seed is rounded to a 32-bit unsigned integer. Gaussian random numbers are generated by the Box–Muller method, gamma random numbers by the Marsaglia–Tsang method, and Poisson random numbers by the product method when the mean is below 30 and by the PTRS method when it is 30 or above. The browser’s built-in
Math.randomis not used. - The simulators that use random numbers have a “Random-number seed” field in which you can enter an integer, along with the buttons “Rerun with same seed,” “Change seed” (adds 1), and “Reset to default.” In the same browser, the same seed and the same order of operations give the same result (in the tests we checked the reproducibility with a fixed seed for each simulator). To reuse the sequence of random numbers from the beginning, press “Rerun with same seed.”
- Exception: elementary functions such as
Math.log,cos,sin,tanh, andexpmay differ in the last 1 ulp (one unit in the last place, the least significant digit of double precision) depending on the execution environment (Gaussian random numbers also pass through them). The difference is normally not visible in the displayed digits, but in an ill-conditioned iterative computation the result changes slightly. An example recorded at the time of writing: for the SVM of S04 (linear kernel, overlapping data, $C=1000$), the number of SMO iterations to convergence was 7,614 in Chrome and 7,583 in Node.js (this difference was not checked again). For S07, the values on screen and in Node.js were treated as agreeing to the fifth digit.
D.1.4 Display of equations
The equations on the simulators’ screens are written in the browser’s standard MathML (MathJax is not used). Therefore they look slightly different from the equations in the main text (for example, the transpose is $\tp$ in the main text but T on screen), but the choice of symbols matches the main text. Many simulators have a panel “Putting the current numbers into the formula,” which displays the formula with the numbers of the current settings substituted. This panel is in the detailed view and not in the simple view. The equations on the explanation pages are also written in MathML. Boldface within equations is specified with MathML mathvariant="bold-italic" to match the main text’s $\bm{x}$ ("bold" for capital Greek letters and digits), and so that it also appears bold in Chrome, which does not reflect this specification, a bold typeface is specified in the stylesheet common to the simulators. Calligraphic and blackboard bold are written with mathematical characters (𝒩, 𝒟, ℬ, 𝔼) without using mathvariant. Boldface in explanatory text outside the equations (<b>) is upright bold, and its shape differs slightly from the bold italic of the main text. How MathML looks in browsers other than Chrome has not been checked.
D.1.5 Embedding parameters
| Parameter | Effect |
|---|---|
?level=easy?level=detail | Specifies the level (simple view or detailed view) shown when the page is opened. Without a parameter, the page opens in the first scene of the simple view. |
?embed=1 | Hides the title (h1) and the introductory text. This is the form used when embedding in a chapter. If no level is specified, the page opens in the detailed view. The explanation that used to be below the simulator (procedure, formulas, conditions, questions) has been moved to the explanation page, so the screen has a one-line link to the explanation page. |
?only=<key> | Displays only that tab (scene) and removes the others. It also serves as embed=1. The level is the one to which the key belongs. The boxes in the main text (Simulator N.k) embed one tab of the detailed view in this form. |
#<key> | The tab selected when the page is opened (example: sim/gp-bo-simulator.html#compare). If the key belongs to a scene of the simple view, the page opens in the simple view; if it belongs to a tab of the detailed view, it opens in the detailed view. |
?mode=hand | S09 only. Opens the hidden Markov model tab in hand-calculation mode ($T=3$). |
The level is determined by the first of the following that is present, in this order: the key of ?only=, the key of #, ?level=, and ?embed=1. Parameters attached to a former URL (sim/NAME.html) are passed on as they are to the new simulator page. An embedded simulator reports its own height to the parent page on loading, when the screen width changes, when tabs are switched, and whenever the height of the page changes, and the height of the frame on the main-text side changes accordingly.
D.1.6 Computation limits, behavior on errors, and when JavaScript is disabled
- All inputs have limited ranges (the minimum and maximum of sliders; numeric fields are rounded into the range). The range and upper limit of each simulator are given in D.2–D.11.
- Time-consuming computations (the evolution of the sample mean in S01, the bias and variance in S03, the comparison in S06, and so on) are divided into pieces of at most 12 ms per frame and advanced little by little, so that you can press “Stop.” No simulator keeps running a computation automatically just because it has been opened.
- The motion of the pictures in the simple view (balls falling, a traveler walking, and so on) is played by a single function of the shared screen components. With the “reduce motion” setting (
prefers-reduced-motion: reduce), the intermediate frames are not drawn, and the resulting picture is drawn at once. - On screens 820 px wide or narrower, the picture of the simple view is kept at the top edge of the screen, so that the picture stays visible while you scroll the controls below it. However, it is not kept there when the screen height is less than 600 px, when the height of the picture exceeds 55 % of the screen height, or when the simulator is embedded (
?embed=1,?only=). - When NaN (not a number) or ∞ appears during a computation, the computation is stopped and a sentence on screen says what happened. The same applies when training diverges (S04, S05).
- All operations are done with buttons, sliders, selection fields, and numeric fields, and can also be done from the keyboard (tabs move with ←, →, Home, and End). Each figure (canvas) is given a sentence describing the state at that moment (aria-label), which is updated every time the figure is drawn. We do not rely on color alone: line styles, marker shapes, and the text beside the curves also distinguish them.
- When JavaScript is disabled, the interactive part and the figures are not displayed. In that case a notice, “The interactive part does not work,” and links to the explanation page and to the section of the main text are displayed. The explanation (procedure, the formulas being computed, conditions of the data and random numbers, simplifications, conditions for instability, questions) is on the explanation page, and the explanation page is static HTML that uses no scripts, so it can be read as it is. The boxes embedded in the main text carry a notice to the same effect.
D.1.7 How the checks were carried out
- Numerical tests (Node.js): The computation file of each simulator and the shared library were run in Node.js (v25.9.0) and compared with reference values computed separately in Python (NumPy 2.5.4, SciPy 1.18.1; CPU, double precision). For S05 the automatic differentiation of PyTorch (double precision) was also used as a reference, for S06 mpmath (50 digits), and for S10 the PyTorch model used for training (single precision). All computations of the simulators are in double precision (JavaScript numbers).
- Statistical checks: Quantities that use random numbers were evaluated only once with a fixed seed, and the tolerance was set to a size at which “a correct generator passes.” As a guide, about 4 standard errors; for the Kolmogorov–Smirnov test (hereafter, KS test), the statistic $D\lt 1.95/\sqrt{n}$ (significance level about 0.1 %); and for the $\chi^{2}$ test, the upper 0.1 % point. We did not reselect seeds to suit the tests, nor widen the tolerances afterward.
- Independent recomputation: Separately from the tests, the main values of each simulator (including the numbers appearing in the procedures of the boxes in the main text) were recomputed with Python programs (NumPy and SciPy; mpmath as well for S06) rewritten without looking at the reference computation of the tests, and compared with the values of the computation file. The differences were sufficiently smaller than the displayed digits. There were two exceptions: for the SVM of S04, because of the stopping tolerance $\varepsilon=10^{-3}$, the margin width and similar quantities differed from the reference in the fourth digit (relative difference at most $3.6\times10^{-4}$), and for the EI and PI of S06, the values differed from the reference in the tail beyond $z\approx-20$ (D.7.5).
- Screen checks: In headless Chrome (desktop version), we opened the screens at widths of 390, 768, and 1280 px (for S10 also 310 and 352 px, which correspond to the chapter’s frame), operated them according to the script (boundary values, starting over, all tabs,
?embed=1,?only=, keyboard operation, the procedures in the boxes of the main text), and compared the numbers on the screen with the Node.js values (the “comparisons” in the script). At the same time, we confirmed that no horizontal scrolling of the page appears and that console errors and loading failures are zero, and we looked at some of the captured images by eye and fixed overlapping text and the like. - The shared numerical computation library itself was also checked with 685 tests: special functions (the log-gamma function, the regularized incomplete gamma and beta functions and their inverses, the error function, the cumulative distribution function and quantile of the Gaussian distribution, log-sum-exp, softmax, and so on) with 347 tests against SciPy’s special, probability distributions with 264 tests against SciPy’s stats, linear algebra (Cholesky decomposition, QR decomposition, least squares, eigendecomposition of symmetric matrices, SVD, and so on) with 28 tests against NumPy’s linalg, statistical functions with 14 tests against NumPy, and 5 tests of random-number reproducibility and 27 tests of sample statistics. All succeeded.
| Simulator | Numerical tests (count) | Screen checks (steps / comparisons) | Check of opening with file:// |
|---|---|---|---|
| Shared library | 685 | — | — |
| S01 Probability Distributions | 593 | 218 / 41 | Right after opening (390 px) |
| S02 Bayesian Updating | 170 | 126 / 22 | Right after opening (390 px) |
| S03 Regression and Overfitting | 217 | 283 / 61 | Right after opening (3 widths) |
| S04 Classification and Kernels | 275 | 339 / 71 | Right after opening (3 widths) |
| S05 Neural Networks | 253 | 174 / 19 | Right after opening |
| S06 Gaussian Processes and Bayesian Optimization | 221 | 158 / 24 | Right after opening |
| S07 Latent Variables | 208 | 154 / 38 | Right after opening (390 px) |
| S08 Approximate Inference and MCMC | 656 | 128 / 29 | Right after opening (390 px) |
| S09 Sequence Models | 285 | 169 / 44 | All steps of the script |
| S10 Attention and Next-Token Generation | 587 | 179 / 42 | All steps of the script |
The counts in the table “How and to what extent the numbers were checked” in each of the following sections are the number of test items (one item is one comparison or one condition). The “comparisons” in the screen checks are the number of places in the script where a value or a state on the screen was checked, and all succeeded. The numerical tests of Table D.3 were all run again on November 13, 2026, and we confirmed that all succeeded with the same counts.
D.1.8 Checks made when the simulators were divided into two pages in December 2026
- That the detailed view is the same as the simulator as originally made: For each of the ten simulators, we opened the original page and the detailed view of the new simulator page in headless Chrome (widths of 390 px and 1280 px), carried out the same scripted operations in the same order as in the screen checks of Table D.3, and after each step compared the displayed tab, the text of the panels, the values in the input fields, the states of the buttons, the pixels of the figures (canvas; as hash values), the descriptive sentences of the figures, and the heights of the panels. Including the state right after opening,
?embed=1, and?embed=1&only=<key>(all keys), 2016 states in total were compared across the ten simulators, and the differences were 0. States whose results differed even between two openings of the original page (those determined by, for example, the moment at which a running computation was stopped: 9 in S04, 4 in S05, 13 in S08, and 2 in S10) were excluded from the comparison. For S10, the first run, made at the same time as other comparison runs, showed differences in 4 states of the figures after sentence generation, but when it was rerun alone the differences were 0. Console errors were 0 on both pages. - Computations of the simple view: The computations added for the simple view (
sim/NAME.easy.js) were compared with the computation files and with closed-form expressions in 4059 Node.js tests in total, and all succeeded (the counts for each simulator are in Sections D.2–D.11). The tests of the detailed view (the Node.js tests of D.1.7; 11 files, 4150 tests in total) were also run again after the division, and all succeeded. The computation files (sim/NAME.model.js) and the shared numerical computation library (sim/lib/mlcore.js) have not been changed by a single byte since they were made (confirmed with MD5). - Screens of the simple view: We ran a script that operates all scenes of the simple view of each simulator at widths of 390, 768, and 1280 px; all checks of the text and states on the screen (298 in total) passed, and we confirmed that there are no console errors and no horizontal scrolling. With the “reduce motion” setting (
prefers-reduced-motion: reduce, set through Chrome’s media emulation), we pressed every button, picture card, and “Try it” item in all 22 scenes once, and confirmed that no button became impossible to press, that no intermediate display remained, and that console errors were 0. At a width of 390 px and a height of 844 px, we confirmed that in all 22 scenes the picture stays at the top edge of the screen and is fully visible even after a “Try it” item is pressed, and that the picture does not overlap other displays. - Links and redirects: We changed the links to the simulators from the main text, the table of contents, and this appendix to the new pages, and confirmed that the link targets (including the id after
#) exist. We opened the former URLs with no parameter, with#<key>, with?embed=1&only=<key>(all keys), and, for S09, with?mode=hand, and confirmed that the expected level and tab (scene) of the new page open (113 cases in total). We opened the 20 simulator and explanation pages viafile://at widths of 390 px and 1280 px, and confirmed that there is no horizontal scrolling and that loading failures and console errors are 0. - Embedding in the main text: We opened the 19 chapters in which simulators are embedded at widths of 390, 768, and 1280 px, brought every frame (37 at each width, 111 in total) into view so that it loaded, and confirmed that each opens in the one specified tab of the detailed view, that the height of the frame matches the height reported by the simulator (difference within 4 px), that there is no horizontal scrolling, and that console errors are 0. In each chapter we also carried out the steps of “Operate and Observe” in the boxes one by one, and confirmed that the numbers written in the main text appear on the screen.
- Not checked: browsers other than Chrome, and actual devices (D.12.1). Whether the simple view helps first-time readers understand (its educational effect) has not been studied by having readers use it.
D.2 S01 Probability Distributions (distributions)
D.2.1 Corresponding chapters, sections, and tabs
- Chapter 3: Section 3.5 (Simulator 3.1, tab shape), Section 3.7 (Simulator 3.2, tab mean). It is also related to Sections 3.1, 3.2, 3.4, and 3.8–3.10, and to Chapter 2, Section 2.8 (law of large numbers).
- Tab
shape, “① Distribution Shape and Interval Probability”; tabmean, “② Behavior of the Sample Mean.” - Scenes of the simple view (added in December 2026):
board“If you drop balls, what shape do they pile up into?” (balls are dropped one at a time onto a pin board (6, 12, or 24 rows; share going right 0.5 or 0.7), and the numbers of balls piled up in the bins are overlaid with the heights computed from the binomial distribution and with the curve of the Gaussian approximation),dice“What if you roll many dice and take the average?” (rolling 1, 4, or 16 dice and averaging them is repeated, to see that making the number of dice 4 times larger halves the width of the scatter of the average),light“Can an average fail to settle down?” (when a light placed 1 unit away from a wall shines in a random direction, we see that the mean of the positions where the light hits (Cauchy distribution) does not settle down even as the number of trials increases). The computations use functions of the same computation file as the detailed view (main ones: make, curve, drawSample, sampleStats, pathSeed, RunningMedian). The explanation page is distributions-derivation.html.
D.2.2 What is computed
- ①: For eight distributions (binomial, Poisson, Gaussian, Cauchy (Lorentzian), gamma (shape $a$, rate $b$), beta, Student’s t (location $\mu$, scale $s$), and Weibull), the simulator computes the probability density (mass) function, the cumulative distribution function $F$, quantiles, the mean and variance (if they do not exist, it displays “does not exist” together with the reason), the median, the mode, and the full width at half maximum. When there are two modes (when $\lambda$ of the Poisson distribution is an integer, or when $(N+1)\mu$ of the binomial distribution is an integer; example: 3 and 4 for $\lambda=4$), both are displayed with “same maximal probability.” The interval probability is obtained from $$P(x_1\le x\le x_2)=F(x_2)-F(x_1)$$ (for a discrete distribution the endpoint integers are included). The cumulative distribution function is computed with the error function, the regularized incomplete gamma and beta functions, the arctangent, and so on; in the “Check” line on the screen, the direct sum of the probability mass function is shown for discrete distributions, and the double-exponential numerical integration of the probability density function for continuous distributions.
- As the reason why the mean does not exist for the Cauchy distribution (and for the t distribution with $\nu=1$), the simulator shows with the numbers $R=10\gamma,100\gamma,1000\gamma$ that $\int_{x_0-R}^{x_0+R}\abs{x-x_0}\,p(x)\,\dd x$ $=(\gamma/\pi)\ln(1+R^{2}/\gamma^{2})$ keeps growing with $R$.
- The samples (histogram) are drawn from the first distribution. The Gaussian uses the Box–Muller method; the Cauchy uses $\tan(\pi(u-1/2))$; the t uses $z/\sqrt{g/\nu}$ ($z$ is a standard Gaussian random number and $g$ is a $\chi^{2}$ random number with $\nu$ degrees of freedom); the gamma uses the Marsaglia–Tsang algorithm; the binomial uses a sum of Bernoulli variables; and the Poisson uses the product method or the PTRS algorithm.
- ②: From independent samples of the Gaussian, Cauchy, and t distributions, the simulator draws the evolution of the sample mean $\bar{x}_n$ (or the median) against the number of samples $n$ for several sequences (the horizontal axis is logarithmic; the number of recorded points is 151/180/197 for the upper limits of $n$ of $10^{3}$/$10^{4}$/$10^{5}$). For the Gaussian (and the t distribution with $\nu\gt 2$) a band of $\pm\sigma/\sqrt{n}$ is overlaid; for the Cauchy distribution, lines at the center $\pm\gamma$ (the half width at half maximum of the distribution of $\bar{x}_n$ does not depend on $n$); and for the median, a band given by the asymptotic formula $\pm1/(2p(m)\sqrt{n})$.
D.2.3 Input ranges, upper limits, and random numbers
- Parameter ranges (defaults in parentheses): binomial $N$ 1–200 (20), success probability 0–1 (0.3); Poisson $\lambda$ 0.1–60 (4); Gaussian $\mu$ −5 to 5, $\sigma$ 0.1–5 (defaults $\mu=0$, $\sigma=1$); Cauchy $x_0$ −5 to 5 (0), $\gamma$ 0.1–5 (1); gamma $a$ 0.2–20 (2), $b$ 0.1–10 (1); beta $a,b$ 0.2–20 (2, 5); $\nu$ of the t distribution is chosen from 17 values between 0.5 and 1000 (including 1 and 2 exactly; default 3), $s$ 0.1–5; Weibull $m$ 0.5–30 (5), $s_0$ 0.2–5 (1).
- The number of samples in ① is none/100/1000/10000, and the upper limit is 10000 samples (the upper limit of the calculation file is also 10000). The $n=20000$ of the KS test and the $\chi^{2}$ test in D.2.6 comes from tests that called the calculation file directly; it cannot be selected on the screen. In ②, the upper limit of $n$ is $10^{3}$/$10^{4}$/$10^{5}$, the number of sequences is 1–20, and the scale is 0.2–3 (the location is fixed at 0). In the largest case, $10^{5}\times20$ sequences × 2 distributions $=4\times10^{6}$ random numbers are computed in chunks of 12 ms each (about 0.56 s in Chrome).
- The default seed is 20261112 for both ① and ②. The seed of sequence $j$ in ② is seed $+\,j\cdot$0x9E3779B9, so the initial part of each sequence is the same even if the upper limit of $n$ or the number of sequences is changed. The 1000 Cauchy samples in ① and the first 1000 samples of sequence 1 of the Cauchy distribution in ② take the same values.
D.2.4 Simplifications
- The parameter ranges are restricted, and $\nu$ of the t distribution is chosen from 17 values.
- The histogram in ① counts only the samples inside the plotted range (the number outside the range is displayed).
- In ②, the location is fixed at 0, and the scale takes a common value for the three distributions (the full widths at half maximum are not matched). The median band is an asymptotic approximation.
- The detailed view provides no example comparing the binomial distribution with its Gaussian approximation (because it does not fit within the range −5 to 5 of the Gaussian $\mu$). In the scene
boardof the simple view, the numbers of balls piled up in the bins of the pin board are overlaid with the heights computed from the binomial distribution (number of balls × probability) and with the curve of the Gaussian distribution with the same mean and variance.
D.2.5 Conditions for instability and the behavior of the simulator
- For the Cauchy distribution and for the t distribution with $\nu\le 2$, samples with very large values (of the order of $10^{5}$–$10^{7}$) appear, and the sample mean and sample variance jump. This is not a calculation error but a property of the distribution, and the simulator displays it as it is.
- For the gamma distribution with $a\lt 1$, the beta distribution with $a\lt 1$ or $b\lt 1$, and the Weibull distribution with $m\lt 1$, the density diverges at an endpoint. The figure is clipped by the frame, and the numerical-integration “Check” deviates by up to about $10^{-8}$ at the endpoint because of the limits of double precision.
- When the vertical axis is logarithmic, values below $10^{-300}$ are rounded to 0 and the line is cut.
- If NaN or ∞ appears, the calculation is stopped and the reason is displayed.
D.2.6 How and to what extent the numbers were checked
| Quantity checked | Compared against | Type | Number | Tolerance, etc. |
|---|---|---|---|---|
| Probability density (mass) function, cumulative distribution function, and quantiles (29 parameter sets) | SciPy stats | independent implementation | 94 | density rtol $10^{-11}$, cumulative distribution rtol $10^{-10}$, quantile rtol $10^{-9}$ |
| Mean, variance, and median (“none” with the reason for those that do not exist) | SciPy stats | independent implementation | 89 | — |
| Normalization (integral of the density = 1, sum of the mass = 1) | Theoretical value (integrating from the 0.0001 % point to the 99.9999 % point by adaptive Simpson’s rule gives $1-2\times10^{-6}$) | analytical solution | 53 | — |
| Interval probability $P(x_1\le x\le x_2)$ | SciPy stats, direct sum of the mass, double-exponential numerical integration of the density | independent implementation | 212 | rtol $10^{-9}$ (atol $10^{-8}$ only when the density diverges at an endpoint) |
| Full width at half maximum | Analytical formula, and the value found with SciPy brentq | analytical solution, independent implementation | 39 | rtol $10^{-10}$ |
| Partial integral of the Cauchy density $(\gamma/\pi)\ln(1+R^{2}/\gamma^{2})$ | SciPy quad | independent implementation | 25 | rtol $10^{-8}$ |
| Sequential computation of the sample mean and median, computation in time chunks, reproducibility of the seed, formulas of the theoretical values | Direct computation, batch computation | analytical solution | 23 | the median agrees exactly |
| Distribution of the samples (continuous distributions) | KS test ($n=20000$) | statistical | 22 | $D\lt1.95/\sqrt{n}$ |
| Distribution of the samples (discrete) | $\chi^{2}$ goodness-of-fit test ($n=20000$) | statistical | 7 | upper 0.1 % point |
| Spread of the sample mean: for the Gaussian, $\sigma^{2}/n$; for the Cauchy, $\bar{x}$ ($n=1000$, 400 sequences) remains a Cauchy distribution (KS test and interquartile range ≈ $2\gamma$); standard deviation of the median ≈ $\pi\gamma/(2\sqrt{n})$ | Theoretical value | statistical | 6 | about 4 standard errors, KS test |
| Mean and variance of the histogram samples | Theoretical value | statistical | 9 | about 4 standard errors |
| Mode (including ties for discrete distributions) | Value obtained by full enumeration of the maximum of the probability mass function | full enumeration | 9 | exact agreement |
| Input restrictions (rounding to the range, upper limit; that a finite value is returned even for 20000 samples beyond the upper limit) | — | — | 5 | — |
In the checks on the screen, 218 steps (41 comparisons) were carried out, including boundary values (the minimum and maximum of $\nu$, binomial $N=200$ with success probability 0 and 1, gamma $a=0.2$, beta $a=b=0.2$, Weibull $m=30$, 0 samples and 10000 samples, a single sequence, and $n=10^{5}\times20$ sequences) and the operating procedure of the box in Chapter 3.
The computations added for the simple view (sim/distributions.easy.js) were checked with 329 Node.js tests, and all succeeded. They were compared with the functions of the computation file (including that the sequence of bins for the balls is the same, for the same seed, as the samples of the binomial distribution in ① of the detailed view) and with closed-form expressions such as binomial coefficients, convolutions, and the cumulative distribution function of the Cauchy distribution.
D.3 S02 Bayesian Updating (bayes-update)
D.3.1 Corresponding chapters, sections, and tabs
- Chapter 4: Section 4.5 (Simulator 4.1, tab beta), Section 4.8 (Simulator 4.2, tab gauss). Also Section 4.4 and Section 4.6.
- Tab
beta“① Beta–Bernoulli (success rate),” tabgauss“② Mean of a Gaussian.” - Scenes of the simple view (added in December 2026):
coin“Does this coin land heads more often?” (each time the coin is tossed, we see the peak of the guess of the probability of heads (Beta distribution) move and become narrower; the initial belief is chosen from three: Beta(1, 1), Beta(2, 2), and Beta(20, 20)),scale“If you weigh many times, do you get closer to the true weight?” (the weight of one apple is measured many times with a scale whose display fluctuates (standard deviation of the fluctuation 5 g, 10 g, or 20 g), and we see the guess of the weight (the posterior distribution of the mean of a Gaussian) become narrower). The computations use functions of the same computation file as the detailed view (main ones: betaSummary, countObs, drawBernoulli, gaussPosterior, drawGauss). The explanation page is bayes-update-derivation.html.
D.3.2 What is computed
- ①: After observing $m$ successes and $l$ failures ($N=m+l$), the prior distribution $\mathrm{Beta}(\mu\mid a,b)$ becomes the posterior distribution $\mathrm{Beta}(\mu\mid a+m,\,b+l)$. The simulator shows the maximum likelihood estimate $m/N$, the MAP estimate $(a+m-1)/(a+b+N-2)$ (when $a+m\gt1$ and $b+l\gt1$), the posterior mean $(a+m)/(a+b+N)$ (= the posterior prediction $p(x=1\mid\data)$), the posterior standard deviation, the 95 % credible interval (equal-tailed; found with the inverse of the regularized incomplete beta function), and the data weight $w=N/(a+b+N)$.
- The likelihood in the figure is drawn with its area normalized to 1 (the same shape as $\mathrm{Beta}(\mu\mid m+1,l+1)$). “Compare sequential and batch updates” compares the sequence of parameters updated one observation at a time, and the density obtained by multiplying numerically one observation at a time on a grid of 2001 points, with the batch analytical solution.
- ②: With the noise variance $\sigma^{2}$ known, from the prior distribution $\Normal(\mu\mid\mu_0,\sigma_0^{2})$ it finds $$\begin{aligned}\frac{1}{\sigma_N^{2}}&=\frac{1}{\sigma_0^{2}}+\frac{N}{\sigma^{2}},\\ \mu_N&=\sigma_N^{2}\left(\frac{\mu_0}{\sigma_0^{2}}+\frac{N\bar{x}}{\sigma^{2}}\right)\end{aligned}$$ and displays the variance of the posterior predictive distribution split into $\sigma^{2}$ (noise) and $\sigma_N^{2}$ (lack of knowledge).
D.3.3 Input ranges, upper limits, and random numbers
- ①: $a,b$ range over 0.5–30 (in steps of 0.5; default 1, 1), the true $\mu$ over 0.01–0.99 (default 0.70), and up to 2000 observations. ②: $\mu_0$ from −3 to 3 (0.0), $\sigma_0$ 0.1–3 (2.00), $\sigma$ 0.2–3 (1.00), the true $\mu$ from −3 to 3 (1.5), and up to 1000 observations.
- Synthetic data (synthetic data for teaching purposes; dimensionless): in ① a uniform random number $u\lt\mu$ counts as a success; in ② $x=\mu+\sigma\varepsilon$ with $\varepsilon\sim\Normal(0,1)$. The default seed is 20261112. Changing the seed clears the observations and draws them again.
D.3.4 Simplifications
- The observations are assumed independent and $\mu$ constant. In ② the noise variance is assumed known (if it were unknown, the posterior predictive distribution would be a Student’s t distribution).
- The credible interval is an equal-tailed interval, not a highest-density interval. The ranges of the parameters are restricted.
D.3.5 Conditions for instability and the behavior of the simulator
- When $a+m\lt1$ or $b+l\lt1$, the density diverges at an endpoint and has no interior maximum, so no MAP estimate is given and the reason is displayed. When $a+m=1$ or $b+l=1$ (with the other greater than 1), the maximum is at an endpoint and agrees with the value from the formula; a note to this effect is shown (example: with a uniform prior and 3 successes in 3 trials, the MAP estimate is 1).
- When $N=0$, the maximum likelihood estimate is undefined (it is not displayed). When the posterior distribution is uniform ($a+m=b+l=1$; for example Beta(1,1) left as it is with $N=0$), the MAP estimate is displayed as “not unique.”
- When $N$ is large, the peak of the density becomes sharp and the vertical axis stretches, but the computation is done with logarithms, so no overflow occurs.
D.3.6 How and to what extent the numbers were checked
| Quantity checked | Compared against | Type | Number of tests | Tolerance, etc. |
|---|---|---|---|---|
| Parameters of the Beta–Bernoulli posterior distribution, posterior mean and posterior prediction, standard deviation, MAP, maximum likelihood, 95 % credible interval, weight $w$ (11 combinations of $a,b,m,l$) | SciPy’s stats.beta and the analytical solution | Analytical solution and independent implementation | 98 | Posterior mean rtol $10^{-15}$, standard deviation rtol $10^{-12}$, credible interval maximum absolute error $10^{-11}$ |
| Sequential updating = batch updating (500 observations, reversed order, numerical computation one observation at a time on the grid with $N=10$–2000) | Batch analytical solution | Analytical solution | 9 | Maximum relative difference from the grid $7.46\times10^{-13}$ ($N=2000$) |
| Reproducibility of the seed; fraction of successes, mean, and variance of the synthetic data | True values | Statistical | 4 | About 4 standard errors |
| Posterior distribution of the Gaussian mean $\mu_N,\sigma_N^{2}$, predictive variance, credible and prediction intervals, sequential = batch (6 combinations) | Analytical solution and SciPy’s stats.norm | Analytical solution and independent implementation | 50 | $\mu_N$ rtol $10^{-13}$, $\sigma_N^{2}$ rtol $10^{-14}$, intervals $10^{-12}$ |
| Case analysis of the MAP estimate (interior maximum, endpoint when one parameter is 1, not uniquely determined when uniform, divergence below 1) | Maximum of the density on a grid, analytical case analysis | Analytical solution | 9 | — |
The on-screen checks comprise 126 steps (22 cross-checks), including the operating procedures in the boxes of Chapter 4.
The computations added for the simple view (sim/bayes-update.easy.js) were checked with 943 Node.js tests, and all succeeded. They were compared with the functions of the computation file, closed-form expressions, and the values of SciPy’s Beta distribution.
D.4 S03 Regression and Overfitting (regression)
D.4.1 Corresponding chapters, sections, and tabs
- Chapter 6: Section 6.2 (Simulator 6.1, tab fit), Section 6.4 (Simulator 6.2, tab biasvar), Section 6.6.
- Chapter 8: Section 8.6 (Simulator 8.1, tab fit), Section 8.8 (Simulator 8.2, tab bayes), Section 8.7.
- Tabs
fit“① Polynomial Regression and Regularization,”biasvar“② Bias and Variance,”bayes“③ Bayesian Linear Regression.” - Scenes of the simple view (added in December 2026):
overfit“Does a curve that fits the points exactly also fit new data?” (after choosing the degree of the polynomial (1, 3, or 9) and whether to regularize, a curve is fitted to the points at hand, and the error on the points at hand and the error on 200 points of new data (RMSE, root mean square error) are compared with bars),shake“Does the shape of the curve change each time you measure again?” (the data are measured again 15 points at a time and the fitted curves are overlaid, to see the deviation of their mean line from the true curve (bias) and their scatter (variance)),band“As more points are measured, how does the range of the prediction change?” (each time one more point is measured, we see the predictive band of Bayesian linear regression (the same cubic polynomial as in ③ of the detailed view) become narrower). The computations use functions of the same computation file as the detailed view (main ones: makeDataA, makeDatasets, makeValidation, designPoly, fitPoly, evalPoly, predict, rmse, bvSweepLambda, bayesPosterior, bayesPredict, bayesPredictMany, bayesSamples). The explanation page is regression-derivation.html.
D.4.2 What is computed
- The data are Data A of Chapter 6 (synthetic data for teaching purposes): $s=(T-1300\ ^{\circ}\mathrm{C})/(200\ ^{\circ}\mathrm{C})\in[-1,1]$, $y=88+8s-5s^{2}+2\sin 3s+\varepsilon$ (relative density in %), $\varepsilon\sim\Normal(0,\sigma^{2})$.
- ①: With a polynomial of degree $d$ (basis functions $\phi_j(s)=s^{j}$, $j=0,\dots,d$, giving $M=d+1$ of them, $\bm{\Phi}\in\R^{N\times M}$), the simulator minimizes $$L(\bm{w})=\tfrac12\norm{(\bm{y}-88)-\bm{\Phi}\bm{w}}^{2}+\tfrac{\lambda}{2}\norm{\bm{w}}^{2}$$ for $\bm{y}-88$, the target values with the fixed baseline value 88 % subtracted. For $\lambda=0$ it solves by Householder QR decomposition, and for $\lambda\gt0$ by QR decomposition of $[\bm{\Phi};\sqrt{\lambda}\bm{I}]$ (no inverse matrix is formed). When $d+1\gt N$ and $\lambda=0$, the solution is not unique, so the minimum-norm solution by SVD is used and this is displayed. It displays the RMSE $=\sqrt{(1/N)\sum_n(y_n-f(s_n))^{2}}$ on the training data and on the validation data (200 separate points from the same distribution), the RMSE against the true function, and the condition number of $\bm{\Phi}$.
- ②: From the mean $\bar{f}(s)$ of the curves $f^{(l)}(s)$ fitted to $L$ training data sets, it finds $(\text{bias})^{2}=\langle(\bar f-g)^{2}\rangle_s$, the variance $=\langle(1/L)\sum_{l=1}^{L}(f^{(l)}-\bar f)^{2}\rangle_s$, and the noise $\sigma^{2}$ ($\langle\cdot\rangle_s$ is the midpoint rule with 200 points on $[-1,1]$, and $g$ is the true function). The sweep over $\lambda$ is solved by SVD, and the mean and variance are updated sequentially, one data set at a time.
- ③: Under the prior distribution $p(\bm{w})=\Normal(\bm{w}\mid\bm{0},\sigma_w^{2}\bm{I})$, it uses $\bm{S}_N^{-1}=\sigma_w^{-2}\bm{I}+\sigma^{-2}\bm{\Phi}^{\tp}\bm{\Phi}$ and $\bm{m}_N=\sigma^{-2}\bm{S}_N\bm{\Phi}^{\tp}\bm{y}$ (the target value is again $y-88$), and the prediction $\Normal(y_*\mid\bm{m}_N^{\tp}\bm{\phi}_*,\ \sigma^{2}+\bm{\phi}_*^{\tp}\bm{S}_N\bm{\phi}_*)$. The band of lack of knowledge $\pm2(\bm{\phi}^{\tp}\bm{S}_N\bm{\phi})^{1/2}$ and the band of observed values $\pm2(\sigma^{2}+\bm{\phi}^{\tp}\bm{S}_N\bm{\phi})^{1/2}$ are drawn separately. The basis is either polynomial (degree $d$) or nine Gaussian basis functions (centers $c_j=-1,-0.75,\dots,1$, width $r=0.25$, no constant basis function).
D.4.3 Input ranges, upper limits, and random numbers
- ①: number of training data points $N$ 5–50 (10), noise standard deviation 0–3 % (1.0), degree $d$ 0–12 (3), $\ln\lambda$ from −20 to 4 (“no regularization” is the default).
- ②: degree 0–12 (9), $\ln\lambda$ from −14 to 4 (−3.0), $N$ of one data set 5–50 (15), noise 0.2–3 %, number of data sets $L$ 10–200 (100). The computation is split so that each frame takes at most 12 ms (measured with Node.js: about 20–25 ms for the default, about 150 ms for the largest setting).
- ③: the $\sigma$ assumed by the model 0.05–5 % (1.00), $\sigma_w$ 0.1–100 (10.0), up to 100 observation points (8 initially), the point of interest $s_*$ from −1.4 to 1.4 (1.20), and 0–10 function samples from the posterior distribution. The noise of the points drawn with “Draw from Data A” is fixed at 1.0 % (separate from the model’s $\sigma$).
- The default seed is 20261112. Points are drawn one at a time (in the order $s$ then $\varepsilon$), so with the same seed the earlier points remain when $N$ is increased. The validation data use the random-number sequence of seed + 1000003, and the samples in ③ use the sequence of seed + 7 (plus 101 each time they are redrawn).
D.4.4 Simplifications
- The fixed baseline value 88 % is subtracted from the target values, and a penalty (in ③, the prior distribution) is applied to all coefficients, including the intercept $w_0$. In practice the intercept is often not penalized, and in that case $\lambda$ acts slightly differently (this is noted in Chapter 8). The value 88 % is not computed from the data.
- Bias$^{2}$ is estimated from a finite number $L$ of data sets, so it contains an error of about variance$/L$.
- The $\sigma$ and $\sigma_w$ in ③ are given values, and the marginal likelihood is not maximized. The basis consists of monomials; orthogonal polynomials are not used.
D.4.5 Conditions for instability and the behavior of the simulator
- At high degrees without regularization, the condition number of $\bm{\Phi}$ becomes $10^{4}$–$10^{8}$ ($2.33\times10^{4}$ for $N=10$, $d=9$). When $d+1\gt N$ and $\lambda=0$, the solution is not unique, so the minimum-norm solution and a cautionary note are displayed.
- In ②, with no regularization and small $N$, the variance exceeds $10^{10}$ and is cut off at the top of the figure ($4.7\times10^{18}$ for $N=15$, $d=12$).
- In ③, if $\sigma/\sigma_w$ is made small (e.g., $\sigma=0.05$, $\sigma_w=100$) and $d=12$, then with the default 8 points the predictive mean swings to about −3000 % at the ends of the extrapolation ($s=\pm1.4$) (the numbers remain finite and the computation does not stop, but they fall outside the figure). With Gaussian basis functions, far from the centers of the basis functions $\bm{\phi}\approx\bm{0}$, and the band of lack of knowledge approaches 0 (the band becomes narrow even though the point is far from the data; this is due to the assumption in how the basis is placed).
- If NaN or ∞ occurs, the computation stops and the reason is displayed.
D.4.6 How and to what extent the numbers were checked
| Quantity checked | Compared against | Type | Number of tests | Tolerance, etc. |
|---|---|---|---|---|
| True function of Data A, design matrix of the Gaussian basis functions | NumPy | Independent implementation | 3 | $10^{-12}$, $10^{-15}$ |
| Coefficients of ① (including the minimum-norm solution) and of Ridge, RMSE on training and validation data and against the true function, condition number (13 settings) | NumPy’s lstsq, normal equations solved with SciPy | Independent implementation | 89 | Coefficients: relative norm $\max(10^{-10},\ \text{condition number}\times10^{-13})$; RMSE rtol $10^{-7}$–$10^{-8}$; condition number rtol $10^{-8}$ |
| Properties of the solution: QR solution = SVD solution, residual of the normal equations, interpolation at $N=d+1$, $\bm{w}\approx\bm{\Phi}^{\tp}\bm{y}/\lambda$ as $\lambda\to\infty$, $\norm{\bm{w}}$ decreasing monotonically in $\lambda$, training RMSE not increasing with the degree | Identities and limits | Analytical solution | 14 | — |
| Bias$^{2}$, variance, and $\langle(f^{(l)}-g)^{2}\rangle$ of ② | Mean and variance computed directly with NumPy | Independent implementation | 52 | rtol $10^{-6}$–$10^{-7}$. Relative difference of the identity below $10^{-12}$; difference between time-split and batch computation below $10^{-10}$ |
| $\bm{m}_N$, $\bm{\phi}^{\tp}\bm{S}_N\bm{\phi}$, and the predictive mean of ③; MAP = Ridge with $\lambda=\sigma^{2}/\sigma_w^{2}$; the prior distribution with zero data points; $\bm{\phi}^{\tp}\bm{S}_N\bm{\phi}$ not increasing when observations are added (5 settings) | NumPy ($\bm{S}_N$ built with an inverse matrix) | Independent implementation and analytical solution | 36 | Relative norm difference $10^{-8}$ |
| Reproducibility of the seed | — | — | 7 | — |
| Uniformity of $s$ in the synthetic data; distribution, mean, and variance of the noise ($n=20000$) | KS test, theoretical values | Statistical | 4 | $D\lt1.95/\sqrt{n}$, 4 standard errors |
| Mean squared error when predicting with the true function ≈ $\sigma^{2}$ | Theoretical value | Statistical | 1 | 4 standard errors |
| Bias$^{2}$ + variance + $\sigma^{2}$ = squared error at a new noisy point (independent Monte Carlo method) | Measured 1.8489 and predicted 1.8824 | Statistical | 1 | ±0.2623 (4 standard errors) |
| Mean and variance of the function samples from the posterior distribution (5 points) | $\bm{m}_N^{\tp}\bm{\phi}$, $\bm{\phi}^{\tp}\bm{S}_N\bm{\phi}$ | Statistical | 10 | 4 standard errors |
The on-screen checks comprise 283 steps (61 cross-checks), including the operating procedures in the boxes of Chapters 6 and 8. We also confirmed that there are no console errors in the display (at three widths) immediately after opening the page via file://.
The computations added for the simple view (sim/regression.easy.js) were checked with 621 Node.js tests, and all succeeded. They were compared with the functions of the computation file, simple computations written separately within the tests (the normal equations, Gaussian elimination, averages on a grid), and the numbers in the main text (Table 6.1 and the operating procedures of Simulators 6.1, 6.2, and 8.2).
D.5 S04 Classification and Kernels (classifier)
D.5.1 Corresponding chapters, sections, and tabs
- Chapter 9: Section 9.4 (Simulator 9.1), Section 9.6 (Simulator 9.2), Section 9.3. All use the logistic tab.
- Chapter 10: Section 10.5 (Simulator 10.1, svm tab). Chapter 11: Section 11.5 (Simulator 11.1), Section 11.6 (Simulator 11.2). All use the svm tab.
- Tab
logistic“① Logistic Regression” (label $y\in\{0,1\}$),svm“② Kernels and the SVM” (label $y\in\{-1,+1\}$). - Scenes of the simple view (added in December 2026):
line“Can one line separate the ● houses from the ■ houses?” (we see the boundary line move and separate the two kinds of points through gradient descent for logistic regression),road“How can we build the widest road between two villages?” (the boundary and the margin of the SVM are drawn as a “road” and its width, and a straight boundary is compared with a curved boundary (kernel)). The computations use functions of the same computation file as the detailed view (main ones: makeData, logisticEval, gdApply, makeKernel, smo, svmSummary, svmDecision, linearW, gridValues). The explanation page is classifier-derivation.html.
D.5.2 What is computed
- ①: With the features $\bm{\phi}(\bm{x})$ (first order $(x_1,x_2)$, or with the quadratic terms $x_1^{2},x_1x_2,x_2^{2}$ added) and $a_n=\bm{w}^{\tp}\bm{\phi}(\bm{x}_n)+b$, we add a regularization term to the sum of the cross-entropies, $$\begin{aligned}L(\bm{w},b)&=\sum_{n=1}^{N}\bigl[\ln(1+e^{a_n})-y_na_n\bigr]\\ &\quad+\tfrac{\lambda}{2}\norm{\bm{w}}^{2}\end{aligned}$$ ($b$ is not regularized), and reduce it by gradient descent starting from $\bm{w}=\bm{0}$, $b=0$. $\ln(1+e^{a})$ is computed in a form that does not overflow. As a guide to the stability of the learning rate, the simulator displays $2/L_c$ (where $L_c=\lambda_{\max}(\tilde{\bm{\Phi}}^{\tp}\tilde{\bm{\Phi}})/4+\lambda$ and $\tilde{\bm{\Phi}}$ is the matrix obtained by adding a column of constant 1 to the features), and, for comparison, the minimum $L^{*}$ found by Newton’s method. When the minimum is not attained at any finite weights (for example, linearly separable data with $\lambda=0$), the simulator reports this through the Newton’s method check.
- ②: It solves the dual problem of the SVM with a kernel (linear $\bm{x}^{\tp}\bm{x}'$, polynomial $(\bm{x}^{\tp}\bm{x}'+1)^{2}$ and $(\bm{x}^{\tp}\bm{x}'+1)^{3}$, RBF $\exp(-\gamma\norm{\bm{x}-\bm{x}'}^{2})$ with $\gamma=1/(2\ell^{2})$), $$\begin{aligned}\max_{\bm{\alpha}}\ &\sum_n\alpha_n-\tfrac12\sum_{n,m}\alpha_n\alpha_m y_ny_m k(\bm{x}_n,\bm{x}_m),\\ &0\le\alpha_n\le C,\qquad \sum_n\alpha_ny_n=0\end{aligned}$$ by the SMO algorithm. Each time a parameter is changed, the problem is solved again from $\bm{\alpha}=\bm{0}$, and the stopping criterion is $m(\bm{\alpha})-M(\bm{\alpha})\le\varepsilon=10^{-3}$. It draws $f(\bm{x})=\sum_n\alpha_ny_nk(\bm{x}_n,\bm{x})+b$, and $b$ is obtained from the free support vectors ($0\lt\alpha_n\lt C$; if there are none, the midpoint is used). The screen states that $f(\bm{x})$ is “a score, not a probability.” The simulator also displays the residual of the KKT conditions, the dual objective function $D$, the value $P$ of the primal problem, and the duality gap.
D.5.3 Input ranges, upper limits, and random numbers
- Common to both tabs: the data type (linearly separable / overlapping / concentric circles / two moons / XOR; synthetic data for teaching purposes; the two descriptors are standardized, dimensionless values), the number of data points $N$ from 10 to 200 (in steps of 2; default 60), and up to 300 points including points added by clicking. The default seed is 20261112 (both tabs).
- ①: $\lambda$ from $10^{-3}$ to 100 (logarithmic scale; default 0.010; “no regularization” is available), learning rate $\eta$ from $10^{-4}$ to 1 (logarithmic scale; default 0.010), and up to 50000 iterations.
- ②: $C$ from 0.01 to 1000 (default 1.00), $\gamma$ from 0.01 to 100 (default 1.00), and an upper limit on SMO iterations from 10 to 100,000 (default 100,000).
- The sliders for $\gamma$ and $C$ move in steps of 0.05 in $\log_{10}$, so they do not land exactly on round values. The displayed “20.0” is $\gamma=10^{1.3}=19.953$, “0.0501” is $10^{-1.3}$, and “5.01” is $10^{0.7}$ (the $C$ value “1000” is exactly $10^{3}$). Likewise $\eta$ cannot be set to 0.3, and the displayed “0.32” is $10^{-0.5}=0.3162$. The numerical values in the text of Chapters 10 and 11 are written with the values on the screen (such as $\gamma=19.953$). They differ in the fourth digit from values computed with exactly $\gamma=20$ (for example, for the two moons with $C=1$, the dual objective function $D$ is 19.319 on the screen and 19.336 for exactly $\gamma=20$; the margin widths are 0.3233 and 0.3231).
D.5.4 Simplifications
- The inputs are taken to be standardized from the start, and the quadratic terms are not standardized (which is why the stable $\eta$ becomes small). Because the loss is a sum rather than a mean, the stable learning rate depends on $N$.
- Only full-data gradient descent is provided (no minibatches). $b$ is not regularized. The only evaluation is the training accuracy (no validation or cross-validation).
- SMO uses neither shrinking nor a cache of kernel values. The conversion of scores to probabilities (Platt scaling) is not performed. The constant of the polynomial kernel is fixed at 1, and the RBF kernel uses $\sigma_f=1$.
D.5.5 Conditions for instability and the behavior of the simulator
- For $\eta\gt2/L_c$, the loss oscillates or increases. The simulator stops when $\norm{\bm{w}}\gt10^{6}$ or on NaN, and displays the reason (convergence can still occur beyond the guide value; the guide value is a sufficient condition).
- If the data are linearly separable with $\lambda=0$, there is no minimum and $\norm{\bm{w}}$ keeps growing (the simulator displays “none at finite weights”). With data of only one class, $b$ diverges.
- The SVM needs at least one point in each of the two classes, and if this is not satisfied the simulator displays the reason. With the linear kernel, overlapping data, or a large $C$, SMO is slow, and when it reaches the upper limit the simulator displays “this solution is not optimal.” For a large $C$, the duality gap $P-D$ remains rather large even when $m-M$ is small.
- When points with opposite labels lie at the same position (the quadratic coefficient of SMO is 0), the algorithm avoids this with a small value ($10^{-12}$) and still converges (confirmed by the tests).
- Because of the stopping tolerance $\varepsilon=10^{-3}$, the number of support vectors may differ by one from that of the exact dual solution. Example: for the overlapping data with RBF $\gamma=1$ and $C=1$, the screen shows 35 (16 ○, 19 ◇), but one of them is a leftover with $\alpha_n=1.7\times10^{-3}$, and in the exact solution there are 34. $D$, the margin width, and the accuracy agree to the displayed digits. The same thing happens depending on the order in which points are added (if the order is changed in the three-point example of Chapter 11, a leftover of $\alpha_n=2.4\times10^{-4}$ remains, giving three support vectors and a width of 2.001).
- For ill-conditioned problems, the number of SMO iterations changes slightly depending on the environment because of a 1 ulp difference in elementary functions (Gaussian random numbers also pass through them; D.1.3).
D.5.6 How and to what extent the numbers were checked
| Quantity checked | Compared with | Type | Number of tests | Tolerance, etc. |
|---|---|---|---|---|
| Loss, gradient, and one step of gradient descent for ①; $\lambda_{\max}$ and $L_c$ (four kinds of data) | NumPy | independent implementation | 68 | rtol about $10^{-12}$ ($10^{-10}$ for $\lambda_{\max}$) |
| Gradient | central difference | analytical solution | 12 | relative $10^{-7}$ |
| Minimum point (Newton’s method) | SciPy BFGS + Newton’s method | independent implementation | 24 | $L^{*}$ rtol $10^{-10}$, $\bm{w}^{*}$ $10^{-6}$ |
| Detection of the case with no minimum (linearly separable, one class), monotone increase of $\norm{\bm{w}}$, zero data points | analytical properties | analytical solution | 9 | — |
| No overflow of the cross-entropy (such as $a=\pm800$) | direct formula and asymptotic form | analytical solution | 23 | — |
| Kernels and the Gram matrix | NumPy | independent implementation | 7 | $10^{-12}$ |
| SMO solution ($\varepsilon=10^{-9}$, seven cases): dual objective function $D$, $\norm{\bm{w}}^{2}$, box and equality constraints, KKT residual, weak duality, $b$, and $f(\bm{x})$ at eight test points. $D$ at the default on-screen $\varepsilon=10^{-3}$ | dual problem solved with SciPy SLSQP and trust-constr (KKT residual of the reference solution at most $10^{-6}$) | independent implementation | 77 | $D$ rtol $10^{-8}$, KKT residual at most $10^{-8}$, $b$ $10^{-5}$, $f(\bm{x})$ $10^{-4}$, relative difference of $D$ at the default $\varepsilon$ at most $10^{-3}$ |
| Examples that can be calculated by hand (two points, three points, and a soft margin with $P=D=0.32$; the type in Chapter 11, Section 11.4) | hand-calculated values | analytical solution | 14 | rtol $10^{-12}$ |
| Special cases and the iteration upper limit, $D$ not decreasing at each step, the formula for $f(\bm{x})$ | — | analytical solution | 11 | — |
| Reproducibility of the seed | — | — | 16 | — |
| Mean, variance, and radius of the synthetic data, and the number of points in each quadrant | theoretical values | statistical | 11 | 4 standard errors, $\chi^{2}$ (0.1 %) |
| Record of the numbers at the on-screen default values (initial loss $=N\ln 2$, etc.) | — | analytical solution | 3 | — |
The on-screen checks comprised 339 procedures, including the operating procedures in the boxes of Chapters 9–11 (71 of them comparisons against reference values). We also confirmed that there are no console errors in the display immediately after opening the page via file:// (at three widths).
The computations added for the simple view (sim/classifier.easy.js) were checked with 243 Node.js tests, and all succeeded. They were compared with the functions of the computation file and with closed-form expressions (the spacing between the lines of probability 0.1 and 0.9, and the agreement of the margin width of the SVM with the direction in which the road is widest).
D.6 S05 Neural Networks (neural-net)
D.6.1 Corresponding chapters, sections, and tabs
- Chapter 14: Section 14.4 (Simulator 14.1), Section 14.5 (Simulator 14.2). Both use the tab train.
- Chapter 15: Section 15.3 (Simulator 15.1, tab trace), Section 15.4 (Simulator 15.2, tab gradcheck), Section 15.5 (Simulator 15.3, tab train), Section 15.8.
- Tabs:
trace“① Following One Step Numerically,”train“② Watching Training,”gradcheck“③ Gradient Checking.” - Scenes of the simple view (added in December 2026):
learn“Can a network separate points of two colors?” (a small network is trained, and we see the coloring that separates the points of two colors change, together with the thickness of the lines (the magnitudes of the weights)),flow“How does a mistake reach the lines?” (one round of forward propagation → error of the output → backpropagation → update of the weights is viewed repeatedly). The computations use functions of the same computation file as the detailed view (main ones: makeTask, initNet, trainEpoch, forward, gridPredict, lossOnly, trace). The explanation page is neural-net-derivation.html.
D.6.2 What is computed
- A network with one hidden layer and one output: $\bm{a}^{(1)}=\bm{W}^{(1)}\bm{x}+\bm{b}^{(1)}$, $\bm{z}^{(1)}=h(\bm{a}^{(1)})$, $a^{(2)}=\bm{W}^{(2)}\bm{z}^{(1)}+b^{(2)}$, $\hat{y}=\sigma(a^{(2)})$ (classification) or $\hat{y}=a^{(2)}$ (regression). Backward propagation is $$\begin{aligned}\delta^{(2)}&=\hat{y}-y,\\ \bm{\delta}^{(1)}&=h'(\bm{a}^{(1)})\odot\bigl(\bm{W}^{(2)\tp}\delta^{(2)}\bigr),\\ \pdiff{L}{\bm{W}^{(l)}}&=\bm{\delta}^{(l)}\bm{z}^{(l-1)\tp},\qquad \pdiff{L}{\bm{b}^{(l)}}=\bm{\delta}^{(l)}\end{aligned}$$ (with $\bm{z}^{(0)}=\bm{x}$).
- ①: For a 2–2–1 network (tanh hidden layer, sigmoid output, cross-entropy), the simulator displays, in order, the numbers of forward propagation, backward propagation, and the weight update $\bm{w}\leftarrow\bm{w}-\eta\,\partial L/\partial\bm{w}$. The default values are the same as in the hand calculation in Section 15.3 of Chapter 15 ($\bm{x}=(1.0,0.5)^{\tp}$, $y=1$, $\eta=0.5$). No random numbers are used.
- ②: The loss $L$ is the average $(1/\abs{\mathcal{B}})\sum_{n\in\mathcal{B}}\ell_n$ over the minibatch $\mathcal{B}$ plus the weight decay term $(\lambda/2)(\norm{\bm{W}^{(1)}}^{2}+\norm{\bm{W}^{(2)}}^{2})$ (not applied to the biases). For classification, $\ell$ is the cross-entropy (computed in the form $\ln(1+e^{a})-ya$); for regression, $\ell$ is $\tfrac12(\hat{y}-y)^{2}$. Training uses plain stochastic gradient descent. The regression target values are standardized with the mean and standard deviation of the training data (the loss is in standardized units, and the RMSE is displayed in %). The initial values are Xavier for tanh and sigmoid (variance $2/(\text{number of inputs}+\text{number of outputs})$) and He for ReLU ($2/\text{number of inputs}$); the output layer uses Xavier, and the biases are 0. “All 0” can also be selected.
- ③: For all parameters, the gradient from backward propagation is compared with finite differences (central difference and forward difference), and the V shape of the error as a function of the step size $\epsilon$ is plotted. Pass or fail is decided by “the relative error as a vector, $\norm{\bm{g}-\hat{\bm{g}}}/\max(\norm{\bm{g}},\norm{\hat{\bm{g}}})\le10^{-6}$.”
D.6.3 Input ranges, upper limits, and random numbers
- ①: $x_1,x_2$ from −3 to 3 (in steps of 0.1), $y\in\{0,1\}$, $\eta$ from 0.05 to 5 (in steps of 0.05).
- ②: The task is regression (data A) / concentric circles / two moons / XOR; the number of hidden units is 1–16 (default 3); the activation is tanh / ReLU / sigmoid; $\eta$ ranges from $10^{-3}$ to 2.5 (on a logarithmic scale in steps of 0.1 in $\log_{10}\eta$; the right end is $10^{0.4}\approx2.51$, which does not reach the upper limit of 3.16 in the computation file; default 0.10); the minibatch is all / 8 / 1 (default 8); the weight decay $\lambda$ takes nine levels from 0 to 0.1 (default 0); the number of training data points is 5–50 (20) for regression and 40–200 (100) for classification; training runs for up to 5000 epochs. The validation data are 200 points drawn from a separate random number stream.
- ③: $\epsilon$ ranges from $10^{-12}$ to $10^{-1}$ (in steps of $10^{0.25}$ on a logarithmic scale; default $10^{-5}$).
- There are two seeds: the seed for the initial values and the minibatch order, and the data seed (both default to 20261112).
D.6.4 Simplifications
- There is one hidden layer and one output. The only optimization is plain stochastic gradient descent (there is no Adam, momentum, or dropout).
- The regression target values are standardized with the training data. The numbers in the figure of ① are displayed to four digits (the table, to six digits).
- The formulas that generate the classification data (concentric circles, two moons, XOR) differ from those of S04, and the XOR of S05 consists of four groups centered at $(\pm0.5,\pm0.5)$ (the arrangement and labels differ from the hand calculation on $\{0,1\}^{2}$ in Section 14.4 of Chapter 14).
D.6.5 Conditions for instability and the behavior of the simulator
- If $\eta$ is large or the minibatch is small, training diverges. The simulator stops at NaN, ∞, or loss $\gt10^{6}$ and displays the reason. The epoch displayed is the epoch at which the loss exceeded $10^{6}$ (examples: for regression with 8 hidden units, $\eta=1$, and minibatch 1, the loss is $4.2\times10^{21}$ at epoch 1 and training stops; with $\eta=2.5$ and minibatch 8 (with the default 3 hidden units), the training loss is $9.27\times10^{7}$ at epoch 3 and training stops). After divergence, an RMSE of $10^{4}$ or more is displayed in exponent form (e.g., $5.72\times10^{24}$).
- With a sigmoid hidden layer the gradients tend to become small, and with ReLU some units get stuck with output 0. In classification, if the classes can be separated perfectly, the weights keep growing when $\lambda=0$.
- If the initial values are all 0, the symmetry is not broken (with tanh the weights stay at 0 and only the bias $b^{(2)}$ moves).
- If XOR is trained with two hidden units, the default seed, and $\eta=0.1$, training stays at a local solution with an accuracy of 75 % (with four hidden units it reaches 100 %). Being able to represent a function and being able to find it by training are different things (Chapter 14).
- In gradient checking, if $\epsilon$ is too small, rounding errors make the finite difference inaccurate. Gradient components close to 0 can show a large componentwise relative error (example: $4.6\times10^{-6}$ for a component of magnitude $3.8\times10^{-6}$), so the decision is based on the relative error as a vector. For an $\epsilon$ that straddles the kink of ReLU, the finite difference does not become the derivative.
D.6.6 How and to what extent the numbers were checked
| Quantity checked | Compared against | Type | Items | Tolerance, etc. |
|---|---|---|---|---|
| One step of ① (four cases: the default values and other inputs): $a$, $z$, $\hat{y}$, $L$, $\delta$, each gradient, and the weights and loss after the update | Hand-written NumPy calculation and PyTorch automatic differentiation (double precision) | independent implementation | 79 | $10^{-15}$ to $10^{-13}$ |
| Loss and gradients of 32 randomly generated networks (4 activations × 2 outputs × 4 shapes, with weight decay) | PyTorch automatic differentiation | independent implementation | 96 | $10^{-13}$ times the magnitude of the gradient |
| Minibatch stochastic gradient descent for 6 epochs (same data, initial values, and ordering) | NumPy implementation | independent implementation | 8 | $10^{-12}$ |
| Output-layer error $\delta^{(2)}=\hat{y}-y$ (sigmoid + cross-entropy; identity + sum of squares/2) | Central difference of $\partial\ell/\partial a^{(2)}$ | analytical solution | 29 | rtol $10^{-8}$ |
| Gradient checking (12 networks). The error of the central difference is proportional to $\epsilon^{2}$, and that of the forward difference to $\epsilon$ | Central difference | analytical solution | 16 | Relative error of the vector at most $10^{-6}$. With the default weights and $\epsilon=10^{-5}$, the maximum absolute error is $3.10\times10^{-12}$ (the value in Node.js; about $7.9\times10^{-12}$ in Chrome) |
| The weight decay term, a linear map when the activation is the identity, the symmetry of the all-0 initial values, the ordering of the parameters, and detection of divergence | Analytical properties | analytical solution | 6 | — |
| Synthetic data (the true function of data A analytically; the noise, the uniformity of the inputs, the radii of the concentric circles, the XOR labels, and the variance of the initial values statistically) | Theoretical values, KS test | analytical solution / statistical | 15 | 4 standard errors |
| Record of training with the default settings | — | — | 4 | — |
The on-screen checks comprise 174 procedures (19 comparisons), including the operating procedures in the boxes of Chapters 14 and 15. At 390 px, the long formula in “Putting the current numbers into the formula” scrolls horizontally inside its frame (the page does not overflow horizontally).
The computations added for the simple view (sim/neural-net.easy.js) were checked with 395 Node.js tests, and all succeeded. They were compared with the results of calling the functions of the computation file in the same order as ② of the detailed view (bit-for-bit agreement), with the numbers in Sections 15.3 and 15.5 of the main text, and with the fact that the border of the coloring is a straight line when there is one hidden unit.
D.7 S06 Gaussian Processes and Bayesian Optimization (gp-bo)
D.7.1 Corresponding chapters, sections, and tabs
- Chapter 12: Section 12.7 (Simulator 12.1, tab gp), Section 12.6, Section 12.8.
- Chapter 13: Section 13.5 (Simulator 13.1, tab bo), Section 13.8 (Simulator 13.2, tab compare), Section 13.4, Section 13.6.
- Tab
gp“① Gaussian Process Regression,”bo“② Bayesian Optimization,”compare“③ Comparison with Random Search.” - Scenes of the simple view (added in December 2026):
predict“Can we predict the performance where we have not measured?” (from the measured points, the prediction of the performance where it has not been measured (the predictive mean of Gaussian process regression) and the “confidence width” are drawn, and we see that the width shrinks when points are added),search“Can we find the best with only a few experiments?” (with 20 experiments, we compare which of Bayesian optimization (EI) and choosing at random (random search) gets closer to the condition with the highest performance; when the page is opened, both start from the state in which the first 3 experiments (points chosen at random) have already been carried out). The computations use functions of the same computation file as the detailed view (main ones: gpFit, gpPredict, gpPredictOne, observeC, sampleFunctions, boCreate, boStep, boModel, randomRun, recommend, regretCurve, compareSeeds). The explanation page is gp-bo-derivation.html.
D.7.2 What is computed
- The objective function is the data C of Chapter 12 (synthetic data for teaching purposes; dopant amount $x\in[0,10]$ mol%, $y=\log_{10}(\sigma_{\mathrm{ion}}/\mathrm{S\,cm^{-1}})$, observation noise standard deviation 0.05). The true global maximum is at $x=7.000$, $y=-3.4000$, and the local maximum is at $x=2.200$, $y=-3.99988$.
- ①: RBF kernel $k(x,x')=\sigma_f^{2}\exp(-(x-x')^{2}/(2\ell^{2}))$, $\bm{K}_y=\bm{K}+\sigma^{2}\bm{I}$. The mean function is a constant $m$ (by default the mean $\bar{y}$ of the observed values), and $$\begin{aligned}\mu_*&=m+\bm{k}_*^{\tp}\bm{a},\quad \bm{a}=\bm{K}_y^{-1}(\bm{y}-m\bm{1}),\\ \sigma_*^{2}&=k(x_*,x_*)-\bm{k}_*^{\tp}\bm{K}_y^{-1}\bm{k}_*,\end{aligned}$$ $$\begin{aligned}&\ln p(\bm{y}\mid\bm{\theta})\\ &=-\tfrac12(\bm{y}-m\bm{1})^{\tp}\bm{K}_y^{-1}(\bm{y}-m\bm{1})\\ &\quad-\tfrac12\ln\abs{\bm{K}_y}-\tfrac N2\ln 2\pi\end{aligned}$$ are computed from the Cholesky decomposition of $\bm{K}_y$ (if it is not numerically positive definite, a small value, the jitter, is added to the diagonal and the computation is retried, and that amount is displayed) together with forward and backward substitution (the inverse matrix is never formed). The vector of dual coefficients is displayed on screen in the same bold $\bm{a}$ as in Chapters 10 and 12. The band $\pm2\sigma_*$ for the latent function and the band $\pm2\sqrt{\sigma_*^{2}+\sigma^{2}}$ for the observed values are drawn separately. If rounding makes $\sigma_*^{2}\lt0$, it is clipped to 0 and the number of such cases is displayed. By grid search, $\ell$ (41 points) or $\ell,\sigma_f,\sigma$ ($41\times13\times21=11193$ combinations) can be chosen so as to maximize the log marginal likelihood.
- ②: The acquisition function is evaluated at 401 points (in steps of 0.025 mol%), and the point with the maximum value is observed next (if values are equal, the one with the smaller $x$). For maximization, $$\begin{aligned}\mathrm{EI}&=(\mu_*-f_{\mathrm{best}}-\xi)\,\Phi(z)+\sigma_*\Normal(z\mid0,1),\\ z&=\frac{\mu_*-f_{\mathrm{best}}-\xi}{\sigma_*},\\ \mathrm{PI}&=\Phi(z),\qquad \mathrm{UCB}=\mu_*+\kappa\sigma_*\end{aligned}$$ (for $\sigma_*=0$, $\mathrm{EI}=\max(\mu_*-f_{\mathrm{best}}-\xi,0)$); for minimization (minimizing $-y$), LCB $=\mu_*-\kappa\sigma_*$ and the EI with the sign changed are used. For $f_{\mathrm{best}}$ one can choose either the best observed value or the best posterior mean at the observation points.
- ③: With the same budget, Bayesian optimization, random search, and an equally spaced grid are repeated, and the median and interquartile range of the simple regret $r_n=y_{\max}-y(\hat{x}_n)$ are drawn ($\hat{x}_n$ is the point with the largest observed value up to the $n$th evaluation, and $y(\hat{x}_n)$ is the true value at that point). For the grid, for each number of evaluations $n$, we measure the grid that one would place for a budget of $n$, namely $x_k=10(k-\tfrac12)/n$.
D.7.3 Input ranges, upper limits, and random numbers
- ①: Up to 40 observations (the “example 8 points” are $x=0.4,1.6,2.8,4.0,5.2,6.4,8.2,9.4$ mol%), $\ell$ from 0.1 to 10 mol% (logarithmic scale; default 1.00), $\sigma_f$ from 0.05 to 3 (0.80), the model’s $\sigma$ from 0.005 to 0.5 (logarithmic scale; default 0.0500; separate from the noise 0.05 of the synthetic data), the constant $m$ from −6 to −3.
- ②: Initial points 1–10 (3; uniform random numbers), budget 2–40 (20), $\xi$ from 0 to 0.5, $\kappa$ from 0 to 5 (2.0). With “Choose $\ell$ by marginal likelihood each time,” the value is chosen from 25 points in $\ell\in[0.2,5]$. The automatic run proceeds only when the button is pressed.
- ③: Budget 5–40 (20), repetitions 10–200 (200). The computation is split into chunks of 12 ms per frame (with the default 200 repetitions × 20 evaluations, about 0.4 s).
- The default seed is 20261112. For repetition $r$ in ③, seed $+r$ is used for Bayesian optimization, seed $+100000+r$ for random search, and seed $+200000+r$ for the grid noise. Some of the figures in the text were computed separately with NumPy random numbers, and their random-number sequences differ from those of the simulator (mulberry32) (this is noted in Chapter 13).
D.7.4 Simplifications
- The input is one-dimensional. The mean function is a constant, and in the marginal likelihood $\bar{y}$ is regarded as a known value.
- The maximization of the acquisition function is done on a grid of 401 points. The hyperparameters are either fixed or chosen only by grid search (no gradient method or prior distribution is used). The recommended point is the point with the largest observed value.
- The definitions of $\sigma_f$, $\sigma$, and $f_{\mathrm{best}}$ in ③ are fixed. The grid is a different arrangement for each $n$.
D.7.5 Conditions for instability and the behavior of the simulator
- When $\sigma$ is small and $\ell$ is large, or when observations at the same $x$ coincide, $\bm{K}_y$ becomes nearly singular. The simulator adds jitter, continues the computation, and writes that amount on the screen (the tests confirm that jitter is added when $\sigma=0$ and there are two observations at the same $x$).
- With few observations, the maximum of the marginal likelihood may be flat or stick to the end of the range (in the example 8 points, $\sigma$ sticks to the lower end 0.005).
- When $\ell$ is long and $\sigma$ is small, EI and PI become 0 everywhere. In that case the left end of the grid is chosen, and a warning is shown in red.
- The cumulative distribution function $\Phi(z)$ of the standard Gaussian distribution in the shared library has a relative error of about 0.4 % in the tail beyond $z\approx-20$, and the EI there (about $10^{-123}$) differs from the mpmath value by 3 % in relative terms. This does not affect the numbers shown on the screen, but in settings where EI is below $10^{-100}$ everywhere ($\ell=10$ with small $\sigma$, for example), the chosen point is determined by rounding. When the 1331 points chosen by Bayesian optimization in the comparison ③ were recomputed with NumPy, only 6 differed (4 were differences in how a value was chosen among equal values, because the marginal likelihood used to choose $\ell$ was flat; 2 were cases where EI was below $10^{-300}$ at all points).
- Because of the observation noise, the simple regret may increase even as the number of evaluations increases (in the default ②, at the 10th and 16th evaluations).
- If we fix $\ell=10$, Bayesian optimization loses to random search (with budget 30 and 200 repetitions, medians 0.0488 versus 0.0186). If $\ell$ is chosen by the marginal likelihood each time, it does not fall behind random search in the median (with budget 20 and 200 repetitions, 0.00165 versus 0.0312; comparing the same repetitions one by one, it loses in about 20 % of them).
- For NaN and ∞, the computation stops and the reason is displayed.
D.7.6 How and to what extent the numbers were checked
| Quantity checked | Compared with | Type | Number of tests | Tolerance, etc. |
|---|---|---|---|---|
| The 11 points of data C, and the positions and values of the true maximum and the local maximum | SciPy minimize_scalar | independent implementation | 7 | position $2\times10^{-7}$, value $10^{-13}$ |
| Predictive mean and variance, posterior covariance, log marginal likelihood and its three terms (9 cases). Hand-calculation formulas for one and two observations, zero observations, return to the prior far away, interpolation as $\sigma\to0$ | NumPy solve and slogdet without the Cholesky decomposition, SciPy multivariate_normal, explicit 2 × 2 inverse matrix | independent implementation, analytical solution | 107 | $10^{-10}$ (hand-calculation formulas $10^{-12}$ to $10^{-14}$) |
| Jitter, rounding of the variance, input validation | — | analytical solution | 8 | — |
| The curve of the log marginal likelihood versus $\ell$ and the maximum of the grid search | NumPy | independent implementation | 8 | $10^{-10}$ to $10^{-12}$ |
| EI and PI (12 cases), the limit $\sigma_*\to0$, monotonicity, the formulas for UCB and LCB | numerical integration with mpmath (50 digits) | independent implementation, analytical solution | 37 | EI rtol $10^{-11}$, PI $10^{-12}$ |
| Values of the acquisition function on the 401-point grid and the chosen points (7 cases) | NumPy | independent implementation | 21 | $f_{\mathrm{best}}$ rtol $10^{-12}$ |
| Correspondence between maximization and minimization: sequences of observation points for 3 acquisition functions × 2 kinds of $f_{\mathrm{best}}$ × $\ell$ fixed/chosen × 4 seeds | the problem with the sign of the objective function reversed | analytical solution | 14 | Exact agreement in all 15 cases. LCB$(-y)=-$UCB$(y)$ agrees bit for bit |
| Reproducibility of the seed, definition of the simple regret | — | — | 9 | — |
| Median and interquartile range | NumPy quantile | independent implementation | 2 | — |
| Mean and variance of the noise of the synthetic data, uniformity of the $x$ of random search, covariance of 4000 samples from the prior and posterior distributions (15 components) | theoretical values, KS test | statistical | 8 | 4 standard errors, $D\lt1.95/\sqrt{n}$ |
The results of the comparison in ③ (the simple regret of Bayesian optimization and random search) are recorded as measured values over 200 repetitions with a fixed seed, and no pass/fail criterion is applied (the quartiles agreed with a recomputation using NumPy’s quantile). SciPy’s quad was not used as the reference for EI because it gave a relative error of 2 % in the tail at $z\approx-12$. The on-screen checks comprise 158 steps (24 of them comparisons), including the operating procedures in the boxes of Chapters 12 and 13.
The computations added for the simple view (sim/gp-bo.easy.js) were checked with 121 Node.js tests, and all succeeded. They were compared with the functions of the computation file, the numbers given in the chapters, and closed-form expressions.
D.8 S07 Latent Variables (latent)
D.8.1 Corresponding chapters, sections, and tabs
- Chapter 17: Section 17.5 (Simulator 17.1, tab em), Section 17.8 (Simulator 17.2, tab em).
- Chapter 18: Section 18.2 (Simulator 18.1, tab pca), Section 18.6 (Simulator 18.2, tab pca).
- Tab
em: “① k-means and EM”;pca: “② PCA.” - Scenes of the simple view (added in December 2026):
group“Can a cloud of points be sorted into groups automatically?” (we see the grouping of a cloud of points by the k-means method progress with each iteration),axis“In which direction does the cloud of points spread out the most?” (a two-dimensional cloud of points is projected onto a line as a shadow, and the direction of the line is rotated to look for the direction in which the spread (variance) of the shadow is largest (the first principal component)). The computations use functions of the same computation file as the detailed view (main ones: makeData, initParams, makeRun, kmeansAssign, makePCA2D, transform2D, pca, cov2, projStats, axisAngle). The explanation page is latent-derivation.html.
D.8.2 What is computed
- ① (EM algorithm for a Gaussian mixture, two dimensions): The E step computes the responsibilities $$\gamma_{nk}=\frac{\pi_k\Normal(\bm{x}_n\mid\bm{\mu}_k,\bm{\Sigma}_k)}{\sum_{j}\pi_j\Normal(\bm{x}_n\mid\bm{\mu}_j,\bm{\Sigma}_j)}$$ and the M step updates $N_k=\sum_n\gamma_{nk}$, $\pi_k=N_k/N$, $\bm{\mu}_k$, and $\bm{\Sigma}_k$; the simulator plots the progression of the log-likelihood $\ln p(\bm{X}\mid\bm{\theta})$. The Gaussian density is computed with a 2 × 2 Cholesky decomposition. When the “variance floor” is on, the eigenvalues of $\bm{\Sigma}_k$ in the M step are raised to $\max(\lambda,c)$ (the eigenvectors are left unchanged; since this is the maximum-likelihood solution under the constraint “eigenvalues $\ge c$” with the mean held fixed, the property that the log-likelihood does not decrease is preserved). Convergence is declared when the increase in the log-likelihood is $\le10^{-10}(\abs{\ln p}+1)$.
- ① (k-means): assignment to the nearest mean and update of the means. The vertical axis shows the objective function $J$ (a quantity different from the log-likelihood).
- ② (two dimensions): For the sample covariance matrix $\bm{S}$ (with the factor $1/N$), the simulator plots, as functions of the angle, the variance of the projection onto the direction $\bm{u}$, $\bm{u}^{\tp}\bm{S}\bm{u}$, and the reconstruction error $\tr\bm{S}-\bm{u}^{\tp}\bm{S}\bm{u}$, and finds the principal axis.
- ② (spectra, 60 spectra × 200 points): From the SVD of the centered data, it obtains the eigenvalues $\lambda_i=s_i^{2}/N$, the loadings, and the scores, and displays the reconstruction with $k$ components and the mean reconstruction error (= the sum of the discarded eigenvalues). As a guide to the range of the eigenvalues for pure noise, it draws a band $\sigma^{2}(\sqrt{D}\mp\sqrt{N})^{2}/N$ (an approximation for large matrices).
D.8.3 Input ranges, upper limits, and random numbers
- ①: five data sets (separated / overlapping / elongated / different sizes / degenerate example; synthetic data for teaching purposes; dimensionless), $K$ from 1 to 6 (default 2), $N$ from 10 to 300 (150), variance floor $c$ from $10^{-4}$ to 1 (0.010), and up to 1000 iterations.
- ②: in two dimensions, $N$ from 2 to 300 (100), a scale factor from 0.1 to 10 that changes the unit of $x_2$, and a switch for standardization. For the spectra, 2 or 3 pure components, a noise standard deviation from 0 to 0.1 (0.020), and a number of reconstruction components $k$ from 0 to 10.
- There are two seeds: the data seed (default 20261113) and the initial-value seed (default 1; it selects the data points used as the initial means). For the initial values, the first $K$ points of the permuted data points are used as the means, with $\bm{\Sigma}_k=(\tr\bm{S}/2)\bm{I}$ and $\pi_k=1/K$.
D.8.4 Simplifications
- ① is two-dimensional only. The initial values are randomly chosen data points (k-means++ and the like are not used). $K$ is chosen by hand.
- In the degenerate example, to make the degeneracy reliably visible, the initial mean of the last component is placed at an isolated point (stated explicitly on the screen). Degeneracy does not occur for every initial value.
- The spectra include neither baselines nor peak shifts, and the noise is uniform Gaussian noise.
D.8.5 Conditions for instability and the behavior of the simulator
- Without the variance floor, degeneration onto a single point (or a line) can make the log-likelihood grow without an upper limit. An update that would make the smallest eigenvalue of a covariance less than $10^{-10}$ is not adopted, and the simulator displays “stopped (degenerate)” together with the reason (in the degenerate example with $K=2$, it stops after −462.35 → −307.53 → −301.11).
- For a component whose sum of responsibilities $N_k$ is almost 0, the previous values are kept and a caution is displayed (the same applies to empty components in k-means). Local minima exist (the result changes with the initial-value seed).
- In two-dimensional PCA, the principal axis is hard to determine when the two eigenvalues are nearly equal. For $N=2$, the second eigenvalue is 0 (a caution is displayed).
- The values on the screen and those from Node.js were treated as agreeing to the fifth digit, because of a 1 ulp difference in elementary functions (Gaussian random numbers also pass through them).
D.8.6 How and to what extent the numbers were checked
For the reference calculations, the data generated by the simulator’s calculation file were passed as they were to NumPy and SciPy (so that the comparison uses the same data and the same initial values).
| Quantity checked | Compared against | Type | Number of tests | Tolerance, etc. |
|---|---|---|---|---|
| Logarithm of the 2 × 2 Gaussian density | SciPy’s multivariate_normal | independent implementation | 16 | rtol $10^{-13}$ |
| Responsibilities in the E step and the initial log-likelihood; $\bm{\mu}_k,\bm{\Sigma}_k,\pi_k,N_k$ in the M step; the sequence of log-likelihoods up to convergence and the number of iterations; the converged values (five cases) | An independent NumPy implementation | independent implementation | 60 | $10^{-11}$–$10^{-13}$; log-likelihood sequence $10^{-9}$; number of iterations ±1; converged values $\pi$ $10^{-7}$, $\bm{\mu}$ $10^{-6}$ |
| Variance floor (raising the eigenvalues) | NumPy’s eigh | independent implementation | 4 | $10^{-12}$ |
| The log-likelihood of EM does not decrease (5 data sets × 5 values of $K$ × 5 seeds × 3 floors = 375 cases) | — | analytical solution | 1 | within rounding of relative $10^{-12}$ |
| $J$ and the means in k-means; $J$ does not increase in either half step; empty components | NumPy’s Lloyd algorithm | independent implementation, analytical solution | 12 | rtol $10^{-12}$ |
| Degeneracy: without the floor the run stops and keeps a finite value; with the floor it converges; and the converged value increases as $c$ is made smaller | — | analytical solution | 6 | — |
| Values of the first iteration with the default settings (for the hand calculation in Chapter 17) | NumPy | independent implementation | 3 | $10^{-12}$–$10^{-13}$ |
| Two-dimensional PCA: the eigenvalues from the SVD equal those of the covariance matrix; the angle of the principal axis; $\bm{u}^{\tp}\bm{S}\bm{u}$ in 24 directions; at the principal axis the reconstruction error equals $\lambda_2$; $1\pm r$ after standardization; $\lambda_2=0$ for $N=2$ | NumPy’s eigh, the Jacobi algorithm | independent implementation, analytical solution | 43 | angle $10^{-9}$; $10^{-8}$–$10^{-12}$ |
| PCA of the spectra: the eigenvalues (including the 200 × 200 Jacobi algorithm); for $k=0$–7 the reconstruction error equals the sum of the discarded eigenvalues; orthonormality of the loadings and agreement up to sign; the reconstruction does not change when the sign is flipped | NumPy | independent implementation, analytical solution | 46 | rtol $10^{-10}$ |
| Reproducibility with the seed | — | — | 7 | — |
| Synthetic data (covariance of a two-dimensional point cloud of 40,000 points, component means, mean of Dirichlet random numbers, mean and maximum of the eigenvalues for pure noise) | Theoretical values | statistical | 10 | 4 standard errors (±20 % for the maximum eigenvalue) |
The checks on the screen comprise 154 steps, including the procedures in the boxes of Chapters 17 and 18 (38 of them cross-checks).
The computations added for the simple view (sim/latent.easy.js) were checked with 754 Node.js tests, and all succeeded. They were compared with the functions of the computation file and with simple computations rewritten within the tests (the nearest representative point, the objective function $J$, the closed-form expression for the eigenvalues of a 2×2 matrix, and the maximum on a fine grid of angles).
D.9 S08 Approximate Inference and MCMC (inference-mcmc)
D.9.1 Corresponding chapters, sections, and tabs
- Chapter 20: Section 20.2 (Simulator 20.1, tab approx), Section 20.7 (Simulator 20.2, tab approx).
- Chapter 21: Section 21.8 (Simulator 21.1, tab mh), Section 21.10 (Simulator 21.2, tab mh).
- Tab
approx: “① Comparing Approximate Distributions”;mh: “② Metropolis–Hastings Algorithm.” - Scenes of the simple view (added in December 2026):
walk“Can walking around copy the shape of the hills?” (we see the histogram of the footprints of a traveler walking by the Metropolis–Hastings method approach the shape of the target distribution, comparing three step sizes (widths of the proposal distribution)),trace“What if you trace a two-humped shape with one bell?” (a distribution with two humps is approximated by a single Gaussian distribution, and we see the difference between minimizing $\KL(q\,\|\,p)$ and minimizing $\KL(p\,\|\,q)$ (matching the moments)). The computations use functions of the same computation file as the detailed view (main ones: makeTarget, mhInit, mhStep, minKLqp, momentMatch, qTerms, klPQ). The explanation page is inference-mcmc-derivation.html.
D.9.2 What is computed
- The targets are one-dimensional, and there are three kinds that can be normalized by numerical integration on a grid: a skewed unimodal distribution $\tilde p(x)=x^{a-1}(1-x)^{b-1}$ (Beta type, $Z=B(a,b)$), a bimodal distribution $\tilde p(x)=w\,e^{-(x+d/2)^{2}/2}+(1-w)\,e^{-(x-d/2)^{2}/2}$, and a double well $\tilde p(x)=\exp[-b(x^{2}-1)^{2}]$ ($b=E_b/(k_{\mathrm B}T)$). Here $p(x)=\tilde p(x)/Z$ ($Z$ corresponds to the marginal likelihood $p(\data)$ of Chapter 20).
- ①: With the approximating distribution $q(x)=\Normal(x\mid m,s^{2})$, the simulator compares the Laplace approximation (mode $x^{*}$, curvature $\Lambda=-(\dd^{2}/\dd x^{2})\ln\tilde p\,\vert_{x^{*}}$, $q=\Normal(x\mid x^{*},\Lambda^{-1})$, $\ln Z\approx\ln\tilde p(x^{*})+\tfrac12\ln(2\pi/\Lambda)$; the screen also displays $\Lambda$), the Gaussian distribution that minimizes $\KL(q\,\|\,p)$ (Nelder–Mead method; the destination depends on the initial value), and the Gaussian distribution that minimizes $\KL(p\,\|\,q)$ (matching of the mean and variance), and displays the KL divergence in both directions, the mean and variance, and $\ELBO(q)=\Ex_q[\ln\tilde p]-\Ex_q[\ln q]$ together with $\ln Z=\ELBO+\KL(q\,\|\,p)$. The integrals use Simpson’s rule with 4000 intervals (for the Beta type, with the change of variables $x=u^{3}(10-15u+6u^{2})$), and the expectations over $q$ are computed on $m\pm12s$ with 2000 intervals.
- ②: The Metropolis–Hastings algorithm with the Gaussian random-walk proposal $x'=x+s\varepsilon$ (acceptance probability $\min(1,\tilde p(x')/\tilde p(x))$; accept when $u\lt\min(1,r)$). One to four chains. It displays the acceptance rate (shown to three significant digits), the integrated autocorrelation time $\tau_{\mathrm{int}}=1+2\sum_{k=1}^{k_c}\rho_k$ (the cutoff $k_c$ is Sokal’s automatic window; the screen also shows it as $\tau_{\mathrm{int}}$, a quantity distinct from the temperature $\tau$ of Chapter 26), the effective sample size $S/\tau_{\mathrm{int}}$, the Monte Carlo standard error of the mean, and the split-$\hat{R}$ (each chain divided into its first and second halves; no rank normalization). The autocorrelation is computed by FFT. Inside the collapsible panel, the transition matrix of the Metropolis algorithm for a three-state discrete distribution is displayed as fractions.
D.9.3 Input ranges, upper limits, and random numbers
- ① (no random numbers): Beta $a,b$ from 1.5 to 20 (default 3, 9); for the bimodal distribution, the left weight $w$ from 0.05 to 0.95 (0.60) and the separation $d$ from 0 to 8 (6.0); for the double well, the barrier $b$ from 0.25 to 15 (3.00).
- ②: proposal width $s$ from 0.01 to 10 (logarithmic scale; default 0.300), 1 to 4 chains (4), initial values scattered / all at the same point, burn-in 0 / 10 / 25 / 50 % (10 %), and up to 20,000 steps per chain. The default target is the double well with $b=2$.
- The default seed is 20261112. Chain $k$ (0–3) uses the random-number sequence of seed $+7919k$, drawing one number at a time in the order $\varepsilon$ → $u$ in each step. Even if the number of chains is changed, the sequence of chain 1 stays the same.
D.9.4 Simplifications
- Only one-dimensional targets for which $Z$ can be obtained by numerical integration on a grid. $q$ is only a one-dimensional Gaussian distribution.
- For a Beta-type target, a Gaussian $q$ puts probability on $x\lt0$ and $x\gt1$, so $\KL(q\,\|\,p)=\infty$. Therefore, for the minimization of $\KL(q\,\|\,p)$ and the ELBO bar, a “Gaussian truncated to $0\lt x\lt1$ and renormalized” is used, and the table lists both ∞ and the truncated value ($\KL(p\,\|\,q)$ and the Laplace approximation are not truncated).
- MCMC uses only the random-walk proposal. $\hat{R}$ is the split-$\hat{R}$ without rank normalization.
D.9.5 Conditions for instability and the behavior of the simulator
- The minimization of $\KL(q\,\|\,p)$ has local minima. If the Nelder–Mead method does not converge within 4000 iterations, the simulator says so. When the Beta $a,b$ are close to 1.5, the Laplace approximation is far off.
- If a chain is short, the cutoff $k_c$ reaches half the series length and the simulator displays “series too short” ($\tau_{\mathrm{int}}$, the effective sample size, and $\hat{R}$ are not reliable). A proposal outside the support is always rejected.
- If the barrier is high, a chain cannot leave one of the wells. In the barrier example (double well $b=12$, $s=0.3$, 4 chains, 2000 steps), none of the four chains leaves the well it started in, and $\hat{R}=9.898$. When the initial values are set to “All at the same point,” $\hat{R}=1.003$ yet the overall mean is −0.98 (the true value is 0), so even $\hat{R}\approx1$ does not guarantee convergence. In this case the “Mean over all chains ± MCSE” on the screen (−0.982 ± 0.0025) is about 400 times the MCSE away from the true value 0. The MCSE represents only the scatter within the range the chains visited, and does not include the bias due to the well that was not visited.
- For NaN or ∞, the computation is stopped and the reason is displayed.
D.9.6 How and to what extent the numbers were checked
| Quantity checked | Compared against | Type | Number of tests | Tolerance, etc. |
|---|---|---|---|---|
| $\ln Z$, mean, variance, and entropy of the targets (15 targets) | SciPy’s quad; analytical solutions ($\ln B(a,b)$; for the double well, a closed form in terms of modified Bessel functions) | independent implementation, analytical solution | 71 | atol $10^{-10}$–$10^{-9}$ (variance rtol $10^{-9}$) |
| Mode, curvature $\Lambda$, and the approximation of $\ln Z$ for the Laplace approximation; KL in both directions; ELBO (for the Beta type, also with the truncated $q$) | SciPy | independent implementation, analytical solution | 168 | mode atol $10^{-7}$, $\Lambda$ rtol $10^{-7}$, KL and ELBO atol $10^{-8}$ |
| The minimum of $\KL(p\,\|\,q)$ = matching of the mean and variance (it increases in the neighborhood) | SciPy | independent implementation, analytical solution | 66 | atol $10^{-8}$ |
| The minimum of $\KL(q\,\|\,p)$ (for each initial value) | SciPy’s Nelder–Mead + BFGS | independent implementation | 62 | KL atol $10^{-8}$, $m,s$ $2\times10^{-4}$ |
| KL in both directions and ELBO for hand-chosen $q$ (27 of them); $\ELBO+\KL=\ln Z$, $\KL\ge0$, $\ELBO\le\ln Z$ | SciPy’s quad | independent implementation, analytical solution | 186 | atol $10^{-8}$ (identities $10^{-12}$) |
| Transition matrix, stationary distribution, and detailed balance of the three-state Metropolis algorithm | Values computed exactly with fractions | analytical solution | 37 | $2\times10^{-16}$, $10^{-15}$ |
| Autocorrelation function (FFT), integrated autocorrelation time and window, split-$\hat{R}$ and its $W$ and $B$ | Direct sums in NumPy, Sokal’s window written in Python, a different implementation in a shared library | independent implementation | 37 | $10^{-10}$–$10^{-12}$ |
| Acceptance rule, rejection of proposals outside the support, reproducibility with the seed | — | analytical solution | 6 | — |
| Reproduction of the barrier example ($b=12$): the chains do not leave the wells, $\hat{R}=9.898$, $\tau_{\mathrm{int}}\lt10$, and $\hat{R}=1.003$ from the same point | Recorded values | — | 4 | — |
| Invariance: the distribution does not change when 3000 points drawn exactly from the target are advanced 25 steps from the starting points (4 targets) | KS test, $\chi^{2}$ test | statistical | 12 | $D\lt1.95/\sqrt{n}$, upper 0.1 %; first acceptance rate within 4 standard errors |
| Mean and variance of one long chain | True values | statistical | 6 | Within 4 times the Monte Carlo standard error |
| Record of the computation time | — | — | 1 | — |
The estimate of the integrated autocorrelation time was recorded alongside the theoretical value $(1+\phi)/(1-\phi)$ for an AR(1) sequence (for $\phi=0.9$, estimated 14.06 versus theoretical 19.0), but this is a reference for comparing estimators and not a pass/fail test. The checks on the screen comprise 128 steps, including the procedures in the boxes of Chapters 20 and 21 (29 of them cross-checks).
The computations added for the simple view (sim/inference-mcmc.easy.js) were checked with 90 Node.js tests, and all succeeded. They were compared with the functions of the computation file, closed-form expressions (the cumulative distribution function of the Gaussian distribution, the probabilities of the mixture distribution), and the numbers of Example 21.6 in Chapter 21.
D.10 S09 Sequence Models (hmm)
D.10.1 Corresponding chapters, sections, and tabs
- Chapter 22: Section 22.6 (Simulator 22.1, tab hmm), Section 22.8 (Simulator 22.2, hand-calculation mode of tab hmm:
?embed=1&only=hmm&mode=hand), Section 22.9 (Simulator 22.3, tab kalman). - Tab
hmm, “① Hidden Markov model” (display: generated sequence / hand calculation with $T=3$), andkalman, “② Kalman filter.” - Scenes of the simple view (added in December 2026):
guess“Is the furnace normal or degraded right now?” (the hidden state of a furnace (normal or degraded) is inferred from a sequence of sensor observations with a hidden Markov model),track“Can a wobbly scale tell your true weight?” (the movement of the true body weight is followed with a Kalman filter from the records of a wobbly scale). The computations use functions of the same computation file as the detailed view (main ones: sampleHMM, analyze, forwardBackwardScaled, sampleRW, kalman, kalmanSummary, kalmanSteady, missingMask). The explanation page is hmm-derivation.html.
D.10.2 What is computed
- ①: Two hidden states (1 = normal, 2 = degraded), the initial distribution $\pi_i$, the transition matrix $A_{ij}=p(z_t=j\mid z_{t-1}=i)$, and the emission probability $B_{jv}$ (three discrete values: low, medium, high) or a Gaussian output (mean 0 for normal, mean $\Delta$ for degraded, standard deviation 1). The scaled forward computation $$\begin{aligned}c_t&=p(x_t\mid x_{1:t-1}),\\ \hat\alpha_t(j)&=p(z_t=j\mid x_{1:t}),\\ \ln p(x_{1:T})&=\sum_{t=1}^{T}\ln c_t\end{aligned}$$ gives the filtering and the likelihood; the backward computation and $\gamma_t=\hat\alpha_t\hat\beta_t$ give the smoothing; and the Viterbi algorithm carried out with logarithms ($\omega_t(j)=\max_{z_{1:t-1}}p(x_{1:t},z_{1:t-1},z_t=j)$, with ties broken in favor of the state with the smaller number) gives the most probable sequence of states. A version computed in the logarithmic domain is calculated at the same time, and its difference from the scaled version is displayed.
- In hand-calculation mode ($T=3$), the simulator lays out the unnormalized $\alpha_t(j)=p(x_{1:t},z_t=j)$, $\beta_t(j)=p(x_{t+1:T}\mid z_t=j)$, $\gamma_t$, $\omega_t$, the backpointer $\psi_t$, and a table of the full enumeration of the eight state sequences.
- ②: The Kalman filter for a one-dimensional random walk $z_t=z_{t-1}+\sqrt{q}\,\varepsilon_t$ with observation $x_t=z_t+\sqrt{r}\,\eta_t$: $$\begin{aligned}P_{t\mid t-1}&=P_{t-1}+q\quad(t\ge2),\\ K_t&=\frac{P_{t\mid t-1}}{P_{t\mid t-1}+r},\\ \mu_t&=\mu_{t\mid t-1}+K_t(x_t-\mu_{t\mid t-1}),\\ P_t&=(1-K_t)P_{t\mid t-1}.\end{aligned}$$ The convention is that the prediction at $t=1$ is $\mu_{1\mid0}=\mu_0=0$, $P_{1\mid0}=P_0=1$ ($q$ is not added). At a time step where the observation is missing, no update is made and $P_t$ grows by $q$ each step. The steady-state values $K_\infty$ and $P_\infty$ are also displayed.
D.10.3 Input ranges, upper limits, and random numbers
- ①: $\pi_1$ 0–1 (default 0.95), $A_{11}$ 0–1 (0.97), $A_{22}$ 0–1 (0.95), the separation of the output distributions $s$ 0–1 (0.70; $B_{1\cdot}=((1+s)/3,1/3,(1-s)/3)$, $B_{2\cdot}=((1-s)/3,1/3,(1+s)/3)$), $\Delta$ of the Gaussian output 0–4 (1.5), and sequence length $T$ 10–200 (100).
- ②: The data’s $q$ 0.001–1 (0.200), $r$ 0.01–4 (1.00), $T$ 10–200 (100), and missing observations (for $T=100$, time steps 31–45 and 71–80). The filter’s $q,r$ can be set separately from the data’s.
- The default seed is 20261112 (synthetic data for teaching purposes; dimensionless). At each time step, random numbers are used in the order state, then observation. When a parameter is changed, the sequence is regenerated with the same seed.
D.10.4 Simplifications
- There are two states, and $A$ and $B$ do not depend on the time step. The parameters are treated as known, and learning (the Baum–Welch algorithm) is not covered. The estimation uses the same parameters as the data generation (only for the Kalman filter can $q,r$ be set separately). The standard deviation of the Gaussian output is fixed at 1.
- The Kalman filter covers only the one-dimensional random walk, and there is no smoothing (RTS). $\mu_0=0$ and $P_0=1$ are fixed.
D.10.5 Conditions for instability and the behavior of the simulator
- The unnormalized $\alpha$ underflows to 0 at $T=2000$ (confirmed in the tests; at $T=200$ it is $10^{-91}$ to $10^{-128}$ and does not yet underflow). The simulator computes with the scaled version and the logarithmic version, so this problem does not occur.
- If a zero-probability transition and a zero-probability output coincide so that the probability of the observation sequence becomes 0, the simulator displays the reason and stops (this can be reproduced in hand-calculation mode with $\pi_1=0$, $A_{22}=1$, $B_{2,\text{low}}=0$, $x_1=$ low).
- For $s=0$ or $\Delta=0$ there are many ties, and the Viterbi algorithm chooses the state with the smaller number.
- If the filter’s $q$ is made too much smaller than the true value, the coverage of the $\pm2\sqrt{P_t}$ band drops sharply (43.0 % for the filter’s $q=0.01$ against the data’s $q=0.2$).
D.10.6 How and to what extent the numbers were checked
| Quantity checked | Compared with | Type | Count | Tolerance, etc. |
|---|---|---|---|---|
| $\alpha,\beta,\gamma,p(x_{1:3})$, $\omega$, and the Viterbi path for the two hand-calculation examples | NumPy and the full enumeration of the eight sequences | full enumeration, independent implementation | 37 | rtol $10^{-13}$ to $10^{-15}$ |
| Eight short sequences ($T\le8$; discrete and Gaussian, cases with 0 in $A$ or $\pi$, and $s=1$): likelihood and $\gamma$ of the scaled and logarithmic versions, and Viterbi | Full enumeration in Python, and SciPy’s logarithmic-domain computation | full enumeration, independent implementation | 80 | rtol $10^{-13}$ |
| Long sequences ($T=200$, 2000): likelihood, $\gamma$, and the Viterbi log probability | Logarithmic-domain computation with SciPy’s logsumexp | independent implementation | 42 | likelihood rtol $10^{-12}$, $\gamma$ $2.5\times10^{-13}\cdot T$ |
| Boundaries and anomalies (stopping for an observation sequence of probability 0, $\gamma$ equal to the prior marginal distribution at $s=0$, $\Delta=30$, ties) | Analytical values | analytical solution | 10 | — |
| Kalman filter: sequential computation, $\mu_t,P_t$, steady-state values, $K_t\to K_\infty$ after 4000 steps, and $P$ growing by $q$ per step during missing observations | NumPy’s sequential computation, conditioning of the joint Gaussian distribution (NumPy’s solve), and closed-form expressions | independent implementation, analytical solution | 95 | sequential $10^{-12}$, conditioning rtol $10^{-9}$, steady-state values rtol $10^{-12}$ |
| Reproducibility of the seed. The sequence generated with the on-screen defaults ($\pi_1=0.95$, $A_{11}=0.97$, $A_{22}=0.95$, $s=0.7$, $T=100$) (degraded interval $t=69$–86, first 20 observations) | Recorded values | — | 5 | — |
| Synthetic data: frequencies of transitions and outputs, stationary distribution, mean and variance of the Gaussian output, mean, variance, and autocorrelation of the Kalman standardized prediction error, and coverage | Theoretical values, $\chi^{2}$ test | statistical | 15 | about 4 standard errors (corrected by the integrated autocorrelation time for correlated quantities), upper 0.1 % |
| Record of computation time | — | — | 1 | — |
For the on-screen checks, 169 procedures (44 of them comparisons), including the operating procedures in the boxes of Chapter 22, were run under both http and file://, and the on-screen values (for example the default $\ln p(x_{1:T})=-102.6791$) were compared with the Node.js values. At 330 px, which corresponds to the chapter’s frame, the fields for the hand-calculation, Kalman, and generation formulas become wider than the frame, but everything can be read by scrolling horizontally within the field.
The computations added for the simple view (sim/hmm.easy.js) were checked with 287 Node.js tests, and all succeeded. They were compared with the functions of the computation file (including that the first record is the same sequence as under the default conditions of ① of the detailed view).
D.11 S10 Attention and Next-Token Generation (attention)
D.11.1 Corresponding chapters, sections, and tabs
- Chapter 24: Section 24.3 (Simulator 24.1, tab attn), Section 24.6 (Simulator 24.2, tab attn).
- Chapter 25: Section 25.8 (Simulator 25.1, tab model). Chapter 26: Section 26.6 (Simulator 26.1, tab model), Section 26.9 (Simulator 26.2, tab model).
- Tab
attn, “① Following Attention Numerically,” andmodel, “② Small Trained Model (Next-Token Distribution and Generation).” - Scenes of the simple view (added in December 2026):
look“Which earlier words does this word look at?” (we see, by the thickness of lines, how much weight each word of a sentence places on which earlier words (the attention weights)),write“How is the next word chosen?” (the probabilities of the next word given by the small trained model are shown as bars, and a sentence is written by choosing one word at a time while changing the temperature $\tau$ (0.5, 1, or 2)). The computations use functions of the same computation file as the detailed view (main ones: forward, nextDist, step, sentences, judge). The explanation page is attention-derivation.html.
D.11.2 What this simulator has and lacks
This simulator clearly distinguishes the following three things (this is also always displayed at the top of the screen).
| ① Calculation demo with hand-set weights | ② A small Transformer trained for this book | ③ The actual GPT | |
|---|---|---|---|
| Where it is | tab attn | tab model | Not in this simulator |
| Weights | Values the reader enters in the numeric fields (the defaults are the same as the hand calculation in Chapter 24). Not trained | Values trained by next-token prediction (PyTorch, CPU, single precision) | — |
| Structure | One head, $d_k=d_v=d_{\mathrm{model}}$ (2–4), $T$ 3–5, no bias and no output projection $\bm{W}_O$ | Decoder only, pre-LN, learned position embedding, GELU (tanh approximation), weight sharing between the embedding and the output projection. $n_{\mathrm{layer}}=2$, $n_{\mathrm{head}}=2$, $d_{\mathrm{model}}=32$ (16 per head), FFN hidden size 128, context length $T_{\max}=24$ | The same type (a decoder-only Transformer with next-token prediction), but the scale, the training data, and the training method are entirely different from those of this simulator |
| Number of parameters | $3d_{\mathrm{model}}^{2}$ ($\bm{W}_Q,\bm{W}_K,\bm{W}_V$) | 28,384 | — |
| Vocabulary and data | — | Vocabulary of 67 (word level; including <bos>, <eos>, and the period). The training data are synthetic sentences for teaching purposes: only short sentences made mechanically from a table of 27 materials and 8 sentence patterns (no real texts are used). 6211 training sentences, 693 validation sentences | — |
| Evaluation values | — | Validation perplexity 1.651 (expected value from the entropy rate of the generation rules 1.653; predicting the 693 validation sentences with the same rules gives 1.645, and the trained model is larger than this; bigram model 2.52, uniform 67). Top-1 accuracy on 144 contexts asking for a fact: 139/144 (62/67 for infrequent materials). Factual errors in generation with the material specified ($\tau=1$): 47/520 (9.0 %) for infrequent materials | The numbers of this simulator are not the error rate of the actual GPT |
The “bigram model” on the screen is a model that looks only at the immediately preceding token and counts the frequencies of the next token (with additive smoothing $\alpha=0.1$); it is neither a Transformer nor GPT. It is included only for comparison with ②.
Caution: Attention weights are not necessarily the reason for a decision
The attention weights shown on the screen are the proportions in which each position gathers information from the other positions, and they are intermediate quantities of the computation. You must not read a position with a large weight as “the reason the model decided so.” This caution is also written directly below the weight diagram on the screen.
D.11.3 What is computed
- ①: From $\bm{X}\in\R^{T\times d_{\mathrm{model}}}$, with the sequence arranged in rows, the simulator forms $\bm{Q}=\bm{X}\bm{W}_Q$, $\bm{K}=\bm{X}\bm{W}_K$, $\bm{V}=\bm{X}\bm{W}_V$, and displays $$\begin{aligned}&\mathrm{Attention}(\bm{Q},\bm{K},\bm{V})\\ &=\softmax\!\left(\frac{\bm{Q}\bm{K}^{\tp}}{\sqrt{d_k}}+\bm{M}\right)\bm{V}\end{aligned}$$ stage by stage (the softmax is taken along the columns in each row; the causal mask is $M_{ij}=-\infty\ (j\gt i)$). The result of the softmax is the attention weight $A_{ij}$ (the proportion in which position $i$ gathers from position $j$). You can switch between dividing and not dividing by $\sqrt{d_k}$ and turn the mask on and off, and the sum of the weights in each row (= 1) is displayed.
- ②: The forward propagation is computed in double precision inside the browser: embedding + position embedding → two layers (LayerNorm → causal self-attention with two heads → residual, LayerNorm → FFN → residual) → final LayerNorm → product with the transpose of the embedding matrix, which gives the logit $\bm{o}_t\in\R^{67}$ (the logit at position $t$ gives the distribution of the next token under the condition $x_{\le t}$). The next-token distribution is built in the following order: divide the logits by the temperature $\tau$ and apply the softmax (computed by subtracting the maximum); top-k (the $k$ largest); top-p (accumulate the renormalized probabilities in descending order and keep the entries up to the position where the cumulative sum reaches $p$ or more); and renormalize what remains. For sampling, one uniform random number is drawn, the probabilities are accumulated in descending order, and the first token at which the cumulative sum exceeds that number is chosen. The log probability and perplexity of the generated sequence are displayed, with the screen stating which distribution they refer to (the model itself at $\tau=1$, or the distribution actually used).
- The generated sentences are classified, by comparison with the table and the templates from which the training data were made, as “Correct,” “Wrong (contradicts the table),” “Unsupported by the training data,” and “Fits no template”; a sequence without a period before
<eos>is regarded as “Incomplete” and is not classified.
D.11.4 Input ranges, upper limits, random numbers, and training conditions
- ①: $T$ 3–5, $d_{\mathrm{model}}$ 2–4, matrix values −5 to 5 (values out of range are clipped to the ends; the arrow keys step by 0.5). Five presets.
- ②: The context is up to 24 tokens (beyond that, the generation button is disabled). $\tau$ 0.05–3 (in steps of 0.05), top-k 0–67 (0 means no restriction), top-p 0.05–1. Fourteen context presets. The default sampling seed is 20261112 (one uniform random number per token; none is drawn for greedy decoding or when only one word remains).
- Training conditions (record): NumPy random numbers (seed 20261112) were used to create the training data. The number of sentences per material follows three frequency tiers (frequent 1000, medium 100, infrequent 8), and each material in the infrequent tier has 7 sentences in training, in which each of the sentence patterns that apply to that material (4–7 kinds) appears at least once (for a material with fewer than 7 patterns, the rest are drawn by weight, so the same pattern can appear 2 or 3 times). AdamW (learning rate $3\times10^{-3}$, warmup for 100 steps and then cosine down to 0, weight decay 0.01), minibatches of 32 rows × 24 tokens, 1500 steps (about 20 passes over the training data), seed 1, CPU, single precision, training time 14.0 s.
- Tuning of the training: in the first configuration the number of factual errors was 0, so the proportion of the infrequent tier was lowered and the number of passes over the data was reduced, giving the present configuration. All 12 configurations that were tried are recorded, and the final configuration was adopted after the training seed had been fixed at 1 (before the results for seeds 2 and 3 were seen).
D.11.5 Simplifications
- ① has one head, $d_k=d_v=d_{\mathrm{model}}$, and no bias and no $\bm{W}_O$.
- ② has a vocabulary of 67, a context length of 24, and word-level tokens (not subwords). The training data are only synthetic sentences, and there are only 8 sentence patterns. The classification targets only sentences that match one of the 8 patterns exactly.
D.11.6 Conditions for instability and the behavior of the simulator
- In ①, setting the inputs to ±5 makes the scores large and the softmax saturates (the maximum is subtracted in the computation, so the numbers do not overflow).
- In ②, a small $\tau$ gives the same result as greedy decoding, and a large one increases the sentences that do not fit a pattern. In a context where the top probabilities are close, a correct sentence and a wrong one swap places depending on the seed.
- For infrequent facts, errors with high probability appear (for example, after “mercury is at room temperature” the word “solid” with 0.998). A high probability does not mean being correct.
D.11.7 How and to what extent the numbers were checked
| Quantity checked | Compared with | Type | Count | Tolerance, etc. |
|---|---|---|---|---|
| That the weights and tables the simulator reads are the same as the original data | Original data | — | 3 | — |
| For ①: $\bm{Q},\bm{K},\bm{V}$, scores, weights, outputs, row sums (30 examples), closed-form expressions for the defaults, properties of the mask, and equivariance under row permutation (50 examples) | NumPy, SciPy’s softmax, closed-form expressions | independent implementation, analytical solution | 204 | weights $10^{-14}$, outputs $10^{-13}$, closed-form expressions rtol $10^{-15}$ |
| Forward propagation of ②: logits at the last position for 50 contexts. For one context of length 24, all intermediate values (embedding, attention weights, residuals, and outputs of each layer, the final LayerNorm, and the logits at all positions) | The PyTorch model used for training (single precision) | independent implementation | 14 | maximum absolute error of the logits $4.5\times10^{-6}$ (tolerance $10^{-4}$), embedding and weights $10^{-5}$, others $10^{-4}$ |
| Attention weights and sequence log probabilities of ②. Row sums = 1 (deviation below $10^{-14}$), weights at future positions = 0 (exact), and the logits at earlier positions not depending on later tokens because of the causal mask | An independent NumPy (double precision) forward propagation, and PyTorch log probabilities | independent implementation, analytical solution | 29 | weights $10^{-12}$, log probabilities $10^{-11}$ (against PyTorch, $10^{-3}$) |
| Next-token distributions (temperature, top-k, top-p; 78 examples): the set and order of the remaining words, the distribution, and the sampling result for given uniform random numbers | A reference written with the same rules as the generation at training time | independent implementation | 320 | distribution $10^{-14}$ |
| Classification of generated sentences (288 sentences). That all sentences of the training data are classified as “correct” | A reference with the same rules as the classification used in the evaluation | independent implementation | 6 | all agree |
| The table of the bigram model, reproducibility of the seed | — | — | 8 | — |
| Frequencies of sampling (20000 draws each for three settings) | $\chi^{2}$ test | statistical | 3 | significance level 0.001 |
Of the evaluation values of ②, the accuracy and the error rate in generation were measured in Python just once after training, and were not re-measured inside the browser (the error rate in generation was counted on sentences generated with Python’s random numbers, so it cannot be reproduced with the simulator’s random numbers). The validation perplexity of 1.65 was recomputed from the 693 validation sentences by a NumPy (double precision) forward propagation using the simulator’s weights, giving 1.6506 (2.5249 for the bigram model). For the on-screen checks, 179 procedures (42 of them comparisons), including the operating procedures in the boxes of Chapters 24–26, were run under both http and file://, and it was also confirmed that the formula of “Putting the current numbers into the formula” fits within the frame at 310 and 352 px, which correspond to the chapter’s frame.
The computations added for the simple view (sim/attention.easy.js) were checked with 276 Node.js tests, and all succeeded. They were compared with the functions of the computation file (forward, nextDist, generate, judge), with $\mathrm{softmax}(o/\tau)$ rewritten within the tests, and with the generated sequence under the default of the detailed view (seed 20261112).
D.12 Summary of What Was Not Checked and Limitations
D.12.1 Environments not checked
- The only environment in which the screens were checked is headless Chrome (desktop version). The widths were 390, 768, and 1280 px (S10 also at 310 and 352 px).
- The simple view and the explanation pages added in December 2026 were also checked only in headless Chrome (widths of 390, 768, and 1280 px). Whether the simple view helps first-time readers understand (its educational effect) has not been studied by having readers use it. Because the simple view has animated pictures, the display under the “reduce motion” setting was checked only for the simple view (D.1.8).
- We have not checked browsers other than Chrome (Safari, Firefox, etc.). In particular, the display of MathML (bold, script letters, left alignment in tables, stretchy parentheses) may differ from browser to browser.
- We have not checked touch operation on actual smartphones or tablets. The check at 390 px was done by narrowing the width of desktop Chrome.
- We have not checked reading aloud with screen readers. Keyboard operation was checked with the scripted operations. Because the detailed view has no animated pictures like those of the simple view, the display with
prefers-reduced-motion(the setting that reduces motion) was not checked for the detailed view (for the simple view, see D.1.8). - When the files were opened directly without starting a server (
file://), we confirmed that there are no console errors immediately after opening in all 10 simulators. Only S09 and S10 were taken through the scripted operations overfile://(Table D.3). - The tracking of the frame height when a simulator is embedded in a chapter, and the display at narrow widths corresponding to the width of the chapter frame, were checked in the per-simulator checks at the time of writing only for S10 (310 and 352 px; the equations fit inside the frame) and S09 (330 px; the equations scroll sideways inside the equation field). In December 2026, the frame heights and the display at a width of 390 px were checked for all frames in the 19 chapters (D.1.8).
D.12.2 Known limitations
- 1 ulp differences in elementary functions: Elementary functions such as
Math.log,cos,sin,tanh, andexp(Gaussian random numbers also pass through them) may differ in the last 1 ulp between Node.js and Chrome (D.1.3). This is not usually visible in the displayed digits, but the iteration count of an ill-conditioned SVM changes slightly with the environment (7,614 and 7,583). - Values of the logarithmic-scale sliders: $\gamma$ and $C$ in S04 move in steps of 0.05 in $\log_{10}$, so they do not land exactly on round values (the displayed 20.0 is 19.953, 0.0501 is $10^{-1.3}$, and 5.01 is $10^{0.7}$). $\eta$ cannot be set to 0.3, and the displayed 0.32 is 0.3162. The right end of $\eta$ in S05 is 2.5 ($10^{0.4}$) and does not reach 3.16. $\ell$ in S06 is 0.1995 at the 0.2 position and 5.012 at the 5 position. The numerical values in the main text are written as the values that actually appear on the screen.
- Number of samples in S01: the upper limit for the samples in ① is 10000 (the $n=20000$ of the test is outside the screen).
- Number of support vectors in S04: because of the SMO stopping tolerance $\varepsilon=10^{-3}$, it may differ by one from the exact solution (D.5.5).
- Tail precision in S06: beyond $z\approx-20$, the relative error of $\Phi(z)$ is about 0.4 %. In a setting where EI is extremely small everywhere, the chosen point is determined by rounding (D.7.5).
- Baseline value in S03: a simplification is made in which a fixed 88 % is subtracted from the target value and the penalty is applied to all coefficients, including the intercept (D.4.4).
- Loss convention in S04: the loss is a sum of cross-entropies, and the stable learning rate depends on $N$. S05 uses the mean loss (this corresponds to the differences in loss conventions among Chapters 7, 8, 9, 14, and 15).
- Mean function in S06: the computation uses the formula that includes a constant $m$ (default $\bar{y}$). The recommended point is the point with the largest observed value, and because of noise the simple regret may increase with the number of evaluations.
- Degenerate example in S07: the degeneracy is produced by placing the initial mean of the last component at an isolated point.
- Beta-type target in S08: the minimization of $\KL(q\,\|\,p)$ and the ELBO are computed with a truncated Gaussian distribution. $\hat{R}$ is the split-$\hat{R}$ without rank normalization.
- Kalman filter in S09: the convention is not to add $q$ in the prediction at $t=1$. The numerical values do not agree with the notation that sets $P_{1\mid0}=P_0+q$.
- S10: ② is not GPT, and the evaluation values are not the error rates of an actual GPT. The attention weights are not necessarily the reasons for a decision.
D.12.3 Beyond the range checked
- The numerical tests were carried out within the ranges of parameter sets and numbers of cases written in each table. We did not try every combination of the sliders. In particular, for ill-conditioned computations near the boundaries (high degrees, large $C$, long $\ell$ with small $\sigma$, and so on), the agreement with the reference computation also worsens in accordance with the condition number.
- The statistical checks were done only once with a fixed seed, and they are tests at a significance level of about 0.1 %. Passing a statistical check is not a proof that the generator or the algorithm is correct.
- Among the numerical values of the chapters in the main text, the figures and tables made with the same random-number sequence as the simulators (mulberry32) agree with the simulator screens, but the figures and tables made separately with NumPy random numbers (such as the comparison in Chapter 13) use a different random-number sequence, so their numerical values do not agree (this is stated in the explanation of the figures in each chapter).
- The evaluation of the trained model (S10 ②) gives values for this small model and this synthetic sentence, and it does not apply to other models or data.