Skip to content
QFT.org

Search QFT.org

Enter a word or phrase.

    You can also browse the main navigation and chapter contents.

    Neural Networks and Training Objectives

    A small training loss is not a complete physical result. A network may miss an exact zero, violate a response identity, or stop before its requested optimization tolerance. We can inspect all three possibilities on the finite scalar response and compare them with ordinary interpolation on exactly the same labels.

    Preparation: The reference scalar observable, the baseline comparison, and the chain rule underlying automatic differentiation.

    A network for two specified outputs

    The input is x=(r/4,J/0.6)x=(r/4,J/0.6) for the two-site periodic scalar with λ=4\lambda=4. The target is z=(M/3,log⁡χ/3)z=(M/3,\log\chi/3), with χ=∂JM>0\chi=\partial_JM>0. Use two hidden layers of width 3232, each with a hyperbolic tangent, followed by a two-component linear output:

    a(0)=x,u(l)=a(l−1)Wl+bl,a(l)=tanh⁡u(l)(l=1,2),a^{(0)}=x,\qquad u^{(l)}=a^{(l-1)}W_l+b_l,\qquad a^{(l)}=\tanh u^{(l)}\quad(l=1,2), fθ(x)=a(2)W3+b3.f_\theta(x)=a^{(2)}W_3+b_3.

    Rows represent examples; WlW_l has shape dl−1×dld_{l-1}\times d_l. Counting weights and biases gives

    (2⋅32+32)+(32⋅32+32)+(32⋅2+2)=1218(2\cdot32+32)+(32\cdot32+32)+(32\cdot2+2)=1218

    real parameters. The physical predictions are

    M^=3fθ,1,χ^=e3fθ,2.\widehat M=3f_{\theta,1},\qquad \widehat\chi=e^{3f_{\theta,2}}.

    The output architecture enforces positivity of χ^\widehat\chi, but it does not enforce χ^=∂JM^\widehat\chi=\partial_J\widehat M or source parity. Those are separate physical checks.

    For n=221n=221 fixed training labels, minimize

    L(θ)=12n∑i=1n∥fθ(xi)−zi∥22+γ2∑l=13∥Wl∥F2,γ=10−6.\mathcal L(\theta)=\frac1{2n}\sum_{i=1}^{n} \lVert f_\theta(x_i)-z_i\rVert_2^2 +\frac\gamma2\sum_{l=1}^{3}\lVert W_l\rVert_F^2, \qquad\gamma=10^{-6}.

    Biases are not penalized. This loss expresses a chosen balance between mean-field error and multiplicative susceptibility error. It is not a likelihood inferred from quadrature noise: the reference labels are deterministic high-accuracy integrals. With genuinely noisy labels, a declared Gaussian covariance would instead lead to a quadratic residual weighted by its inverse, including cross-example correlations if present. Estimating or ignoring that covariance changes the objective; calling an arbitrary squared loss a physical likelihood would hide an assumption.

    Derive the gradient that is actually optimized

    Let AlA_l contain layer-ll activations for all examples, with A0=XA_0=X and A3=FA_3=F. Define the output adjoint

    Δ3=F−Zn.\Delta_3=\frac{F-Z}{n}.

    The derivative of tanh⁡u\tanh u is 1−tanh⁡2u1-\tanh^2u. Therefore backward propagation gives

    Δl=(Δl+1Wl+1T)⊙(1−Al2),l=2,1,\Delta_l=(\Delta_{l+1}W_{l+1}^T)\odot(1-A_l^2), \qquad l=2,1,

    where ⊙\odot denotes elementwise multiplication. The parameter derivatives are

    ∂L∂Wl=Al−1TΔl+γWl,∂L∂bl=∑i(Δl)i,:.\frac{\partial\mathcal L}{\partial W_l} =A_{l-1}^T\Delta_l+\gamma W_l, \qquad \frac{\partial\mathcal L}{\partial b_l} =\sum_i(\Delta_l)_{i,:}.

    For the final layer the same weight and bias formulas use A2A_2 and Δ3\Delta_3; there is no output activation derivative. These equations are the ordinary backward chain rule. Rumelhart, Hinton and Williams, pp. 533–535, Eqs. (1)–(9) (PDF), present the layered squared-loss construction with a logistic activation. The tanh derivative and optimizer used here are explicit choices for this example.

    A useful check must test more than two copies of this vectorized formula. The companion evaluates a tiny 2→3→22\to3\to2 network by independent scalar loops. Five fixed parameter directions compare the analytic directional derivative against central differences with steps from 10−310^{-3} to 10−710^{-7}. Every direction reaches an error below 1.1×10−111.1\times10^{-11}; the expected truncation decrease and eventual roundoff increase are retained. A separate production-network input derivative check differs from finite differences by less than 2.5×10−112.5\times10^{-11}. Packing and unpacking all 12181218 parameters is checked exactly.

    Frozen optimization and independent evaluation

    Five initializations use zero biases and independent Gaussian weights with variance 2/(dl−1+dl)2/(d_{l-1}+d_l). Their seeds are SeedSequence([941025,20,k]) for k=0,…,4k=0,\ldots,4. Each is optimized once by L-BFGS-B without parameter bounds, using the analytic gradient above. The fixed caps are 15001500 iterations and 50005000 function evaluations, with maxls=40, maxcor=20, ftol=1e-14 and gtol=1e-7.

    The two stopping tests have different meanings: a small relative objective change can stop a run without satisfying the gradient criterion. The SciPy 1.13.1 L-BFGS-B documentation defines these tests and caps. Here all five runs reach the iteration limit. Their returned status is unsuccessful, and an independent final gradient evaluation confirms that none meets the requested 10−710^{-7} maximum-component tolerance. No run is restarted or replaced by a more favorable seed.

    Accepted-iterate training and monitor losses are retained. The 192192 monitor points do not stop training or select a checkpoint. The 2 0482\,048 final test points are not available to optimization. The table reports physical test RMSE and the final objective-gradient norm:

    InitializationRMSE in MMRMSE in χ\chi∥∇L∥∞\lVert\nabla\mathcal L\rVert_\infty
    000.004680.004680.014630.014631.71×10−51.71\times10^{-5}
    110.004010.004010.017030.017032.82×10−52.82\times10^{-5}
    220.004780.004780.013890.013895.55×10−55.55\times10^{-5}
    330.004990.004990.013970.013972.12×10−52.12\times10^{-5}
    440.004780.004780.011490.011491.83×10−51.83\times10^{-5}
    Five-model transformed-output mean0.003600.003600.011730.01173—
    Zero-initialized control0.890720.890722.011882.011883.51×10−173.51\times10^{-17}

    The ensemble averages fθf_\theta, not the two physical outputs after exponentiation. Thus its MM is the arithmetic average of individual M^\widehat M, while its χ\chi is the geometric average of individual χ^\widehat\chi. Initialization SD is neither a standard error of a measured observable nor a Bayesian posterior without further assumptions.

    The zero-initialized control has all weights and biases initially zero. It reaches the constant-output stationary solution in one iteration and satisfies the gradient target, yet predicts poorly. This is a deliberately retained counterexample to identifying successful optimization with a useful representation. Its derivation appears in Exercise 1.

    Five neural optimization histories and their final physical susceptibility errors, alongside a poor stationary zero-initialization control.

    Training and monitor losses for five fixed initializations, with the same optimizer budget. All random runs reach 15001500 iterations before the requested gradient tolerance. The constant zero-initialized control converges quickly but has much larger physical error. Test values never select an iteration.

    These finite-budget neural fits are less accurate than the cubic spline's 0.001290.00129 susceptibility RMSE on this regular-grid test. They still demonstrate a trainable representation with checked derivatives. Neither greater width nor a lower training loss alone establishes an advantage over the appropriate baseline.

    Exact zeros and identities that the loss does not impose

    Relative error in MM is ill-defined at J=0J=0. The separate diagnostic set contains r=−4,0,2,4r=-4,0,2,4, each at J=0J=0, ±10−8\pm10^{-8}, ±10−4\pm10^{-4} and ±0.01\pm0.01. We use absolute errors when ∣M∣<10−6|M|<10^{-6} and report relative errors only on the remaining points. Across the random networks, the maximum near-zero absolute mean-field error ranges from 0.004280.00428 to 0.010270.01027. A smooth-looking curve can therefore miss a tiny physical response by many times its magnitude. No denominator floor is used to disguise this as a finite relative error at zero.

    The scaled input also matters when testing the response relation. Since x2=J/0.6x_2=J/0.6,

    ∂JM^=5 ∂x2fθ,1.\partial_J\widehat M =5\,\partial_{x_2}f_{\theta,1}.

    The physical defect is 5∂x2fθ,1−exp⁡(3fθ,2)5\partial_{x_2}f_{\theta,1}-\exp(3f_{\theta,2}). Its test RMS ranges from 0.03650.0365 to 0.05090.0509 across the five runs. The outputs were trained separately, so this is a substantive residual rather than a contradiction.

    A secondary source-parity projection is possible:

    M^odd(r,J)=M^(r,J)−M^(r,−J)2,\widehat M_{\rm odd}(r,J)=\frac{\widehat M(r,J)-\widehat M(r,-J)}2, log⁡χ^even(r,J)=log⁡χ^(r,J)+log⁡χ^(r,−J)2.\widehat{\log\chi}_{\rm even}(r,J) =\frac{\widehat{\log\chi}(r,J)+\widehat{\log\chi}(r,-J)}2.

    The first expression makes M^(r,0)=0\widehat M(r,0)=0 exactly, and the second yields an even positive susceptibility after exponentiation. These are prediction-only projections, not retrained models. They reduce the observed response-defect RMS to 0.02730.0273–0.04170.0417 here, but do not make it vanish. The saved raw parity diagnostics are explicitly defects in MM and log⁡χ\log\chi, not MM and physical χ\chi.

    The active example retains every primary network's weights, stopping status and history in observable-network.json. Running observable_network.py --fit deliberately retrains the frozen study; its default mode only verifies and evaluates saved weights. This separation permits a figure or a prediction to be reproduced without silently running a new optimization.

    Summary

    Backpropagation supplies the gradient of a declared loss, not a guarantee of physical accuracy. This example separates reference errors, representation choices, finite optimization, initialization variation, near-zero diagnostics and exact identities. All five random fits miss the requested convergence target; a different stationary control succeeds numerically while failing as a predictor.

    Exercises

    1. Why can zero initialization fail at a stationary point?

    For the two-hidden-layer tanh network and weight penalty above, set every weight to zero and the first two biases to zero. Show that optimizing only the output bias reaches a stationary point of the full objective. Is it necessarily a global minimum?

    Solution

    Both hidden activations vanish, so fθ(x)=b3f_\theta(x)=b_3 for every input. The output-bias derivative is b3−z‾b_3-\overline z, hence b3=z‾b_3=\overline z minimizes the constant-predictor loss. The output-weight gradient is A2TΔ3+γW3=0A_2^T\Delta_3+\gamma W_3=0, since A2=W3=0A_2=W_3=0. Propagating through W3=0W_3=0 gives Δ2=0\Delta_2=0, and then Δ1=0\Delta_1=0. All remaining weight gradients and hidden-bias gradients vanish as well.

    Thus the point is stationary for the entire parameter vector. Its data loss is the target variance divided according to the declared normalization; it need not be small. A nonconstant network can fit varying targets better, so stationarity is not a global-minimum certificate. The experiment realizes this trap: a tiny gradient coexists with susceptibility RMSE about 2.012.01.

    2. Symmetry does not imply the fluctuation relation

    Derive the source derivative of M^odd\widehat M_{\rm odd}. Give a parity-correct positive pair (M^,χ^)(\widehat M,\widehat\chi) that still violates χ^=∂JM^\widehat\chi=\partial_J\widehat M.

    Solution

    The chain rule on the reflected argument gives

    ∂JM^odd(r,J)=∂JM^(r,J)+∂JM^(r,−J)2.\partial_J\widehat M_{\rm odd}(r,J) =\frac{\partial_J\widehat M(r,J)+\partial_J\widehat M(r,-J)}2.

    The second derivative symbol on the right means differentiation with respect to the function's own source argument before evaluating it at −J-J. In scaled network coordinates this is 2.5[∂x2f1(x1,x2)+∂x2f1(x1,−x2)]2.5[\partial_{x_2}f_1(x_1,x_2)+\partial_{x_2}f_1(x_1,-x_2)].

    For a simple counterexample take M^(r,J)=J\widehat M(r,J)=J and χ^(r,J)=2\widehat\chi(r,J)=2. The first is odd, the second positive and even, yet ∂JM^=1≠2\partial_J\widehat M=1\ne2. Source parity constrains transformation laws; the fluctuation relation couples derivatives of one observable to another. It would need a different representation, such as consistent derivatives of a learned generating function, or an additional explicitly stated constraint. Such a model would still require accuracy checks.

    References

    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.