Struct net_ensembles::sampling::histogram::HistogramFast
source · [−]pub struct HistogramFast<T> { /* private fields */ }
Expand description
Faster version of HistogramInt for Integers
provided the bins should be: (left, left +1, …, right - 1) then you should use this version!
Implementations
sourceimpl<T> HistogramFast<T>where
T: Copy,
impl<T> HistogramFast<T>where
T: Copy,
sourceimpl<T> HistogramFast<T>where
T: HasUnsignedVersion + PrimInt,
<T as HasUnsignedVersion>::Unsigned: Bounded + HasUnsignedVersion<LeBytes = <T as HasUnsignedVersion>::LeBytes> + WrappingAdd + ToPrimitive + Sub<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned>,
impl<T> HistogramFast<T>where
T: HasUnsignedVersion + PrimInt,
<T as HasUnsignedVersion>::Unsigned: Bounded + HasUnsignedVersion<LeBytes = <T as HasUnsignedVersion>::LeBytes> + WrappingAdd + ToPrimitive + Sub<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned>,
sourcepub fn new(left: T, right: T) -> Result<HistogramFast<T>, HistErrors>
pub fn new(left: T, right: T) -> Result<HistogramFast<T>, HistErrors>
Create a new interval
- same as
Self::new_inclusive(left, right - 1)
though with checks - That makes
left
an inclusive andright
an exclusive border
sourcepub fn new_inclusive(left: T, right: T) -> Result<HistogramFast<T>, HistErrors>
pub fn new_inclusive(left: T, right: T) -> Result<HistogramFast<T>, HistErrors>
Create new histogram with inclusive borders
Err
ifleft > right
left
is inclusive borderright
is inclusive border
sourcepub fn bin_iter(&self) -> impl Iterator<Item = T>
pub fn bin_iter(&self) -> impl Iterator<Item = T>
Iterator over all the bins
In HistogramFast is hit only when a value matches the corresponding bin exactly, which means there exists a map between bins and corresponding values that would hit them. So a bin is perfectly defined by one value. That is what we are iterating over here
This iterates over these values
Example
use sampling::histogram::HistogramFast;
let hist = HistogramFast::<u8>::new_inclusive(2, 5).unwrap();
let vec: Vec<u8> = hist.bin_iter().collect();
assert_eq!(&vec, &[2, 3, 4, 5]);
sourcepub fn bin_hits_iter(&self) -> impl Iterator<Item = (T, usize)>
pub fn bin_hits_iter(&self) -> impl Iterator<Item = (T, usize)>
Iterator over all the bins
In HistogramFast is hit only when a value matches the corresponding bin exactly, which means there exists a map between bins and corresponding values that would hit them.
This iterates over these values as well as the corresponding hit count (i.e., how often the corresponding bin was hit)
Item of Iterator
(value_corresponding_to_bin, number_of_hits)
Example
use sampling::histogram::HistogramFast;
let mut hist = HistogramFast::<u8>::new_inclusive(2, 5).unwrap();
hist.increment(4).unwrap();
hist.increment(5).unwrap();
hist.increment(5).unwrap();
let vec: Vec<(u8, usize)> = hist.bin_hits_iter().collect();
assert_eq!(&vec, &[(2, 0), (3, 0), (4, 1), (5, 2)]);
sourcepub fn equal_range(&self, other: &HistogramFast<T>) -> boolwhere
T: Eq,
pub fn equal_range(&self, other: &HistogramFast<T>) -> boolwhere
T: Eq,
checks if the range of two Histograms is equal, i.e., if they have the same bin borders
sourcepub fn try_add(&mut self, other: &HistogramFast<T>) -> Result<(), ()>where
T: Eq,
pub fn try_add(&mut self, other: &HistogramFast<T>) -> Result<(), ()>where
T: Eq,
Add other histogram to self
- will fail if the ranges are not equal, i.e., if equal_range returns false
- Otherwise the hitcount of the bins of self will be increased by the corresponding hitcount of other.
- other will be unchanged
sourcepub fn increment<V>(&mut self, val: V) -> Result<usize, HistErrors>where
V: Borrow<T>,
pub fn increment<V>(&mut self, val: V) -> Result<usize, HistErrors>where
V: Borrow<T>,
Increment hit count
If val
is inside the histogram, the corresponding bin count will be increased
by 1 and the index corresponding to the bin in returned: Ok(index)
.
Otherwise an Error is returned
Note
This is the same as HistogramVal::count_val
sourcepub fn increment_quiet<V>(&mut self, val: V)where
V: Borrow<T>,
pub fn increment_quiet<V>(&mut self, val: V)where
V: Borrow<T>,
Increment hit count
Increments the hit count of the bin corresponding to val
.
If no bin corresponding to val
exists, nothing happens
Trait Implementations
sourceimpl<T> Clone for HistogramFast<T>where
T: Clone,
impl<T> Clone for HistogramFast<T>where
T: Clone,
sourcefn clone(&self) -> HistogramFast<T>
fn clone(&self) -> HistogramFast<T>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<T> Debug for HistogramFast<T>where
T: Debug,
impl<T> Debug for HistogramFast<T>where
T: Debug,
sourceimpl<'de, T> Deserialize<'de> for HistogramFast<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for HistogramFast<T>where
T: Deserialize<'de>,
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<HistogramFast<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<HistogramFast<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
sourceimpl<T> Histogram for HistogramFast<T>
impl<T> Histogram for HistogramFast<T>
sourcefn count_multiple_index(
&mut self,
index: usize,
count: usize
) -> Result<(), HistErrors>
fn count_multiple_index(
&mut self,
index: usize,
count: usize
) -> Result<(), HistErrors>
self.hist[index] += count
, Err()
if index
out of boundssourcefn count_index(&mut self, index: usize) -> Result<(), HistErrors>
fn count_index(&mut self, index: usize) -> Result<(), HistErrors>
self.hist[index] += 1
, Err()
if index
out of boundssourcefn any_bin_zero(&self) -> bool
fn any_bin_zero(&self) -> bool
sourceimpl<T> HistogramCombine for HistogramFast<T>where
T: PrimInt + HasUnsignedVersion,
<T as HasUnsignedVersion>::Unsigned: Bounded + HasUnsignedVersion<LeBytes = <T as HasUnsignedVersion>::LeBytes> + WrappingAdd + ToPrimitive + Sub<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned>,
HistogramFast<T>: HistogramVal<T>,
impl<T> HistogramCombine for HistogramFast<T>where
T: PrimInt + HasUnsignedVersion,
<T as HasUnsignedVersion>::Unsigned: Bounded + HasUnsignedVersion<LeBytes = <T as HasUnsignedVersion>::LeBytes> + WrappingAdd + ToPrimitive + Sub<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned>,
HistogramFast<T>: HistogramVal<T>,
sourcefn encapsulating_hist<S>(hists: &[S]) -> Result<HistogramFast<T>, HistErrors>where
S: Borrow<HistogramFast<T>>,
fn encapsulating_hist<S>(hists: &[S]) -> Result<HistogramFast<T>, HistErrors>where
S: Borrow<HistogramFast<T>>,
sourcefn align<S>(&self, right: S) -> Result<usize, HistErrors>where
S: Borrow<HistogramFast<T>>,
fn align<S>(&self, right: S) -> Result<usize, HistErrors>where
S: Borrow<HistogramFast<T>>,
sourceimpl<T> HistogramIntervalDistance<T> for HistogramFast<T>where
HistogramFast<T>: HistogramVal<T>,
T: PartialOrd<T> + Sub<T, Output = T> + NumCast + Copy,
impl<T> HistogramIntervalDistance<T> for HistogramFast<T>where
HistogramFast<T>: HistogramVal<T>,
T: PartialOrd<T> + Sub<T, Output = T> + NumCast + Copy,
sourcefn interval_distance_overlap<V>(&self, val: V, overlap: NonZeroUsize) -> usizewhere
V: Borrow<T>,
fn interval_distance_overlap<V>(&self, val: V, overlap: NonZeroUsize) -> usizewhere
V: Borrow<T>,
sourceimpl<T> HistogramPartition for HistogramFast<T>where
T: ToPrimitive + CheckedAdd + One + FromPrimitive + HasUnsignedVersion + Bounded + PrimInt + CheckedSub,
<T as HasUnsignedVersion>::Unsigned: Bounded + HasUnsignedVersion<LeBytes = <T as HasUnsignedVersion>::LeBytes, Unsigned = <T as HasUnsignedVersion>::Unsigned> + WrappingAdd + ToPrimitive + Sub<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned> + FromPrimitive + WrappingSub,
impl<T> HistogramPartition for HistogramFast<T>where
T: ToPrimitive + CheckedAdd + One + FromPrimitive + HasUnsignedVersion + Bounded + PrimInt + CheckedSub,
<T as HasUnsignedVersion>::Unsigned: Bounded + HasUnsignedVersion<LeBytes = <T as HasUnsignedVersion>::LeBytes, Unsigned = <T as HasUnsignedVersion>::Unsigned> + WrappingAdd + ToPrimitive + Sub<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned> + FromPrimitive + WrappingSub,
sourcefn overlapping_partition(
&self,
n: usize,
overlap: usize
) -> Result<Vec<HistogramFast<T>, Global>, HistErrors>
fn overlapping_partition(
&self,
n: usize,
overlap: usize
) -> Result<Vec<HistogramFast<T>, Global>, HistErrors>
sourceimpl<T> HistogramVal<T> for HistogramFast<T>where
T: HasUnsignedVersion + PrimInt,
<T as HasUnsignedVersion>::Unsigned: Bounded + HasUnsignedVersion<LeBytes = <T as HasUnsignedVersion>::LeBytes> + WrappingAdd + ToPrimitive + Sub<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned>,
impl<T> HistogramVal<T> for HistogramFast<T>where
T: HasUnsignedVersion + PrimInt,
<T as HasUnsignedVersion>::Unsigned: Bounded + HasUnsignedVersion<LeBytes = <T as HasUnsignedVersion>::LeBytes> + WrappingAdd + ToPrimitive + Sub<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned>,
sourcefn borders_clone(&self) -> Result<Vec<T, Global>, HistErrors>
fn borders_clone(&self) -> Result<Vec<T, Global>, HistErrors>
Creates a vector containing borders
How to understand the borders?
Lets say we have a Vector containing [a,b,c]
,
then the first bin contains all values T
for which
a <= T < b
, the second bin all values T
for which
b <= T < c
. In this case, there are only two bins.
Errors
- returns
Err(Overflow)
if right border isT::MAX
- creates and returns borders otherwise
- Note: even if
Err(Overflow)
is returned, this does not provide any problems for the rest of the implementation, as the border vector is not used internally forHistogramFast
sourcefn first_border(&self) -> T
fn first_border(&self) -> T
sourcefn second_last_border(&self) -> T
fn second_last_border(&self) -> T
let b = self.borders_clone().expect("overflow"); assert_eq!(self.second_last_border(), b[b.len()-2])
sourcefn distance<V>(&self, val: V) -> f64where
V: Borrow<T>,
fn distance<V>(&self, val: V) -> f64where
V: Borrow<T>,
sourcefn get_bin_index<V>(&self, val: V) -> Result<usize, HistErrors>where
V: Borrow<T>,
fn get_bin_index<V>(&self, val: V) -> Result<usize, HistErrors>where
V: Borrow<T>,
sourcefn is_inside<V>(&self, val: V) -> boolwhere
V: Borrow<T>,
fn is_inside<V>(&self, val: V) -> boolwhere
V: Borrow<T>,
sourcefn not_inside<V>(&self, val: V) -> boolwhere
V: Borrow<T>,
fn not_inside<V>(&self, val: V) -> boolwhere
V: Borrow<T>,
is_inside