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) ∂²ρ/∂μ∂sThe 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
impl GaussianLocationScaleChannelHessian
Sourcepub fn from_pilot_observed_unclamped(
y: &Array1<f64>,
w: &Array1<f64>,
eta_mu: &Array1<f64>,
eta_log_sigma: &Array1<f64>,
) -> Result<Self, String>
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.
Sourcepub fn from_pilot(
y: &Array1<f64>,
w: &Array1<f64>,
eta_mu: &Array1<f64>,
eta_log_sigma: &Array1<f64>,
) -> Result<Self, String>
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
impl FamilyChannelHessian for GaussianLocationScaleChannelHessian
Source§fn n_subjects(&self) -> usize
fn n_subjects(&self) -> usize
Source§fn fill_subject(&self, i: usize, out: &mut [f64])
fn fill_subject(&self, i: usize, out: &mut [f64])
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>
fn evaluate_full(&self) -> Array3<f64>
(n_subjects × n_outputs × n_outputs) tensor.
Default implementation calls fill_subject for each row.Auto Trait Implementations§
impl Freeze for GaussianLocationScaleChannelHessian
impl RefUnwindSafe for GaussianLocationScaleChannelHessian
impl Send for GaussianLocationScaleChannelHessian
impl Sync for GaussianLocationScaleChannelHessian
impl Unpin for GaussianLocationScaleChannelHessian
impl UnsafeUnpin for GaussianLocationScaleChannelHessian
impl UnwindSafe for GaussianLocationScaleChannelHessian
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.