Skip to main content

UnifiedFitConfig

Struct UnifiedFitConfig 

Source
pub struct UnifiedFitConfig { /* private fields */ }
Expand description

Unified fit configuration for all data types and solvers.

Carries both transmission and counts background configs, and uses SolverConfig (which embeds solver-specific tuning).

Implementations§

Source§

impl UnifiedFitConfig

Source

pub fn new( energies: Vec<f64>, resonance_data: Vec<ResonanceData>, isotope_names: Vec<String>, temperature_k: f64, resolution: Option<ResolutionFunction>, initial_densities: Vec<f64>, ) -> Result<Self, FitConfigError>

Construct a new config with validation.

Source

pub fn with_tzero_jacobian_method( self, method: Option<EnergyScaleJacobianMethod>, ) -> Self

Override the method used for the t0 / L_scale Jacobian columns in EnergyScaleTransmissionModel. None (default) defers to the model’s own default selection via EnergyScaleJacobianMethod::from_env: PartialGal since issue #489 unless overridden by NEREIDS_TZERO_JACOBIAN.

Source

pub fn with_solver(self, solver: SolverConfig) -> Self

Source

pub fn with_fit_temperature(self, v: bool) -> Self

Source

pub fn with_compute_covariance(self, v: bool) -> Self

Source

pub fn with_energy_scale( self, t0_init_us: f64, l_scale_init: f64, flight_path_m: f64, ) -> Self

Enable energy-scale fitting (SAMMY TZERO equivalent).

Adds t₀ (μs) and L_scale (dimensionless) as fit parameters. These adjust the energy axis during fitting to correct for flight-path and timing-offset uncertainties.

Source

pub fn with_fit_energy_range( self, range: Option<(f64, f64)>, ) -> Result<Self, FitConfigError>

Restrict the fit cost function to bins inside [min_eV, max_eV] (SAMMY EMIN/EMAX equivalent). The configured energies grid is expected to extend by ~5×FWHM beyond [min, max] on each side (the GUI / pre-processing layer handles this); the LM and joint-Poisson cost paths mask residuals outside [min, max] to zero so resonance broadening at the boundaries is correct. None (default) = full grid, no masking.

Validates the range up-front so non-finite or reversed bounds (which would silently produce an empty active-bin mask and a deceptive fit) are rejected at config-build time rather than surfacing as a downstream solver error.

Source

pub fn with_transmission_background(self, bg: BackgroundConfig) -> Self

Source

pub fn with_counts_background(self, bg: CountsBackgroundConfig) -> Self

Source

pub fn with_counts_enable_polish(self, v: Option<bool>) -> Self

Override the Nelder-Mead polish flag for the counts-KL dispatch. Some(true) forces polish on, Some(false) forces it off, None (the default) lets the dispatcher pick (polish on for single-spectrum, off for spatial maps per memo 38 §6).

Source

pub fn with_precomputed_cross_sections(self, xs: Arc<Vec<Vec<f64>>>) -> Self

Source

pub fn with_precomputed_work_cross_sections( self, xs: Arc<Vec<Vec<f64>>>, layout: Arc<WorkingGridLayout>, ) -> Self

Attach the working-grid Doppler-broadened σ + its layout for the fixed-calibration / fixed-temperature precomputed path (issue #608).

When set, build_transmission_model builds a [PrecomputedTransmissionModel] whose σ live on the working grid and whose evaluate / analytical_jacobian apply resolution on the working grid and extract the data points last — matching forward_model. The data-grid precomputed_cross_sections must still be set (for the surrogate-plan builders and shape validation); for tabulated / no resolution the working grid equals the data grid and this is left None.

The σ + layout are not validated here (this is an infallible builder setter); shape/consistency are checked once up front in validate_precomputed_cross_sections, which every public entry point (fit_spectrum_typed, fit_transmission_poisson, spatial_map_typed) calls before any forward-model build or per-pixel loop — mirroring how Self::with_precomputed_cross_sections is validated.

Source

pub fn with_precomputed_base_xs(self, xs: Arc<Vec<Vec<f64>>>) -> Self

Source

pub fn with_precomputed_resolution_plan(self, plan: Arc<ResolutionPlan>) -> Self

Attach a prebuilt resolution plan for the config’s energy grid.

The caller (typically spatial_map_typed) must ensure that plan.target_energies() equals self.energies(), otherwise the fit-model layer will return either a length-mismatch error or ResolutionError::PlanGridMismatch (for a different same-length grid) on the first broadening call.

Source

pub fn with_precomputed_sparse_cubature_plan( self, plan: Arc<SparseEmpiricalCubaturePlan>, ) -> Self

Attach a prebuilt sparse empirical cubature plan for the config’s energy grid + isotope set (see epic #472).

The plan is advisory — the fit model falls back to the exact ResolutionPlan path when any of these guards fire:

  • plan.target_energies() != self.energies() (grid mismatch).
  • plan.k() != n_density_params (isotope-set mismatch).
  • self.fit_temperature == true (σ changes → atoms stale).
  • self.fit_energy_scale == true (grid changes → plan stale).
  • n_density_params == 1 (scalar fast-path belongs to PR #475; for now this path still falls back).

Callers (typically spatial_map_typed) are responsible for ensuring the plan was built against compatible sigmas / training_densities / jacobian_anchor; the fit model cannot re-check those at dispatch time.

Source

pub fn with_precomputed_sparse_scalar_plan( self, plan: Arc<ScalarSurrogatePlan>, ) -> Self

Attach a prebuilt scalar (k = 1) surrogate plan. Epic #472, PR #475. Same invalidation discipline as the cubature: the plan is cleared on with_groups / with_precomputed_cross_sections / with_precomputed_base_xs, so a stale σ cannot silently dispatch.

Source

pub fn with_groups( self, groups: &[(&IsotopeGroup, &[ResonanceData])], initial_densities: Vec<f64>, ) -> Result<Self, FitConfigError>

Configure isotope groups with ratio constraints.

Each group binds multiple isotopes to one fitted density parameter. groups is a slice of (IsotopeGroup, member_resonance_data) pairs. initial_densities must have one entry per group.

Replaces the existing per-isotope configuration with the expanded group mapping (flattened resonance_data + density_indices + density_ratios).

Source

pub fn precomputed_sparse_cubature_plan( &self, ) -> Option<&Arc<SparseEmpiricalCubaturePlan>>

Caller-attached sparse empirical cubature plan, if any. spatial_map_typed reads this so a pre-existing plan is preserved instead of being clobbered by the local rebuild pathway (Codex round-5 P3 on PR #480).

Source

pub fn precomputed_sparse_scalar_plan( &self, ) -> Option<&Arc<ScalarSurrogatePlan>>

Caller-attached scalar (k = 1) surrogate plan, if any. Epic #472, PR #475.

Source

pub fn energies(&self) -> &[f64]

Source

pub fn resonance_data(&self) -> &[ResonanceData]

Source

pub fn isotope_names(&self) -> &[String]

Source

pub fn temperature_k(&self) -> f64

Source

pub fn resolution(&self) -> Option<&ResolutionFunction>

Source

pub fn initial_densities(&self) -> &[f64]

Source

pub fn solver(&self) -> &SolverConfig

Source

pub fn fit_temperature(&self) -> bool

Source

pub fn transmission_background(&self) -> Option<&BackgroundConfig>

Source

pub fn counts_background(&self) -> Option<&CountsBackgroundConfig>

Source

pub fn counts_enable_polish(&self) -> Option<bool>

Counts-KL polish override (see Self::with_counts_enable_polish).

Source

pub fn fit_energy_scale(&self) -> bool

Whether SAMMY TZERO energy-scale calibration is enabled (see Self::with_energy_scale).

Source

pub fn fit_energy_range(&self) -> Option<(f64, f64)>

User-specified fit-energy-range restriction (SAMMY EMIN/EMAX equivalent), or None for full-grid fitting. See Self::with_fit_energy_range.

Source

pub fn precomputed_cross_sections(&self) -> Option<&Arc<Vec<Vec<f64>>>>

Source

pub fn n_density_params(&self) -> usize

Number of density parameters (one per group or per isotope).

Trait Implementations§

Source§

impl Clone for UnifiedFitConfig

Source§

fn clone(&self) -> UnifiedFitConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnifiedFitConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more