Draft
Conversation
- implements Levenberg-Maquardt/Gauss-Newton style iterative least-squares solver
- for calibration/fitting of sextupoles strengths via the Nonlinear Optics from Off-energy Orbits (NOECO) method
Co-authored-by: fernandohds564 <fernandohds564@gmail.com>
- do not calculate M.T M every iter, only when jacobian is update - same for ridge regularization
fernandohds564
approved these changes
Oct 2, 2025
xresende
approved these changes
Oct 7, 2025
…nsformations additions: - automatically raveling of OEORM for `merit_figure_goal` - setter for goal oeorm - properties for nr of hor and ver bpms and corrs - methods to apply gains, parse gains and other params from optimization pos and vice-versa
-`rcond` added to params for cutting-off singular values less than `rcond * largest_singular_value` - initialized to `numpy.linalg.pinv` default of `1e-15`
- `ValueError` raised if no pos is passed.
… error bars) - refactor module to include fitting of corrs. gains and BPMs gains and couplings, support for bpms noise as error bars - organization and stylistic changes (func args names)
- allows choosing to use or not the diagonal & off-diagonal OEORM blocks as well as the hor. & ver. dispersion col.
…od and new behavior for default pos - dedicated method to get positions from init guesses and machine model state - default pos: if no last position evaluated, use params initial position, if empty, calculate it.
- now supports fitting only sextupoles, only corr or bpms gains, or only corr or only bpms gains
- residual evaluation was an implicit function of position. The objective func would evaluate the merit figure at current pos then calculate the residual with `calc_pos` - for NOECO, the residual evaluation depends not only on the position for calculating the figure of merit, but also for the application of gains to the goal figure of merit - to avoid workarounds, better make the residual calculation an explicit function of `pos`
…idual` w/ explicit `pos` dependence - default `pos` arg: `calc_merit_figure`, `calc_residual`, `calc_jacobian` and `apply_gains` now accept `None` arg and use default pos, which is the initial pos (machine initial state and gains initial guesses) - `calc_residual` with explicit `pos` dependence, in accordance with previous commit in `least_squares.py` - automatic handling of possibly raveled oeorm now inside `apply_gains` - `default_pos`: default pos is the initial pos (machine init strengths & gains initial guesses)
… constructing full jacobians
- enables selecting which OEORM blocks (diag, off-diag, dispersions) will be included for figure of merit calculations - does so by keeping track of `oeorm_mask`, which applies to the OEORM or its ravelled vector and the jacobian columns for filtering entries of interest
- method for calculating chromatic optics - matrix diffs visualization - plot chromatic optics - allows plot comparison of strenghts with respect to initial strength
- fitting to measured OEORMs is failing to reproduce vertical chromaticity - including chromaticities to the fitting with adequate weights (200 for fitting w/o off-diag blocks) rendered more well-behaved solutions
- introduces `disp_weight` for weighting the dispersion column - experimental noise: now supports natrix with noise for individual OEORM entries, as well as a single BPM noise vector used for a given line - fix errorbar: errorbars were not being conformed to the `oeorm_mask` object, so the selection of diag, off-diag, hor disp and vert disp noise components was broken - handling of merit figure shape outside `apply_gains` function, with new method `reshape_merit_figure`
- these changes introduce tentative steps to the LM loop - prior to them, steps were always accepted, whether they improved or worsened the chi2. Changes in the damping constan to control steps were applied only to the subsequent step - now the steps are tested prior to acceptance, and are accepted only if improve the objective - this change removes the need for back-tracking when the objective function evaluation fails - steps control now concentrates in the damping constant of the LM loop, with no need for a learning_rate constant
- properties `max_number_iters` or `max_number_evals` may be set to `np.inf` - in this case, the integer formatting method breaks - `np.inf` requires float format
- `_initialization` method now also specifies conssitent upper/lower limits for the optimization params
- other formats are always right-aligned - however, strings not necessarily. - for instance, `str(bool)` would always lose alignment
- adds str method for NOECO params
- change `ridge_constant` to `tikhonov_reg_constants` - allowing anisotropic constraining of particular singular modes - changing of the pseudo-inversion method: from pinv of the normal matrix to the calculation of the SVD and filtering/regularization of singular values - also requires including the singular modes penalization to the chi2 - not yet thoroughly tested
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work in progress
Introduces a least-squares iterative solver in the style of Gauss-Newton/Levenberg-Maquardt method to optimization module as well as a class implementing NOECO: sextupole strengths fitting routine using the off-energy orbit response matrix (OEORM) as input.