pub struct LatentZRankIntCalibration {
pub sorted_z: Vec<f64>,
pub weighted_cdf: Vec<f64>,
pub post_mean: f64,
pub post_sd: f64,
}Expand description
Blom-rankit weighted rank inverse-normal transform for the latent score.
When the latent z fails the standard-normal auto-detection
([latent_z_is_standard_normal_enough]), the BMS family applied to
pretend the score is N(0,1) anyway would distort the closed-form
probit log-CDF kernel. The historical fallback (local- or
global-empirical latent measure) is mathematically correct but
triggers the per-row intercept Newton solve in the empirical-grid
closed-form kernels (empirical_rigid_primary_grad_hess_closed_form
and its higher-order siblings); at large scale that is the dominant
cost.
Rank-INT is exact under monotone re-parameterisation. The Blom rankit assigns
each sorted training z the rank-probability
(W_i − 0.375) / (W_total + 0.25), then maps that probability
through Φ⁻¹. The transform is strictly monotone on the
observed support, so the BMS likelihood is invariant up to a
re-parameterisation (the model is a transformation-equivariant
family on the latent axis). The transformed sample is exactly
N(0,1) by construction, so the standard-normal closed-form kernel
is exact on the calibrated scale. The kept work is the same
closed-form signed_probit_logcdf_and_mills_ratio evaluation as
the no-calibration path; the dropped work is the empirical-grid
jet machinery. Persisted to disk so prediction applies the same
monotone map to incoming z and re-routes through the closed-form
kernel.
Fields§
§sorted_z: Vec<f64>Sorted unique z values seen during training, ascending. Knot table
for apply_to_training / apply_at_predict.
weighted_cdf: Vec<f64>Weighted cumulative-distribution-function values at each
sorted_z knot, in [eps, 1 - eps] with
eps = 0.5 / W_total. Strictly increasing.
post_mean: f64Weighted mean of the calibrated training sample. Used as a
sanity-check value on fit; should be very close to zero.
post_sd: f64Weighted SD of the calibrated training sample. Used as a
sanity-check value on fit; should be very close to one.
Implementations§
Source§impl LatentZRankIntCalibration
impl LatentZRankIntCalibration
Sourcepub fn fit(z: &Array1<f64>, weights: &Array1<f64>) -> Result<Self, String>
pub fn fit(z: &Array1<f64>, weights: &Array1<f64>) -> Result<Self, String>
Fit the weighted rank-INT calibration from training z and weights.
Algorithm:
- Sort rows by ascending z.
- Compute cumulative weight
W_iat each sorted row. - Blom-rankit cumulative probability:
p_i = (W_i − 0.375) / (W_total + 0.25). - Clip to
[eps, 1 − eps]witheps = 0.5 / W_total. - Store
(sorted_z, weighted_cdf = p_i).
Returns the calibration plus the post-transform sample’s weighted mean / SD for sanity-check logging.
Sourcepub fn apply_to_training(&self, z: &Array1<f64>) -> Result<Array1<f64>, String>
pub fn apply_to_training(&self, z: &Array1<f64>) -> Result<Array1<f64>, String>
Apply the calibration to the full training z vector, returning the
calibrated sample. Equivalent to mapping each row’s z through
Self::apply_at_predict, but vectorised.
Sourcepub fn apply_at_predict(&self, z: f64) -> f64
pub fn apply_at_predict(&self, z: f64) -> f64
Apply the calibration to a single z at predict time.
Linear interpolation on (sorted_z, weighted_cdf) to obtain
p ∈ [eps, 1 − eps], then Φ⁻¹(p) via
standard_normal_quantile. Out-of-range z’s clip to the
boundary CDF before the quantile, so the calibration extrapolates
monotonically beyond the training support.
Trait Implementations§
Source§impl Clone for LatentZRankIntCalibration
impl Clone for LatentZRankIntCalibration
Source§fn clone(&self) -> LatentZRankIntCalibration
fn clone(&self) -> LatentZRankIntCalibration
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LatentZRankIntCalibration
impl Debug for LatentZRankIntCalibration
Source§impl<'de> Deserialize<'de> for LatentZRankIntCalibration
impl<'de> Deserialize<'de> for LatentZRankIntCalibration
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for LatentZRankIntCalibration
impl PartialEq for LatentZRankIntCalibration
Source§fn eq(&self, other: &LatentZRankIntCalibration) -> bool
fn eq(&self, other: &LatentZRankIntCalibration) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for LatentZRankIntCalibration
Auto Trait Implementations§
impl Freeze for LatentZRankIntCalibration
impl RefUnwindSafe for LatentZRankIntCalibration
impl Send for LatentZRankIntCalibration
impl Sync for LatentZRankIntCalibration
impl Unpin for LatentZRankIntCalibration
impl UnsafeUnpin for LatentZRankIntCalibration
impl UnwindSafe for LatentZRankIntCalibration
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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,
impl<T> Scalar for T
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.