- Home
- Library
- Computational Quantum Field Theory
- Differentiating and Optimizing Field Calculations
- Stochastic Gradients and Optimization Noise
Stochastic Gradients and Optimization Noise
A variational energy can be estimated accurately while the parameters used to define the state are still wandering. Conversely, an optimizer can stop at a plausible parameter whose final energy estimate is noisy. Which uncertainty belongs to the state, and which belongs to the measurement?
We answer with a Gaussian trial state for a quartic oscillator. Its exact variational objective is known, so two sampled gradients, fixed learning-rate schedules, and independent final measurements can be checked separately. The calculation also gives a counterexample to the claim that differentiating through a sampling path always produces the lowest-variance gradient.
Preparation: Expectations and importance sampling in Monte Carlo integration, and the distinction between a numerical stopping test and a physical result in constrained optimization. All oscillator quantities below are dimensionless after choosing units; the potential uses the site's quartic coefficient .
An energy whose optimum is known
Take
and the normalized trial family
The probability density is , with and . The kinetic expectation is , hence
Use to enforce positive width. Its exact gradient and curvature are
The objective is strictly convex in for , . The stationary equation is . For the chosen parameters,
These are the optimum and energy within this Gaussian family. Variational optimization does not establish that a Gaussian is the exact ground state of the quartic Hamiltonian. Optimizer error, sampling error, and trial-family error are different quantities.
Specify what is sampled before differentiating
The local energy is
Its expectation under is . This standard variational Monte Carlo identity and its zero-variance limit are explained in Toulouse, Assaraf and Umrigar, §1.1–1.2.1, pp.3–4 (PDF). Here we can sample the Gaussian directly:
There is no Markov chain, burn-in, or autocorrelation correction in this example. The training draws are independent conditional on the current parameter.
Differentiate the path at fixed base noise
Substitute the sampling map into the local energy:
Differentiation at fixed gives one unbiased gradient draw,
Both the explicit parameter in and the parameter in were differentiated. Holding the sampled fixed and taking only the explicit derivative would omit a term. The interchange of integration and differentiation is valid here because, on any compact positive-width interval, the Gaussian supplies an integrable bound on the required polynomial factors. Mohamed et al., §§5.1–5.2, Eqs.(26)–(29) (PDF).
Differentiate the probability measure instead
The score at fixed is
In general, a parameter-dependent integrand requires
For this family, , whose expectation is zero. Thus
The last expression is the usual variational-energy covariance gradient. The vanishing explicit-derivative expectation has been proved for this estimator; it is not a license to drop such derivatives in another model. The score identity and constant-baseline construction are given in Mohamed et al., §§4.1–4.3, Eqs.(11)–(14) (PDF).
For a batch of draws, the companion uses
This sample covariance is unbiased. If the same-batch means are subtracted but the denominator is , the expectation is . A randomly fitted baseline cannot simply be treated as a fixed constant independent of its own sample.
Estimator variance changes during optimization
For the pathwise batch mean, the variance is . For the sample covariance, define centered moments
Expanding the sample sums and grouping equal and unequal indices gives
All moments here are Gaussian polynomial integrals. The companion evaluates them using exact integer normal moments and independently with Gauss–Hermite quadrature. At the resulting variances are:
| Width | Pathwise variance | Score-covariance variance |
|---|---|---|
| 1.02799 | 4.83811 | |
| 0.0843492 | 0.0224371 | |
| 0.0709635 | 0.0612847 |
The preferred estimator by this criterion changes with the parameter. An even sharper distinction occurs at the free minimum, and . The local energy is then the constant , so every sample-covariance gradient is zero. The pathwise gradient is instead , with nonzero variance per draw. Equal expectations do not imply equal variances, even for derivatives of the same energy.
There is also uncertainty in an empirical variance estimate. The fixed diagnostic uses 1024 independent batches at each width and batch size. At , , its measured score-gradient variance is , while the independently evaluated population variance is . The score gradient contains high powers of a Gaussian, making rare large samples influential. We retain this discrepancy; a finite batch study is not a precise replacement for the available moment calculation. The two polynomial-moment paths agree within , and neither uses these random batches as its reference.
Learning rates control a distribution of parameters
Apply the update
where projects onto the declared interval. The initial width is , and the true variational optimum is interior. Projection is an explicit algorithm choice, not unreported gradient clipping. Every boundary contact is counted.
We compare a constant rate with
The infinite decreasing sequence has and . Such conditions help control noise under suitable regularity assumptions; they do not certify a finite run or automatically transfer an unprojected convergence theorem to this projected algorithm. Fixed steps can retain a stationary spread even when the gradient estimator is unbiased. Bottou, Curtis and Nocedal, §4.2, Eq.(4.19) and Theorems 4.6–4.7 (PDF).
Near the optimum, write , with and zero-mean gradient noise. A fixed step multiplies the old parameter error by and adds fresh noise. Exercise2 derives its limiting variance. This explains why averaging the last few parameters, using a decreasing rate, and increasing the batch size affect different parts of the calculation. Averaging and averaging are also different operations.
A frozen repeated-seed comparison
Each of the eight estimator/schedule/batch combinations uses 32 independent runs. Every run consumes 16384 training normals: 1024 updates at or 256 at . The seeds are SeedSequence([921025, 10, estimator, schedule, batch, replica]); the accompanying JSON declares the integer labels and runtime versions. Settings were fixed before production. Equal draw counts do not imply equal update counts or equal wall time.
| Gradient | Schedule | Mean final ± SE | RMS error in | Mean | |
|---|---|---|---|---|---|
| Pathwise | Constant | 16 | 0.04223 | ||
| Pathwise | Constant | 64 | 0.02211 | ||
| Pathwise | Decreasing | 16 | 0.02461 | ||
| Pathwise | Decreasing | 64 | 0.01854 | ||
| Score covariance | Constant | 16 | 0.02551 | ||
| Score covariance | Constant | 64 | 0.01267 | ||
| Score covariance | Decreasing | 16 | 0.01413 | ||
| Score covariance | Decreasing | 64 | 0.00963 |
The SE in this table describes the mean over 32 runs; it is not the spread of a single optimized width. The RMS error includes both finite-horizon bias and stochastic spread. All 256 runs finish without a projection contact. That observed result does not prove that the projection would remain inactive for every seed or coupling.
The same recursions with exact gradients supply deterministic finite-horizon controls. The least accurate final exact-gradient energy in these settings exceeds by , for the shorter constant-rate run. The larger stochastic excesses therefore cannot be explained solely by that deterministic stopping horizon. All final iterates remain primary results; averages over the last quarter of updates are retained separately, without selecting whichever looks best after the calculation.
The final-width panel shows individual runs and their mean; the bars give one across-run standard deviation, whereas the table quotes the standard error of the mean. The dashed horizontal line is . The variance panel uses the independent Gaussian-moment calculation at , not fitted variance estimates from the optimizer paths.
Measure the final state with new draws
After training, each run receives 8192 independent normals from a separate seed family beginning [921025, 12, ...]. At its final width , we estimate both and . Conditional on the trained parameter, their reference expectations are
The validation error bar is the sample standard deviation divided by . It measures uncertainty in an observable of that final trial state. It does not include its displacement from the variational optimum or the unknown Gaussian-family error relative to the true ground state.
The mean reported energy SE ranges from to across the eight settings. Between 29 and 31 of the 32 energy estimates per setting lie within 1.96 reported SE of their own conditional expectation. These small ensembles are diagnostics, not precise coverage measurements. In particular, this validation noise can exceed the remaining mean optimization excess; quoting it as uncertainty about would mix two different targets.
The law of total variance summarizes the separation. If is an unbiased fresh estimate at a random trained width,
More validation draws reduce the first term, while further or improved optimization changes the second. Neither operation enlarges the variational family.
Reproduction uses gaussian_variation.py, stochastic_gaussian.py, and stochastic-results.json in the chapter's example directory. The driver also writes all parameter histories to an ignored numerical archive. Training consumes 4194304 normal draws, validation 2097152, and the independent fixed-point gradient study 245760. The plotter reads retained summaries without rerunning any training.
Summary
An unbiased gradient is a statement about one conditional expectation, not a promise that a finite optimizer output is unbiased or optimal. The Gaussian example separates gradient variance, the distribution of trained parameters, and a fresh measurement of the final state. Its exact objective and moment calculations reveal finite sampling fluctuations without tuning them away, while the quartic model keeps variational-family error distinct from numerical uncertainty.
Exercises
- Derive the optimum of the Gaussian family and show that the score-covariance gradient has zero variance at the free minimum, although the pathwise local-energy gradient does not.
Solution
The Gaussian moments give . Multiplication of by gives . Strict positivity of and divergence of at both width endpoints imply a unique minimum for , .
For , the solution is . Substitution into leaves the constant , so every centered local-energy sample is zero and . In contrast,
A batch mean divides that variance by . The derivative along the sampling path probes neighboring trial states, so constancy of the local energy at the single optimum does not force that derivative to be constant as a function of .
- Consider , where , the independent noises have mean zero and variance , and is fixed. Derive its mean and variance. What can an independent final observable measurement repair?
Solution
Write . Iteration gives
Consequently and
When , the finite sum instead gives . For , the mean tends to zero but the limiting variance is
For a quadratic objective , the expected excess energy is . A zero mean parameter error therefore does not imply zero mean energy error. If an observable is subsequently estimated with fresh samples, its measurement noise can be reduced independently. Those samples do not move the already chosen parameter, so they cannot remove its bias or across-run spread. This linearized calculation assumes fixed noise variance and no active projection; it explains a mechanism rather than replacing the nonlinear experiment.
References
- Léon Bottou, Frank E. Curtis and Jorge Nocedal, “Optimization Methods for Large-Scale Machine Learning,” SIAM Review 60 (2018) 223–311, arXiv:1606.04838 (PDF), February 12, 2018 version, §§4.1–4.2, Eq.(4.19) and Theorems 4.6–4.7: gradient-moment assumptions and fixed/decreasing step sizes.
- Shakir Mohamed, Mihaela Rosca, Michael Figurnov and Andriy Mnih, “Monte Carlo Gradient Estimation in Machine Learning,” Journal of Machine Learning Research 21 (132) (2020) 1–62, PDF, §§4.1–4.3 and 5.1–5.2: score and pathwise estimators, baselines and differentiation assumptions.
- Julien Toulouse, Roland Assaraf and C. J. Umrigar, “Introduction to the variational and diffusion Monte Carlo methods,” arXiv:1508.02989v1 (PDF), §§1.1–1.2.1, Eq.(1) and pp.3–4: normalized local-energy expectation, iid uncertainty and the zero-variance property.
Scrollable formula. Use Left and Right arrow keys to reveal hidden content.
Scrollable table. Use Left and Right arrow keys to reveal hidden columns.
Scrollable figure. Use Left and Right arrow keys to reveal hidden content.