Skip to main content

JointPoissonObjective

Struct JointPoissonObjective 

Source
pub struct JointPoissonObjective<'a> {
    pub model: &'a dyn FitModel,
    pub o: &'a [f64],
    pub s: &'a [f64],
    pub c: f64,
    pub active_mask: Option<&'a [bool]>,
}
Expand description

Joint-Poisson objective.

Wraps a transmission FitModel (which produces T_i = model.evaluate(θ)) together with the observed open-beam counts O_i, sample counts S_i, and proton-charge ratio c = Q_s / Q_ob.

The caller is responsible for ensuring o, s, and model.evaluate() output all have the same length.

Fields§

§model: &'a dyn FitModel

Transmission model: evaluate(θ) → T(E).

§o: &'a [f64]

Open-beam counts per bin.

§s: &'a [f64]

Sample counts per bin.

§c: f64

Proton-charge ratio c = Q_s / Q_ob. Must be strictly positive.

§active_mask: Option<&'a [bool]>

Optional per-bin active mask (SAMMY EMIN/EMAX-equivalent fit-energy-range restriction). When Some(m), only bins where m[i] is true contribute to the deviance / gradient / Fisher information; the model is still evaluated on the full grid so resolution broadening at the boundaries is correct. When None, all bins are active (default behaviour).

Length must equal o.len(); the GUI / pipeline dispatch builds it from the configured [E_min, E_max] against the energy grid.

Implementations§

Source§

impl<'a> JointPoissonObjective<'a>

Source

pub fn n_data(&self) -> usize

Number of data bins.

Source

pub fn n_active(&self) -> usize

Number of active data bins — n_data when no mask is set, or the count of true entries in active_mask otherwise. This is the count that should drive deviance-per-dof reporting.

Source

pub fn profile_lambda(&self, t_i: f64, o_i: f64, s_i: f64) -> f64

Closed-form profile MLE for the per-bin flux: λ̂ = c·(O+S) / (1+c·T).

Guards: when 1 + c·T ≤ ε, returns 0 to avoid division blow-up.

Source

pub fn profile_lambda_per_bin( &self, t: &[f64], ) -> Result<Vec<f64>, FittingError>

Vector form of profile_lambda.

Validates t.len() == o.len() == s.len() and c > 0; returns FittingError::LengthMismatch / InvalidConfig rather than the previous .zip() truncate-and-pretend behaviour (which would silently shrink the output to min(t.len(), o.len(), s.len())).

Source

pub fn deviance_from_transmission(&self, t: &[f64]) -> Result<f64, FittingError>

Conditional binomial deviance at the given transmission vector.

D = 2 · Σ [ S·ln(S/(Np)) + O·ln(O/(N(1−p))) ] with p = cT/(1+cT), N = O+S, and x·ln(x/0) → 0.

Near invalid or numerically tiny transmission values, the per-bin evaluation (binomial_deviance_term) uses t.max(POISSON_EPSILON) to clamp T away from zero before entering the logarithms and the 1/(1+cT) factor. This avoids singular logs and division-by-zero but is a piecewise clamp, not a smooth quadratic extrapolation — D(T) is C⁰ at the clamp boundary, not C¹. In practice this is adequate because the optimizer’s transmission values come from a FitModel that keeps T bounded well above POISSON_EPSILON for physically plausible density / nuisance parameter values.

Source

pub fn deviance(&self, params: &[f64]) -> Result<f64, FittingError>

Evaluate the deviance at parameter vector θ by calling the model.

Source

pub fn deviance_gradient_analytical( &self, params: &[f64], free_param_indices: &[usize], ) -> Result<Option<Vec<f64>>, FittingError>

Analytical gradient of the deviance w.r.t. the free parameters.

Returns None if the transmission model does not provide an analytical Jacobian — callers should fall back to deviance_gradient_fd.

Gradient derivation: with p_i = cT_i/(1+cT_i) and N_i = O_i+S_i,

d D / d T_i = −2 · (S_i − O_i·c·T_i) / (T_i · (1 + c·T_i))

then chain-rule with the transmission Jacobian J_{i,j} = ∂T_i / ∂θ_{f(j)} where f(j) is the j-th free parameter index.

Source

pub fn fisher_information( &self, params: &[f64], free_param_indices: &[usize], ) -> Result<Option<FlatMatrix>, FittingError>

Fisher information for free parameters (Gauss-Newton curvature of D).

Uses the expected-info form

h_i ≡ ∂² D / ∂ T_i² ≈ 2 · (O_i + S_i) · c / (T_i · (1 + c·T_i)²)

(derived from logit-link binomial Var(S|N) = N p (1−p) and d logit(p) / dT = 1/T, scaled by 2 since D = −2 L). Then

I(θ){j,k} = Σ_i h_i · J{i,j} · J_{i,k}.

Returns None if the transmission model does not provide an analytical Jacobian.

Source

pub fn fisher_information_fd( &self, params: &mut ParameterSet, fd_step: f64, ) -> Result<Option<FlatMatrix>, FittingError>

Finite-difference Fisher information.

Fallback for callers whose transmission model does not implement FitModel::analytical_jacobian — i.e., when Self::fisher_information would return None. Builds the transmission Jacobian column-by-column via central differences and assembles

I(θ)_{j,k} = Σ_i h_i · J_{i,j} · J_{i,k}

where h_i = ∂² D / ∂ T_i² is the per-bin deviance curvature 2·(O_i + S_i)·c / (T_i·(1 + c·T_i)²) (Fisher-scoring form derived from binomial logit-link Var(S | N) = N·p·(1−p) with d logit p / dT = 1/T — see the module-level docstring §Model). Returns Ok(None) only if the base model evaluation itself fails.

Source

pub fn deviance_gradient_fd( &self, params: &mut ParameterSet, fd_step: f64, ) -> Result<Vec<f64>, FittingError>

Finite-difference gradient of the deviance.

Central differences on each free parameter. Used as a fallback when the model has no analytical Jacobian. params is a mutable ParameterSet so we can respect bounds via clamp().

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> 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, 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