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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more