Skip to main content

PenaltyCoordinate

Enum PenaltyCoordinate 

Source
pub enum PenaltyCoordinate {
    DenseRoot(Array2<f64>),
    DenseRootCentered {
        root: Array2<f64>,
        prior_mean: Array1<f64>,
    },
    BlockRoot {
        root: Array2<f64>,
        start: usize,
        end: usize,
        total_dim: usize,
    },
    BlockRootCentered {
        root: Array2<f64>,
        start: usize,
        end: usize,
        total_dim: usize,
        prior_mean: Array1<f64>,
    },
    KroneckerMarginal {
        eigenvalues: Vec<Array1<f64>>,
        dim_index: usize,
        marginal_dims: Vec<usize>,
        total_dim: usize,
    },
}
Expand description

A rho-coordinate always contributes

A_k = λ_k S_k, S_k = R_k^T R_k.

For single-block/small problems it is fine to store the full-root R_k in the joint basis. For exact-joint multi-block paths that scaling is wasteful: the root is naturally block-local. This enum lets the unified evaluator consume both forms through one interface.

Variants§

§

DenseRoot(Array2<f64>)

§

DenseRootCentered

Fields

§root: Array2<f64>
§prior_mean: Array1<f64>
§

BlockRoot

Fields

§root: Array2<f64>
§start: usize
§end: usize
§total_dim: usize
§

BlockRootCentered

Fields

§root: Array2<f64>
§start: usize
§end: usize
§total_dim: usize
§prior_mean: Array1<f64>
§

KroneckerMarginal

Kronecker-factored penalty coordinate for tensor-product smooths.

In the reparameterized (eigenbasis) representation, the penalty I ⊗ ... ⊗ S_k ⊗ ... ⊗ I becomes I ⊗ ... ⊗ Λ_k ⊗ ... ⊗ I where Λ_k = diag(μ_{k,0}, ..., μ_{k,q_k-1}). This is diagonal in each mode, so apply/quadratic/trace operations avoid O(p²).

Fields

§eigenvalues: Vec<Array1<f64>>

Marginal eigenvalues for ALL dimensions: eigenvalues[j] has length q_j.

§dim_index: usize

Which marginal dimension this penalty coordinate corresponds to.

§marginal_dims: Vec<usize>

Marginal basis dimensions: [q_0, ..., q_{d-1}].

§total_dim: usize

Total joint dimension: ∏ q_j.

Implementations§

Source§

impl PenaltyCoordinate

Source

pub fn from_dense_root(root: Array2<f64>) -> Self

Source

pub fn from_dense_root_with_mean( root: Array2<f64>, prior_mean: Array1<f64>, ) -> Self

Source

pub fn from_block_root( root: Array2<f64>, start: usize, end: usize, total_dim: usize, ) -> Self

Source

pub fn from_block_root_with_mean( root: Array2<f64>, start: usize, end: usize, total_dim: usize, prior_mean: Array1<f64>, ) -> Self

Source

pub fn rank(&self) -> usize

Source

pub fn dim(&self) -> usize

Source

pub fn uses_operator_fast_path(&self) -> bool

Source

pub fn project_into_subspace(&self, z: &Array2<f64>) -> Self

Restrict this penalty coordinate onto the free subspace spanned by the orthonormal columns of z (shape p × m, m ≤ p, zᵀz = I).

When a linear-inequality active set is non-empty, the inner solve and the penalized Hessian are reduced to the free subspace β = z β_f of dimension m = p − active_set_size. The penalty must move in lockstep: the quadratic βᵀ S_k β = β_fᵀ (zᵀ S_k z) β_f, and since S_k = R_kᵀ R_k the reduced root is R_k z (shape rank_k × m). For a block-local root R_k acting on β[start..end] the same identity gives reduced dense root R_k · z[start..end, :], so the reduced coordinate is always a (dimension-m) DenseRoot / DenseRootCentered — the block structure does not survive an arbitrary subspace rotation. A centered mean μ_k maps to zᵀ μ_k, the representation of μ_k in the free subspace.

This keeps dim() equal to the reduced beta.len(), which InnerSolutionBuilder::build asserts.

Source

pub fn apply_penalty(&self, beta: &Array1<f64>, scale: f64) -> Array1<f64>

Source

pub fn apply_penalty_view_into( &self, beta: ArrayView1<'_, f64>, scale: f64, out: ArrayViewMut1<'_, f64>, )

Source

pub fn scaled_add_penalty_view( &self, beta: ArrayView1<'_, f64>, scale: f64, out: ArrayViewMut1<'_, f64>, )

Source

pub fn quadratic(&self, beta: &Array1<f64>, scale: f64) -> f64

Source

pub fn apply_shifted_penalty( &self, beta: &Array1<f64>, scale: f64, ) -> Array1<f64>

Source

pub fn shifted_quadratic(&self, beta: &Array1<f64>, scale: f64) -> f64

Source

pub fn scaled_dense_matrix(&self, scale: f64) -> Array2<f64>

Source

pub fn scaled_block_local(&self, scale: f64) -> (Array2<f64>, usize, usize)

Returns the block-local scaled penalty matrix (p_block × p_block) along with the embedding range, WITHOUT materializing into total_dim × total_dim. For DenseRoot (full-rank, no block structure), returns (matrix, 0, p).

Source

pub fn is_block_local(&self) -> bool

Whether this coordinate has block structure (not full-rank dense).

Source

pub fn scaled_matvec(&self, v: &Array1<f64>, scale: f64) -> Array1<f64>

Apply λ_k S_k to a vector v without materializing the full matrix. For BlockRoot: extracts v[start..end], multiplies by local S_k, embeds result.

Source

pub fn canonical_structural_key(&self) -> u64

A stable, formula-order-independent signature of this penalty coordinate’s STRUCTURAL CONTENT.

Two penalty coordinates that represent the same smoothing structure — the same wiggliness root, the same null-space ridge, the same tensor margin — produce the same key regardless of which block of the joint coefficient vector they happen to occupy or which order the user typed the terms in. It is derived ENTIRELY from rotation/placement-invariant content (rank, block width, the spectrum of the block-local penalty Sₖ = RₖᵀRₖ, or the marginal eigenvalue spectrum for a Kronecker margin), and NEVER from a coordinate’s position (start/dim_index) in the joint layout. Swapping s(x)+s(z)s(z)+s(x) or te(x,z)te(z,x) permutes the coordinates but leaves each coordinate’s key fixed.

This is the key the outer REML driver sorts on to present an identical canonical coordinate layout to the smoothing-parameter optimizer regardless of term/margin order, so the flat double-penalty REML valley is resolved order-invariantly (#1538/#1539). Values are quantized to a coarse relative grid so that floating-point round-off in the roots does not split an otherwise-identical key.

Trait Implementations§

Source§

impl Clone for PenaltyCoordinate

Source§

fn clone(&self) -> PenaltyCoordinate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PenaltyCoordinate

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

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

Source§

fn vzip(self) -> V