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 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 / penalised-Hessian of the centred fit pushes forward to the raw basis through the SAME z via Gauge::lift_covariance.

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 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 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 back to reduced coordinates: S_reduced = Tᵀ · S_raw · T.

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, m_reduced: &Array2<f64>) -> Array2<f64>

Push a reduced-coordinate symmetric matrix (posterior covariance, penalized Hessian — any symmetric bilinear form on θ) forward to raw coordinates via the exact sandwich M_raw = T · M_θ · Tᵀ.

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

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