pub enum PenaltyMatrix {
Dense(Array2<f64>),
KroneckerFactored {
left: Array2<f64>,
right: Array2<f64>,
},
Blockwise {
local: Array2<f64>,
col_range: Range<usize>,
total_dim: usize,
},
Labeled {
label: String,
inner: Box<PenaltyMatrix>,
},
Fixed {
log_lambda: f64,
inner: Box<PenaltyMatrix>,
},
}Expand description
A penalty matrix that may be stored in Kronecker-factored form.
For tensor-product terms (e.g. time-varying survival covariates), the penalty
has the structure S = left ⊗ right (Kronecker product). Keeping this
factored avoids materializing (p_left × p_right)² dense entries and enables
exact log-determinant computation via log|A ⊗ B| = n_B log|A| + n_A log|B|.
Dense penalties are stored as-is. Callers that need a raw Array2<f64> can
call as_dense() (zero-cost for Dense, lazy-materialized for KroneckerFactored).
Variants§
Dense(Array2<f64>)
KroneckerFactored
Blockwise
Block-local penalty: local is block_dim × block_dim, embedded at
col_range in the full parameter space of dimension total_dim.
Avoids materializing the full total_dim × total_dim matrix.
Labeled
Wrapper assigning this penalty component to a user-visible precision label. Components with the same label share one smoothing parameter.
Fixed
Wrapper fixing this penalty component at a physical log-precision. Fixed components remain in the block-local physical penalty layout but are removed from the REML outer coordinate vector.
Implementations§
Source§impl PenaltyMatrix
impl PenaltyMatrix
Sourcepub fn as_dense_cow(&self) -> Cow<'_, Array2<f64>>
pub fn as_dense_cow(&self) -> Cow<'_, Array2<f64>>
Borrow the inner dense matrix if Dense, otherwise materialize.
Sourcepub fn as_dense_ref(&self) -> Option<&Array2<f64>>
pub fn as_dense_ref(&self) -> Option<&Array2<f64>>
Returns a reference to the inner matrix if this is a Dense variant.
pub fn with_precision_label(self, label: impl Into<String>) -> Self
pub fn precision_label(&self) -> Option<&str>
pub fn with_fixed_log_lambda(self, log_lambda: f64) -> Self
pub fn fixed_log_lambda(&self) -> Option<f64>
Sourcepub fn dot(&self, v: &Array1<f64>) -> Array1<f64>
pub fn dot(&self, v: &Array1<f64>) -> Array1<f64>
Compute S * v using the row-major Kronecker vec trick when factored: (A ⊗ B) vec_rm(V) = vec_rm(A V Bᵀ) where V = reshape(v, (p_left, p_right)).
Sourcepub fn add_scaled_to(&self, lambda: f64, target: &mut Array2<f64>)
pub fn add_scaled_to(&self, lambda: f64, target: &mut Array2<f64>)
Add λ * self to a mutable dense accumulator.
Sourcepub fn add_scaled_diag_to(&self, lambda: f64, target: &mut Array1<f64>)
pub fn add_scaled_diag_to(&self, lambda: f64, target: &mut Array1<f64>)
Add λ * diag(self) to a mutable diagonal accumulator.
Sourcepub fn quadratic_form(&self, beta: &Array1<f64>) -> f64
pub fn quadratic_form(&self, beta: &Array1<f64>) -> f64
Compute the quadratic form β’ S β.
pub fn ncols(&self) -> usize
Trait Implementations§
Source§impl Clone for PenaltyMatrix
impl Clone for PenaltyMatrix
Source§fn clone(&self) -> PenaltyMatrix
fn clone(&self) -> PenaltyMatrix
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PenaltyMatrix
impl Debug for PenaltyMatrix
Auto Trait Implementations§
impl Freeze for PenaltyMatrix
impl RefUnwindSafe for PenaltyMatrix
impl Send for PenaltyMatrix
impl Sync for PenaltyMatrix
impl Unpin for PenaltyMatrix
impl UnsafeUnpin for PenaltyMatrix
impl UnwindSafe for PenaltyMatrix
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.