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_yhasg ≥ 2finite, strictly increasing entries;hisn × gand strictly increasing along every row;h_primeisn × 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
impl CtnTransformTable
Sourcepub fn new(
grid_y: Array1<f64>,
h: Array2<f64>,
h_prime: Array2<f64>,
) -> Result<Self, String>
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.
Sourcepub fn grid_y(&self) -> ArrayView1<'_, f64>
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.
Sourcepub fn latent(&self) -> ArrayView2<'_, f64>
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.
Sourcepub fn tail_slopes(&self, row: usize) -> (f64, f64)
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.
Sourcepub fn evaluate(&self, row: usize, y: f64) -> f64
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.
Sourcepub fn invert(&self, row: usize, target: f64) -> f64
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
impl Clone for CtnTransformTable
Source§fn clone(&self) -> CtnTransformTable
fn clone(&self) -> CtnTransformTable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CtnTransformTable
impl RefUnwindSafe for CtnTransformTable
impl Send for CtnTransformTable
impl Sync for CtnTransformTable
impl Unpin for CtnTransformTable
impl UnsafeUnpin for CtnTransformTable
impl UnwindSafe for CtnTransformTable
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.