Skip to main content

Gauge

Struct Gauge 

Source
pub struct Gauge {
    pub t_full: Array2<f64>,
    pub affine_shift: Array1<f64>,
    pub block_starts_raw: Vec<usize>,
    pub block_starts_reduced: Vec<usize>,
}
Expand description

The lift T : reduced → raw plus the per-block partitions of both coordinate systems. See the module docs for the lift conventions.

Fields§

§t_full: Array2<f64>

Global lift matrix, shape (Σ p_b_raw) × (Σ r_b_reduced).

§affine_shift: Array1<f64>

Global affine shift in raw coordinates, length Σ p_b_raw.

§block_starts_raw: Vec<usize>

Raw-coordinate block partition: block_starts_raw[b]..block_starts_raw[b+1] is block b’s raw row range in t_full. Length n_blocks + 1, starts at 0.

§block_starts_reduced: Vec<usize>

Reduced-coordinate block partition (columns of t_full), same layout.

Implementations§

Source§

impl Gauge

Source

pub fn validate(&self) -> Result<(), String>

Validate the serialized affine section and its block topology.

A Gauge is persisted inside fitted models and its fields remain public for matrix-oriented consumers. Consumers of decoded or manually assembled state must therefore reject malformed dimensions, partitions, and non-finite affine maps before coefficient or curvature transforms.

Source

pub fn identity(raw_widths: &[usize]) -> Self

The trivial section: raw == reduced for every block.

Source

pub fn from_block_transforms(transforms: &[Array2<f64>]) -> Self

Block-diagonal section from independent per-block lifts T_b : reduced_b → raw_b (selection matrices from the canonical audit, orthogonalisation V_bs, or their compositions).

Source

pub fn from_block_transforms_with_shift( transforms: &[Array2<f64>], affine_shift: Array1<f64>, ) -> Self

Block-diagonal affine section from independent per-block lifts plus one concatenated raw-coordinate shift.

Source

pub fn from_block_transform_with_shift( transform: Array2<f64>, affine_shift: Array1<f64>, ) -> Self

Single-block affine section.

Source

pub fn from_v_and_r( v_per_term: &[Array2<f64>], r_per_term: &[Option<Array2<f64>>], ) -> Self

Block-upper-triangular section from per-block V_b plus cross-block residualisation stacks R_{a→b} — see assemble_block_triangular_t for the packing convention.

Source

pub fn sum_to_zero(z: Array2<f64>) -> Self

The sum-to-zero (centering) section as a first-class single-block gauge. z is the (k × (k−1)) reparametrisation matrix returned by terms::basis::duchon_thinplate::apply_sum_to_zero_constraint (an orthonormal basis for null(cᵀ), c = Bᵀw the weighted column sums): the constrained design is B_c = B · z, so on the model η = B · β_raw = B_c · θ = B · z · θ the raw coefficients lift back from the reduced (centred) coefficients by exactly β_raw = z · θ.

That is the one Gauge convention with T = z over a single block, so the centring constraint stops being a special-cased outside-the-object transform and becomes a Gauge section like every other reduction: the covariance of the centred fit pushes forward to the raw basis through the SAME z via Gauge::lift_covariance. A raw-coordinate Hessian or penalty instead pulls back to the centred coordinates as zᵀ H z via Gauge::restrict_penalty.

z is taken as the section itself (rather than recomputed from a basis) because the constraint matrix is the only gauge-relevant artifact — the basis the column sums were taken over is irrelevant to the lift. The only requirement is the structural one of a centring section: z.ncols() < z.nrows() (at least one direction is removed); an identity z would be Gauge::identity and is rejected so callers do not silently treat an unconstrained block as centred.

Source

pub fn from_t( t_full: Array2<f64>, raw_widths: &[usize], reduced_widths: &[usize], ) -> Self

Wrap an already-assembled global T given the per-block raw and reduced width partitions.

Source

pub fn from_t_with_shift( t_full: Array2<f64>, raw_widths: &[usize], reduced_widths: &[usize], affine_shift: Array1<f64>, ) -> Self

Wrap an already-assembled global affine section β = Tθ + a given the per-block raw and reduced width partitions.

Source

pub fn left_compose(&self, outer: &Gauge) -> Result<Gauge, String>

Compose this affine section on the left with outer.

self maps active geometry coordinates into a current raw coefficient frame, while outer maps that current frame into a new raw frame:

current = T_self · active + a_self
new     = T_outer · current + a_outer

Therefore the returned section has lift T_outer · T_self and shift T_outer · a_self + a_outer. The complete intermediate block partition must agree exactly; matching only the total dimension would lose the coefficient-block lineage persisted with a fit.

Source

pub fn from_compiled_map<M: CompiledBlockMap, O>( map: &M, ordering: &[O], ) -> Self

Build from a compiled identifiability reparametrisation (see CompiledBlockMap, implemented for the CompiledMap emitted by the identifiability compiler): map.raw_from_compiled() IS the global triangular T, and the block ranges give both partitions. ordering is accepted purely as a length sanity check.

Source

pub fn n_blocks(&self) -> usize

Number of blocks in the partition.

Source

pub fn raw_total(&self) -> usize

Total raw width Σ p_b.

Source

pub fn reduced_total(&self) -> usize

Total reduced width Σ r_b.

Source

pub fn raw_widths(&self) -> Vec<usize>

Per-block raw widths.

Source

pub fn reduced_widths(&self) -> Vec<usize>

Per-block reduced widths.

Source

pub fn block_transform(&self, b: usize) -> Array2<f64>

The diagonal slab T_b = T[raw_b, reduced_b] of block b. For a block-diagonal gauge this is the whole story for the block; for a triangular gauge it omits the cross-block −R.

Source

pub fn restrict_design<S: Data<Elem = f64>>( &self, raw_design: &ArrayBase<S, Ix2>, ) -> Array2<f64>

Compose a raw design with the section: X_reduced = X_raw · T.

Source

pub fn is_identity(&self) -> bool

Whether this is the exact affine identity on every persisted block.

This is stricter than the internal linear fast-path predicate: the lift must be a literal identity, the affine shift must be exactly zero, and raw/reduced block boundaries must coincide. No tolerance is used, so a true result is a proof that active and saved coordinates are identical rather than merely numerically close.

Source

pub fn restrict_design_and_offset<S: Data<Elem = f64>>( &self, raw_design: &ArrayBase<S, Ix2>, raw_offset: &Array1<f64>, ) -> (Array2<f64>, Array1<f64>)

Compose a raw design and offset with the affine section: X_raw · (Tθ + a) + o_raw = (X_raw · T)θ + (o_raw + X_raw · a).

Source

pub fn restrict_penalty<S: Data<Elem = f64>>( &self, raw_penalty: &ArrayBase<S, Ix2>, ) -> Array2<f64>

Pull a raw-coordinate quadratic form (including a penalty or Hessian) back to reduced coordinates: S_reduced = Tᵀ · S_raw · T.

Source

pub fn restrict_quadratic_factor<S: Data<Elem = f64>>( &self, raw_factor: &ArrayBase<S, Ix2>, ) -> Array2<f64>

Pull a constructive quadratic factor into reduced coordinates.

A positive-semidefinite quadratic represented as S_raw = A_rawᵀ A_raw has energy ‖A_raw · β_raw‖². Under this gauge’s section β_raw = T · θ + a, the quadratic part is therefore represented constructively by

A_reduced = A_raw · T,
S_reduced = A_reducedᵀ A_reduced.

Keeping the rectangular factor across the congruence is stronger than materializing Tᵀ S_raw T: it preserves the proof that the restricted form is PSD and its null space is null(A_raw T), even when two dense matrix products would leave a signed roundoff residue in an exact null direction (#2318).

Source

pub fn extend_with_identity(&self, extra_raw_widths: &[usize]) -> Self

Append blocks that were never reduced (raw == reduced, identity lift). Used to lift joint objects that span both gauged blocks and untouched ones (e.g. the survival flex blocks alongside the compiled parametric blocks).

Source

pub fn lift_block_betas( &self, reduced_block_betas: &[Array1<f64>], ) -> Vec<Array1<f64>>

Lift per-block reduced coefficients to per-block raw coefficients: concatenate into θ, apply β = T · θ + a, split at the raw partition.

Source

pub fn lift_covariance(&self, covariance_reduced: &Array2<f64>) -> Array2<f64>

Push a reduced-coordinate posterior covariance forward to raw coordinates via the exact sandwich Σ_raw = T · Σ_θ · Tᵀ.

This is deliberately covariance-specific. Hessians and penalties are covariant quadratic forms and transform in the opposite direction via Gauge::restrict_penalty; T H Tᵀ is not a Hessian pushforward.

The result is explicitly symmetrised: T · M · Tᵀ is symmetric for symmetric M, but the two matmuls accumulate independent rounding, so the transpose pair is averaged to land an exactly symmetric matrix for downstream Cholesky / eigensolves.

Trait Implementations§

Source§

impl Clone for Gauge

Source§

fn clone(&self) -> Gauge

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 Gauge

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Gauge

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Gauge

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Gauge

§

impl RefUnwindSafe for Gauge

§

impl Send for Gauge

§

impl Sync for Gauge

§

impl Unpin for Gauge

§

impl UnsafeUnpin for Gauge

§

impl UnwindSafe for Gauge

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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