Loss, Weights and Uncertainties

This page gives the formulas a tracking fit uses. The POCO fitters use the same weights and uncertainty estimate.

Loss

Each worker compares the model with the measurement at its BPMs and returns the chi-square

\[\chi^2 = \sum_{o} \sum_{\mathrm{particles}} \sum_{\mathrm{points}} w_o \, (m_o - d_o)^2 ,\]

where \(o\) runs over the compared observables (x and y, plus px and py with optimise_momenta), \(m_o\) is the model value and \(d_o\) the measured value. The optimiser adds the worker chi-squares (reduce_replies()); a worker that lost its particles returns NaN and is left out.

  • Levenberg-Marquardt minimises \(\chi^2\) plus the priors.

  • Adam and L-BFGS minimise \(\chi^2 / N\), with \(N\) the number of training points with a non-zero weight. The validation loss is the held-out \(\chi^2\) divided by its own \(N\), so the two are on one scale.

Weights

\[w_o = \frac{1}{\sigma_o^2}\]
  • \(\sigma_o^2\) is the var_* column of the measurement file (Measurement Data).

  • A missing reading, or a variance that is zero, negative or not finite, gets \(w_o = 0\).

Gradient

The model values and their derivatives by every knob come from one MAD-NG track with the knobs as TPSA parameters. The gradient is

\[\frac{\partial \chi^2}{\partial k_n} = 2 \sum_{o} \sum_{\mathrm{particles}} \sum_{\mathrm{points}} w_o \, (m_o - d_o) \, \frac{\partial m_o}{\partial k_n} .\]

Levenberg-Marquardt also uses the Gauss-Newton Hessian \(2 J^\mathsf{T} W J\), where \(J\) holds the derivatives \(\partial m / \partial k\).

Uncertainties

After the fit, the workers send their Jacobians at the best knobs and the start coordinates they used. The 1-sigma uncertainty of each knob is

\[\sigma_k = \sqrt{\operatorname{diag}\left(A^{-1} B A^{-1}\right)} ,\]

with \(A = J^\mathsf{T} W J\) and \(B\) the measurement noise propagated through every reading and start coordinate (sandwich_uncertainties()). Eigenvalues of \(A\) below a floor are raised to the floor, so a direction the data do not constrain gets a large, finite uncertainty. check_degeneracy() lists those directions before a fit.

With TrackingParameters.fit_start_coords the start coordinates are fit parameters. Each particle’s start is projected out of \(A\) and of every reading’s sensitivity (the Schur complement of the joint knob and start matrix), and the measured start variances are not used.

Gaussian priors (TrackingParameters.knob_sigmas, bpm_gain_sigma and the zero-mean gain groups) are added as one more measurement: \(P = 1/\sigma_\mathrm{prior}^2\) enters both \(A\) and \(B\), so with \(B = A\) the covariance is \((A + P)^{-1}\).

OutputConfig.include_uncertainty=False skips this step; the uncertainties are then zero.

Knob values

A fitter reports its knobs in optimisation space:

  • A field error is the change of the integrated strength, for example MQ.12R3.B1.dk1l is the change of \(k_1 L\) in m⁻¹.

  • A misalignment is the offset or angle itself: .dx, .dy, .ds in m, .tilt in rad.

  • The beam energy is fitted as pt; a deltap given as a starting value is converted to pt.

Accelerator.format_result_knobs renames indexed multipole knobs (knl[3]) for reports.