pub struct FeatureHistogram {
pub grad_sums: Vec<f64>,
pub hess_sums: Vec<f64>,
pub counts: Vec<u64>,
pub edges: BinEdges,
/* private fields */
}alloc only.Expand description
Histogram for a single feature: accumulates grad/hess/count per bin. SoA layout for cache efficiency during split-point evaluation.
Fields§
§grad_sums: Vec<f64>Gradient sums per bin.
When decay_scale != 1.0, these are stored in un-decayed coordinates.
Multiply by decay_scale to recover effective (decayed) values.
hess_sums: Vec<f64>Hessian sums per bin (same scaling convention as grad_sums).
counts: Vec<u64>Sample counts per bin (never decayed).
edges: BinEdgesBin edges for this feature.
Implementations§
Source§impl FeatureHistogram
impl FeatureHistogram
Sourcepub fn accumulate(&mut self, value: f64, gradient: f64, hessian: f64)
pub fn accumulate(&mut self, value: f64, gradient: f64, hessian: f64)
Accumulate a single sample into the appropriate bin.
Finds the bin for value using the stored edges, then adds the
gradient, hessian, and increments the count for that bin.
Sourcepub fn total_gradient(&self) -> f64
pub fn total_gradient(&self) -> f64
Sum of all gradient accumulators across bins.
Accounts for any pending lazy decay by multiplying by decay_scale.
Sourcepub fn total_hessian(&self) -> f64
pub fn total_hessian(&self) -> f64
Sum of all hessian accumulators across bins.
Accounts for any pending lazy decay by multiplying by decay_scale.
Sourcepub fn total_count(&self) -> u64
pub fn total_count(&self) -> u64
Total sample count across all bins.
Sourcepub fn accumulate_with_decay(
&mut self,
value: f64,
gradient: f64,
hessian: f64,
alpha: f64,
)
pub fn accumulate_with_decay( &mut self, value: f64, gradient: f64, hessian: f64, alpha: f64, )
Accumulate with lazy forward decay: O(1) per sample.
Implements the forward decay scheme (Cormode et al. 2009) using a
deferred scaling technique. Instead of decaying all bins on every
sample, we track a running decay_scale and store new samples in
un-decayed coordinates. The actual bin values are materialized only
when read (see materialize_decay()).
Mathematically equivalent to eager decay: a gradient g added at
epoch t contributes g * alpha^(T - t) at read time T.
The counts array is NOT decayed – it tracks the raw sample count
for the Hoeffding bound computation.
Sourcepub fn materialize_decay(&mut self)
pub fn materialize_decay(&mut self)
Apply the pending decay factor to all bins and reset the scale.
After calling this, grad_sums and hess_sums contain the true
decayed values and can be passed directly to split evaluation.
O(n_bins) – called at split evaluation time, not per sample.
Sourcepub fn subtract(&self, child: &FeatureHistogram) -> FeatureHistogram
pub fn subtract(&self, child: &FeatureHistogram) -> FeatureHistogram
Histogram subtraction trick: self - child = sibling.
When building a tree, if you know the parent histogram and one child’s histogram, you can derive the other child by subtraction rather than re-scanning the data. This halves the histogram-building cost at each split.
Scale-aware: if either operand has pending lazy decay, the effective
(decayed) values are used. The result has decay_scale = 1.0.
The returned histogram uses edges cloned from self.
Trait Implementations§
Source§impl Clone for FeatureHistogram
impl Clone for FeatureHistogram
Source§fn clone(&self) -> FeatureHistogram
fn clone(&self) -> FeatureHistogram
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 FeatureHistogram
impl RefUnwindSafe for FeatureHistogram
impl Send for FeatureHistogram
impl Sync for FeatureHistogram
impl Unpin for FeatureHistogram
impl UnsafeUnpin for FeatureHistogram
impl UnwindSafe for FeatureHistogram
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more