Skip to main content

ImplicitDesignPsiDerivative

Struct ImplicitDesignPsiDerivative 

Source
pub struct ImplicitDesignPsiDerivative { /* private fields */ }
Expand description

Implicit representation of ∂X/∂ψ_d that supports matrix-vector products without materializing the full (n x p) derivative matrices.

For anisotropic Matern / Duchon terms with D axes, the dense path creates D matrices of size (n x p_smooth) for dX/dpsi_d. At n=400K, p=2000, D=16, that is ~100 GB.

Two storage modes:

Materialized (small-to-medium problems): stores pre-computed arrays

  • phi_values[i*n_knots + j] = phi(r_{ij})
  • q_values[i*n_knots + j] = phi’(r_{ij}) / r_{ij}
  • t_values[i*n_knots + j] = (phi’’(r_{ij}) - q_{ij}) / r_{ij}^2
  • axis_components[i*n_knots + j, d] = exp(2 eta_d) * (x_{id} - c_{jd})^2 Memory: O(n * k * (D + 2)).

Streaming (biobank scale): stores only data/centers/eta/kernel params and recomputes (q, t, s_a) on the fly during each matvec. Memory: O(nd + kd) – no per-(data,knot) storage.

The raw-psi chain rule: shape_a = q * s_a shape_ab = t * s_a * s_b + 2 q s_a 1[a=b] dphi/dpsi_a = shape_a + c * phi d2phi/(dpsi_a dpsi_b) = shape_ab + c (shape_a + shape_b) + c^2 phi where c = 0 for Matérn and c = delta / d for hybrid Duchon.

Implementations§

Source§

impl ImplicitDesignPsiDerivative

Source

pub fn new( phi_values: Array1<f64>, q_values: Array1<f64>, t_values: Array1<f64>, axis_components: Array2<f64>, ident_transform: Option<Array2<f64>>, full_ident_transform: Option<Array2<f64>>, n: usize, n_knots: usize, n_poly: usize, n_axes: usize, ) -> Self

Construct from pre-computed radial jet scalars.

§Arguments
  • q_values: (n * n_knots,) — φ’(r)/r for each (data, knot) pair.
  • t_values: (n * n_knots,) — (φ’’(r) - q) / r² for each pair.
  • axis_components: (n * n_knots, D) — s_{d,ij} = exp(2η_d) · h_d² for each pair/axis.
  • ident_transform: optional (n_knots × p_constrained) constraint projection.
  • full_ident_transform: optional further projection after padding.
  • n, n_knots, n_poly, n_axes: dimensions. Construct from pre-computed (materialized) radial jet scalars. This is the original path for small-to-medium problems where O(nk(d+2)) storage is acceptable.
Source

pub fn n_data(&self) -> usize

Number of data points.

Source

pub fn n_axes(&self) -> usize

Number of axes (D).

Source

pub fn p_out(&self) -> usize

Output dimension: total basis columns in the final space.

Source

pub fn unproject_matrix(&self, u: &ArrayView2<'_, f64>) -> Array2<f64>

Batched unproject for a (p_out × rank) coefficient matrix. Returns (n_knots × rank) via two BLAS3 matmuls — the same algebra as unproject, but amortized across all rank columns of u. Used by forward_mul_matrix so per-axis trace evaluations can be a single chunked GEMM rather than rank-many forward_mul calls.

Source

pub fn transpose_mul( &self, axis: usize, v: &ArrayView1<'_, f64>, ) -> Result<Array1<f64>, BasisError>

Compute (∂X/∂ψ_d)^T v for a given axis d and vector v of length n.

Returns a vector of length p_out (total basis dimension after all transforms).

Formula in raw knot space: [raw]j = Σ_i v_i · q{ij} · s_{d,ij} then project through Z and pad.

Note: q = φ_r/r and s_d = exp(2ψ_d)·h_d² are UNNORMALIZED axis components. With this convention, q·s_d = (φ_r/r)·(exp(2ψ_d)·h_d²) = φ_r·(s_d/r), which equals the correct ∂φ/∂ψ_d = φ_r·∂r/∂ψ_d = φ_r·s_d/r. No r² correction is needed — that would be required only if s_d were the fractional quantity s_d/r².

Source

pub fn forward_mul( &self, axis: usize, u: &ArrayView1<'_, f64>, ) -> Result<Array1<f64>, BasisError>

Compute (∂X/∂ψ_d) u for a given axis d and vector u of length p_out.

Returns a vector of length n.

Formula: for each data point i, result_i = Σ_j q_{ij} · s_{d,ij} · u_knot_j where u_knot = Z · u_smooth (unprojected back to knot space).

Source

pub fn transpose_mul_second_diag( &self, axis: usize, v: &ArrayView1<'_, f64>, ) -> Result<Array1<f64>, BasisError>

Compute (∂²X/∂ψ_d²)^T v — diagonal second derivative, same axis.

Matrix-free variant of materialize_second_diag: avoids forming the full (n × p_out) matrix when only a single adjoint matvec is needed.

Source

pub fn transpose_mul_second_cross( &self, axis_d: usize, axis_e: usize, v: &ArrayView1<'_, f64>, ) -> Result<Array1<f64>, BasisError>

Compute (∂²X/∂ψ_d∂ψ_e)^T v — cross second derivative (d ≠ e).

Source

pub fn forward_mul_second_diag( &self, axis: usize, u: &ArrayView1<'_, f64>, ) -> Result<Array1<f64>, BasisError>

Compute (∂²X/∂ψ_d²) u — forward diagonal second derivative.

Source

pub fn forward_mul_second_cross( &self, axis_d: usize, axis_e: usize, u: &ArrayView1<'_, f64>, ) -> Result<Array1<f64>, BasisError>

Compute (∂²X/∂ψ_d∂ψ_e) u — forward cross second derivative.

Source

pub fn materialize_first(&self, axis: usize) -> Result<Array2<f64>, BasisError>

Materialize the full (n × p_out) first-derivative matrix for axis d.

Efficient O(n * k) construction: builds the raw (n × k) kernel derivative matrix directly, then projects through identifiability transforms. This is used when the dense matrix is needed temporarily (e.g., for HyperCoord construction) while avoiding simultaneous storage of all D axes.

Source

pub fn materialize_second_diag( &self, axis: usize, ) -> Result<Array2<f64>, BasisError>

Materialize the full (n × p_out) second diagonal derivative matrix for axis d.

Source

pub fn materialize_second_cross( &self, axis_d: usize, axis_e: usize, ) -> Result<Array2<f64>, BasisError>

Materialize the full (n × p_out) cross second derivative matrix for axes (d, e).

Dense materialization of the t · s_d · s_e cross coupling.

Source

pub fn row_chunk_first( &self, axis: usize, rows: Range<usize>, ) -> Result<Array2<f64>, BasisError>

Source

pub fn row_chunk_first_raw( &self, axis: usize, rows: Range<usize>, ) -> Result<Array2<f64>, BasisError>

Raw (chunk × n_knots) first-order kernel scalars for axis d, without the identifiability/padding projection. Pairs with unproject_matrix in forward_mul_matrix: the kernel scalars stay in raw knot space while the rank side (F) is unprojected to knot space, so the per-chunk GEMM is (chunk × n_knots) · (n_knots × rank) rather than (chunk × p_out) · (p_out × rank). Saves both flops and a (chunk × p_out) intermediate.

Source

pub fn row_chunk_first_raw_all_axes( &self, rows: Range<usize>, ) -> Result<Vec<Array2<f64>>, BasisError>

All-axis variant of Self::row_chunk_first_raw: produces the raw first-order kernel scalars for every ψ-axis in a single sweep over (row, knot) pairs. The radial scalars (phi, q, r²) only depend on — not on the axis — so an N-axis Duchon term that previously invoked compute_pair N× per (row, knot) now invokes it once and fills N output matrices cheaply. Transformed axis_combinations remap axes nontrivially, so defer to the per-axis path in that case.

Source

pub fn row_chunk_second_diag( &self, axis: usize, rows: Range<usize>, ) -> Result<Array2<f64>, BasisError>

Source

pub fn row_chunk_second_cross( &self, axis_d: usize, axis_e: usize, rows: Range<usize>, ) -> Result<Array2<f64>, BasisError>

Source

pub fn row_vector_first_into( &self, axis: usize, row: usize, out: ArrayViewMut1<'_, f64>, ) -> Result<(), BasisError>

Single-row specialization of row_chunk_first(axis, row..row+1) that writes the length-p_out row directly into the caller-provided buffer.

This is the row-local API used by CustomFamilyPsiLinearMapRef::row_vector for survival rowwise exact-Hessian paths, which previously applied a unit-vector transpose_mul trick (O(n·K) per row) to recover a single row. Avoids allocating a temporary (1 × p_out) matrix per row call.

Source

pub fn forward_mul_rows( &self, axis: usize, rows: Range<usize>, u: ArrayView1<'_, f64>, ) -> Result<Array1<f64>, BasisError>

Apply the first derivative forward map to a row block: computes result[i - rows.start] = Σ_j (∂X/∂ψ_axis)[i, j] * u[j] for each i ∈ rows.

The argument u is expressed in the final (p_out) basis. The returned vector has length rows.end - rows.start.

Source

pub fn transpose_mul_rows( &self, axis: usize, rows: Range<usize>, v: ArrayView1<'_, f64>, ) -> Result<Array1<f64>, BasisError>

Apply the first derivative adjoint to a row block: computes result[j] = Σ_{i ∈ rows} (∂X/∂ψ_axis)[i, j] * v[i - rows.start] expressed in the final p_out basis (the row_chunk_first output is already projected through the identifiability transforms).

Trait Implementations§

Source§

impl Clone for ImplicitDesignPsiDerivative

Source§

fn clone(&self) -> ImplicitDesignPsiDerivative

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 ImplicitDesignPsiDerivative

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

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,