Skip to main content

GaussianLocationScaleChannelHessian

Struct GaussianLocationScaleChannelHessian 

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

Per-subject 2×2 channel Hessian W_i for Gaussian location-scale.

The row negative log-likelihood (with per-row weight w_i, response y_i, mean predictor μ_i, log-scale predictor s_i = log σ_i) is

ρ_i(μ, s) = w_i [s + 0.5·(y_i − μ)²·exp(−2s)]

The 2×2 Hessian in (μ, s) coordinates:

W_i[0,0] = w_i · exp(−2 s_i)                        ∂²ρ/∂μ²
W_i[1,1] = w_i · 2·(y_i − μ_i)²·exp(−2 s_i)        ∂²ρ/∂s²
W_i[0,1] = W_i[1,0] = w_i · 2·(y_i − μ_i)·exp(−2 s_i)  ∂²ρ/∂μ∂s

The off-diagonal cross-channel term ∂²ρ/∂μ∂s is nonzero whenever the residual (y_i − μ_i) ≠ 0, i.e. away from the fitted mean.

Implementations§

Source§

impl GaussianLocationScaleChannelHessian

Source

pub fn from_pilot_observed_unclamped( y: &Array1<f64>, w: &Array1<f64>, eta_mu: &Array1<f64>, eta_log_sigma: &Array1<f64>, ) -> Result<Self, String>

Construct the raw (un-PSD-clamped) per-subject observed Hessian.

For Gaussian location-scale the 2×2 observed Hessian [[w·e^{-2s}, 2·w·r·e^{-2s}], [2·w·r·e^{-2s}, 2·w·r²·e^{-2s}]] has determinant -2·w²·r²·e^{-4s} which is non-positive whenever the residual r = y − μ ≠ 0. Tests that finite-difference the row NLL must compare against this raw observed Hessian — PSD clamping alters the eigenvalues and the FD-versus-closed-form match fails.

Production code that needs a PSD matrix (e.g. the canonicalize gate) must call Self::from_pilot which PSD-clamps via 2×2 eigendecomposition.

Source

pub fn from_pilot( y: &Array1<f64>, w: &Array1<f64>, eta_mu: &Array1<f64>, eta_log_sigma: &Array1<f64>, ) -> Result<Self, String>

Construct from pilot predictors (μ and log σ at current β) and data, with PSD eigenvalue clamping applied per subject.

y is the response, w the per-row sample weights, eta_mu and eta_log_sigma the current linear predictors. Negative eigenvalues are projected to zero (PSD clamp) before storage so the resulting matrix is a valid metric for the W-Gram identifiability compile.

Trait Implementations§

Source§

impl FamilyChannelHessian for GaussianLocationScaleChannelHessian

Source§

fn n_outputs(&self) -> usize

Number of output channels n_outputs (= K in the row Jacobian).
Source§

fn n_subjects(&self) -> usize

Number of subjects (rows).
Source§

fn fill_subject(&self, i: usize, out: &mut [f64])

Fill the n_outputs × n_outputs per-subject channel Hessian W_i into out (row-major, length n_outputs * n_outputs) for subject i. Negative eigenvalues must be clamped to zero (PSD projection) before or inside this call.
Source§

fn evaluate_full(&self) -> Array3<f64>

Materialise the full (n_subjects × n_outputs × n_outputs) tensor. Default implementation calls fill_subject for each row.
Source§

fn channel_hessian_at( &self, beta: &[f64], family_scalars: Option<&Arc<dyn Any + Sync + Send>>, ) -> Result<Arc<dyn FamilyChannelHessian>, String>

Return a refreshed W evaluated at beta using family_scalars when those scalars carry the per-row primary state at the current β. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V