Skip to main content

OuterScoreSubsample

Struct OuterScoreSubsample 

Source
pub struct OuterScoreSubsample {
    pub mask: Arc<Vec<usize>>,
    pub rows: Arc<Vec<WeightedOuterRow>>,
    pub n_full: usize,
    pub weight_scale: f64,
    pub seed: u64,
}
Expand description

Stratified row index subsample shared across outer-loop evaluations.

mask is sorted, deduplicated, and never empty in practice (enforced by build_outer_score_subsample).

Per-row inverse-inclusion weights w_i = N_h / k_h (where h is the row’s stratum) are stored alongside the mask in rows. The Horvitz–Thompson estimator for any linear-in-row functional T = Σ_i f_i is T̂ = Σ_{i ∈ mask} w_i · f_i, which is unbiased even when per-stratum sampling fractions differ (the ceil(k * N_h / n).max(1) rule in the stratified builder makes rare strata oversample relative to the bulk, so a single global rescale n_full / |mask| is biased in those strata).

weight_scale is retained as a diagnostic (mean of w_i across the mask). It equals n_full / |mask| when all rows share a uniform inclusion probability (the caller-supplied-mask case represented by OuterScoreSubsample::from_uniform_inclusion_mask); it can drift from that value under the stratified builder’s rare-stratum boost. It is not the per-row scaling factor — consumers must read rows[i].weight for HT correctness.

§Horvitz–Thompson contract

Per-row weight rows[i].weight = 1 / π_i, where π_i is the inclusion probability of row i under the stratified sampler. Any outer-only score/gradient routine that consumes this subsample must form Σ_{i ∈ mask} w_i · f_i so the resulting estimator is unbiased:

  E[ score_subsample ]  =  score_full.

The following families consume this subsample on their outer-loop hot paths: Gaussian-LS, Binomial-LS, the Wiggle variants, CTN, and Survival-LS. Each routes the rows[i].weight factor through its per-row accumulator (gradient, Hessian-action, trace probes).

§Convergence warning

Subsampled gradients are noisy by construction. The outer driver must never declare convergence on a subsampled gradient — near convergence it switches back to the full-data score so that the KKT stopping test sees the unbiased, low-variance signal. New consumers adding subsampled paths must preserve this invariant.

Fields§

§mask: Arc<Vec<usize>>§rows: Arc<Vec<WeightedOuterRow>>§n_full: usize§weight_scale: f64§seed: u64

Implementations§

Source§

impl OuterScoreSubsample

Source

pub fn from_uniform_inclusion_mask( mask: Vec<usize>, n_full: usize, seed: u64, ) -> Self

Wrap a precomputed mask sampled with a uniform inclusion probability, assigning each selected row the inverse-inclusion weight n_full / m. The caller is responsible for sortedness and uniqueness; build_outer_score_subsample remains the stratified per-row HT builder.

Source

pub fn with_uniform_weight( mask: Vec<usize>, n_full: usize, seed: u64, weight: f64, ) -> Self

Wrap a precomputed mask with an explicit uniform per-row weight. Useful for tests that need the unrescaled (weight = 1.0) sum over a custom mask, and for callers that already know the desired rescaling factor and don’t want the constructor to derive it from n_full / |mask|.

Source

pub fn from_weighted_rows( rows: Vec<WeightedOuterRow>, n_full: usize, seed: u64, ) -> Self

Wrap a vector of (index, weight, stratum) triples. The mask is derived as the sorted/dedup’d index list. Used by the stratified builder to install per-row HT weights.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn has_variable_weights(&self) -> bool

True when at least two retained rows have different per-row weights. Consumers that previously applied a single post-sum scalar must switch to per-row weighting whenever this returns true.

Trait Implementations§

Source§

impl Clone for OuterScoreSubsample

Source§

fn clone(&self) -> OuterScoreSubsample

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 OuterScoreSubsample

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