accelmo.tracking.lm_problem¶
The tracking Levenberg-Marquardt objective: knobs, BPM gains and optionally the particle starts.
- accelmo.tracking.lm_problem.LM_REFRESH_ATOL = 1e-12¶
A refresh that moves no start coordinate by more than this (m, rad) leaves the objective unchanged.
- class accelmo.tracking.lm_problem.StartGainMap(starts, jacobian, gains)[source]¶
Bases:
objectStarts as a linear function of the BPM gains:
s(g) = starts + jacobian @ (g - gains).starts(n_particles, 4)inTrackingSession.send_init_condition_updates()order,jacobian(n_particles, 4, n_gains)andgains(n_gains,)inTrackingFitter.gain_namesorder. See docs/start_gain_chain_rule.md.- Parameters:
starts (numpy.ndarray)
jacobian (numpy.ndarray)
gains (numpy.ndarray)
- starts: ndarray¶
- jacobian: ndarray¶
- gains: ndarray¶
- accelmo.tracking.lm_problem.chain_starts_through_gains(grad, hessian, start_grad, knob_start, blocks, jacobian, gains)[source]¶
Gradient and Gauss-Newton Hessian of
L(k, g, s(g))from those ofL(k, g, s).start_grad(4P,),knob_start(n, 4P) andblocks(P, 4, 4) are the start blocks,jacobian(P, 4, n_gains) is ds/dg andgainsthe gains’ slice of the n parameters. Derivation: docs/start_gain_chain_rule.md.- Return type:
tuple[ndarray,ndarray]- Parameters:
grad (numpy.ndarray)
hessian (numpy.ndarray)
start_grad (numpy.ndarray)
knob_start (numpy.ndarray)
blocks (numpy.ndarray)
jacobian (numpy.ndarray)
gains (slice)
- class accelmo.tracking.lm_problem.TrackingLMProblem(session, names, n_gains, num_batches, parameters, knob_sigma, gain_ridge, callback, model_values)[source]¶
Bases:
LMProblemLoss, gradient and Gauss-Newton Hessian of the tracking fit over every batch.
The parameters are the
names(magnet knobs, then the BPM gains, the lastn_gains). Withfit_start_coordsevery training particle’s start (x, px, y, py) follows them in session particle order and is pushed to the workers before each evaluation. Withstarts_follow_gainsthe starts are the callback’sStartGainMapat the trial gains.- Parameters:
session (TrackingSession)
names (list[str])
n_gains (int)
num_batches (int)
parameters (TrackingParameters)
knob_sigma (np.ndarray)
gain_ridge (float)
callback (Callable[[dict[str, float], dict[str, float]], np.ndarray | StartGainMap | None] | None)
model_values (dict[str, float])
- start_map: StartGainMap | None¶
- initial_params(knobs)[source]¶
Knobs in
namesorder; with fitted starts, the workers’ measured starts follow.- Return type:
ndarray- Parameters:
knobs (dict[str, float])
- param_names()[source]¶
namesthen onestart_param{i}per fitted start coordinate.- Return type:
list[str]
- starts(params)[source]¶
The fitted
(n_particles, 4)starts inparams; empty without fitted starts.- Return type:
ndarray- Parameters:
params (numpy.ndarray)
- knobs(params)[source]¶
The
namesentries ofparamsas a knob dict.- Return type:
dict[str,float]- Parameters:
params (numpy.ndarray)