Struct net_ensembles::sampling::HistogramInt
source · [−]pub struct HistogramInt<T> { /* private fields */ }
Expand description
Implementations
sourceimpl<T> HistogramInt<T>
impl<T> HistogramInt<T>
sourcepub fn borders(&self) -> &Vec<T, Global>
pub fn borders(&self) -> &Vec<T, Global>
similar to self.borders_clone
but does not allocate memory
sourcepub fn bin_iter(&self) -> impl Iterator<Item = &[T; 2]>
pub fn bin_iter(&self) -> impl Iterator<Item = &[T; 2]>
Iterator over all the bins
In HistogramInt a bin is defined by two values: The left border (inclusive) and the right border (exclusive)
Here you get an iterator which iterates over said borders. The Iterator returns a borrowed Array of length two, where the first value is the left (inclusive) border and the second value is the right (exclusive) border
Example
use sampling::histogram::*;
let hist = HistI8::new(0, 8, 4).unwrap();
let mut bin_iter = hist.bin_iter();
assert_eq!(bin_iter.next(), Some(&[0_i8, 2]));
assert_eq!(bin_iter.next(), Some(&[2, 4]));
assert_eq!(bin_iter.next(), Some(&[4, 6]));
assert_eq!(bin_iter.next(), Some(&[6, 8]));
assert_eq!(bin_iter.next(), None);
sourcepub fn bin_hits_iter(&self) -> impl Iterator<Item = (&[T; 2], usize)>
pub fn bin_hits_iter(&self) -> impl Iterator<Item = (&[T; 2], usize)>
Iterate over all bins
In HistogramInt a bin is defined by two values: The left border (inclusive) and the right border (exclusive)
This iterates over these values as well as the corresponding hit count (i.e. how often the corresponding bin was hit)
Item of Iterator
(&[left_border, right_border], number_of_hits)
Example
use sampling::histogram::*;
let mut hist = HistUsize::new(0, 6, 3).unwrap();
hist.increment(0).unwrap();
hist.increment(5).unwrap();
hist.increment(4).unwrap();
let mut iter = hist.bin_hits_iter();
assert_eq!(
iter.next(),
Some(
(&[0, 2], 1)
)
);
assert_eq!(
iter.next(),
Some(
(&[2, 4], 0)
)
);
assert_eq!(
iter.next(),
Some(
(&[4, 6], 2)
)
);
assert_eq!(iter.next(), None);
sourceimpl<T> HistogramInt<T>where
T: Add<T, Output = T> + Ord + One + Copy + NumCast + Sub<T, Output = T>,
impl<T> HistogramInt<T>where
T: Add<T, Output = T> + Ord + One + Copy + NumCast + Sub<T, Output = T>,
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
sourceimpl<T> HistogramInt<T>where
T: Zero + Copy + PartialOrd<T> + ToPrimitive + FromPrimitive + CheckedAdd + One<Output = T> + HasUnsignedVersion + Bounded + Sub<T, Output = T> + Mul<T>,
RangeInclusive<T>: Iterator<Item = T>,
<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> + Rem<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned> + FromPrimitive + Zero + Eq + Div<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned> + Ord + Mul<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned> + WrappingSub + Copy,
RangeInclusive<<T as HasUnsignedVersion>::Unsigned>: Iterator<Item = <T as HasUnsignedVersion>::Unsigned>,
impl<T> HistogramInt<T>where
T: Zero + Copy + PartialOrd<T> + ToPrimitive + FromPrimitive + CheckedAdd + One<Output = T> + HasUnsignedVersion + Bounded + Sub<T, Output = T> + Mul<T>,
RangeInclusive<T>: Iterator<Item = T>,
<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> + Rem<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned> + FromPrimitive + Zero + Eq + Div<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned> + Ord + Mul<<T as HasUnsignedVersion>::Unsigned, Output = <T as HasUnsignedVersion>::Unsigned> + WrappingSub + Copy,
RangeInclusive<<T as HasUnsignedVersion>::Unsigned>: Iterator<Item = <T as HasUnsignedVersion>::Unsigned>,
sourcepub fn new(left: T, right: T, bins: usize) -> Result<HistogramInt<T>, HistErrors>
pub fn new(left: T, right: T, bins: usize) -> Result<HistogramInt<T>, HistErrors>
Create a new histogram
right
: exclusive borderleft
: inclusive borderbins
: how many bins do you need?
Note
(right - left) % bins == 0
has to be true, otherwise the bins cannot all have the same length!
sourcepub fn new_inclusive(
left: T,
right: T,
bins: usize
) -> Result<HistogramInt<T>, HistErrors>
pub fn new_inclusive(
left: T,
right: T,
bins: usize
) -> Result<HistogramInt<T>, HistErrors>
Create a new histogram
- equivalent to
Self::new(left, right + 1, bins)
(except that this method checks for possible overflow)
Note:
- Due to implementation details,
right
cannot beT::MAX
- if you try, you will getErr(HistErrors::Overflow)
Trait Implementations
sourceimpl<T> Clone for HistogramInt<T>where
T: Clone,
impl<T> Clone for HistogramInt<T>where
T: Clone,
sourcefn clone(&self) -> HistogramInt<T>
fn clone(&self) -> HistogramInt<T>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<T> Debug for HistogramInt<T>where
T: Debug,
impl<T> Debug for HistogramInt<T>where
T: Debug,
sourceimpl<'de, T> Deserialize<'de> for HistogramInt<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for HistogramInt<T>where
T: Deserialize<'de>,
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<HistogramInt<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<HistogramInt<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
sourceimpl<T> From<AtomicHistogramInt<T>> for HistogramInt<T>
impl<T> From<AtomicHistogramInt<T>> for HistogramInt<T>
sourcefn from(other: AtomicHistogramInt<T>) -> HistogramInt<T>
fn from(other: AtomicHistogramInt<T>) -> HistogramInt<T>
sourceimpl<T> From<HistogramInt<T>> for AtomicHistogramInt<T>
impl<T> From<HistogramInt<T>> for AtomicHistogramInt<T>
sourcefn from(other: HistogramInt<T>) -> AtomicHistogramInt<T>
fn from(other: HistogramInt<T>) -> AtomicHistogramInt<T>
sourceimpl<T> Histogram for HistogramInt<T>
impl<T> Histogram for HistogramInt<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> HistogramIntervalDistance<T> for HistogramInt<T>where
T: Sub<T, Output = T> + Add<T, Output = T> + One + NumCast + Copy + Ord,
impl<T> HistogramIntervalDistance<T> for HistogramInt<T>where
T: Sub<T, Output = T> + Add<T, Output = T> + One + NumCast + Copy + Ord,
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 HistogramInt<T>where
T: Clone + Debug,
impl<T> HistogramPartition for HistogramInt<T>where
T: Clone + Debug,
sourcefn overlapping_partition(
&self,
n: usize,
overlap: usize
) -> Result<Vec<HistogramInt<T>, Global>, HistErrors>
fn overlapping_partition(
&self,
n: usize,
overlap: usize
) -> Result<Vec<HistogramInt<T>, Global>, HistErrors>
sourceimpl<T> HistogramVal<T> for HistogramInt<T>where
T: Sub<T, Output = T> + Add<T, Output = T> + One + NumCast + Copy + Ord,
impl<T> HistogramVal<T> for HistogramInt<T>where
T: Sub<T, Output = T> + Add<T, Output = T> + One + NumCast + Copy + Ord,
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>,
None if not inside Hist covered zone
sourcefn count_val<V>(&mut self, val: V) -> Result<usize, HistErrors>where
V: Borrow<T>,
fn count_val<V>(&mut self, val: V) -> Result<usize, HistErrors>where
V: Borrow<T>,
Ok(index)
, if inside of hist, Err(_)
if val is invalidsourcefn distance<V>(&self, val: V) -> f64where
V: Borrow<T>,
fn distance<V>(&self, val: V) -> f64where
V: Borrow<T>,
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 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