Skip to main content

CtnTransformTable

Struct CtnTransformTable 

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

A per-row tabulation of the fitted CTN transform h(·|x_i) and its derivative on a shared response grid.

Invariants, all checked by CtnTransformTable::new:

  • grid_y has g ≥ 2 finite, strictly increasing entries;
  • h is n × g and strictly increasing along every row;
  • h_prime is n × g, finite and strictly positive everywhere.

Together these make CtnTransformTable::invert a total, strictly increasing function of the latent argument on the whole real line: the tabulated part is a monotone bracket-and-solve, and the two tails are exact affine inverses at the end slopes.

Implementations§

Source§

impl CtnTransformTable

Source

pub fn new( grid_y: Array1<f64>, h: Array2<f64>, h_prime: Array2<f64>, ) -> Result<Self, String>

Assemble a table, validating every invariant invert relies on.

The validation is not defensive decoration: a non-monotone row makes the bracketing search meaningless, and a zero or negative slope makes the affine tail inverse point the wrong way (or to infinity). Both are structurally impossible for a feasible CTN fit — h' = ε + Σ_k M_k α_k with α ≥ 0 on the monotonicity cone — so either one signals a corrupt coefficient block, and the caller should hear about it here rather than receive a silently wrong quantile.

Source

pub fn nrows(&self) -> usize

Number of covariate rows the table carries.

Source

pub fn grid_y(&self) -> ArrayView1<'_, f64>

The shared, strictly increasing response grid the transform is tabulated on. Its first and last entries are the fitted support [y_lo, y_hi], the two points the affine tails are anchored at.

Source

pub fn latent(&self) -> ArrayView2<'_, f64>

h[[i, k]] = h(grid_y[k] | x_i) — the model’s own latent, on the scale the standard normal is compared against.

Source

pub fn tail_slopes(&self, row: usize) -> (f64, f64)

(h'(y_lo | x_i), h'(y_hi | x_i)) — the slopes of row i’s two affine tails, which are just the end columns of the derivative table.

Source

pub fn evaluate(&self, row: usize, y: f64) -> f64

h(y | x_row) — the tabulated transform itself, by the same rule CtnTransformTable::invert inverts.

The forward map is part of the contract, not a convenience: without it “the inverse is the inverse of the interpolant” is not a statement anyone can check, and the only available check would be against the exact chart, which conflates a solver bug with an interpolation error.

Source

pub fn invert(&self, row: usize, target: f64) -> f64

h⁻¹(target | x_row) — the response value whose latent is target.

Outside the tabulated range the transform is affine, so the inverse is the exact affine inverse rather than the support endpoint. Inside, the bracketing cell is inverted by safeguarded Newton on its Hermite interpolant. The branches agree at the endpoints by construction (target == h[0] returns grid_y[0] from either side), so the returned quantile function is continuous and strictly increasing in target on the whole real line.

Trait Implementations§

Source§

impl Clone for CtnTransformTable

Source§

fn clone(&self) -> CtnTransformTable

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 CtnTransformTable

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> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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

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