Struct net_ensembles::sampling::HistogramFloat
source · [−]pub struct HistogramFloat<T> { /* private fields */ }
Expand description
Generic Histogram struct
Implementations
sourceimpl<T> HistogramFloat<T>
impl<T> HistogramFloat<T>
sourceimpl<T> HistogramFloat<T>where
T: Float + PartialOrd<T> + FromPrimitive,
impl<T> HistogramFloat<T>where
T: Float + PartialOrd<T> + FromPrimitive,
sourcepub fn new(
left: T,
right: T,
bins: usize
) -> Result<HistogramFloat<T>, HistErrors>
pub fn new(
left: T,
right: T,
bins: usize
) -> Result<HistogramFloat<T>, HistErrors>
Create a new Historgram
- right exclusive, left inclusive
- if you want
right
to behave (almost) the same as an inclusive border, consider usingnew(left, right + T::EPSILON, bins)
(make sure, that adding Epsilon actually changes the value!)
sourcepub fn interval_length(&self) -> T
pub fn interval_length(&self) -> T
Returns the length of the interval
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 HistogramFloat 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 = HistogramFloat::<f32>::new(0.0, 1.0, 2).unwrap();
let mut iter = hist.bin_iter();
assert_eq!(iter.next(), Some(&[0.0, 0.5]));
assert_eq!(iter.next(), Some(&[0.5, 1.0]));
assert_eq!(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 HistogramFloat a bin is defined by two values: The left border (inclusive) and the right border (exclusive)
This Iterator iterates over these values as well as the corresponding hit count ( i.e., how often a bin was hit)
Item of Iterator
(&[left_border, right_border], number_of_hits)
Example
use sampling::histogram::*;
let mut hist = HistogramFloat::<f64>::new(0.0, 1.0, 2).unwrap();
hist.increment_quiet(0.5);
hist.increment_quiet(0.71253782387);
let mut iter = hist.bin_hits_iter();
assert_eq!(iter.next(), Some((&[0.0, 0.5], 0)));
assert_eq!(iter.next(), Some((&[0.5, 1.0], 2)));
assert_eq!(iter.next(), None);
sourcepub fn increment<B>(&mut self, val: B) -> Result<usize, HistErrors>where
B: Borrow<T>,
pub fn increment<B>(&mut self, val: B) -> Result<usize, HistErrors>where
B: Borrow<T>,
Increment hit count of bin
This will increment the hit count of the bin corresponding to the value val
.
If the bin was valid it will return the index of the corresponding bin
sourcepub fn increment_quiet<B>(&mut self, val: B)where
B: Borrow<T>,
pub fn increment_quiet<B>(&mut self, val: B)where
B: 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 HistogramFloat<T>where
T: Clone,
impl<T> Clone for HistogramFloat<T>where
T: Clone,
sourcefn clone(&self) -> HistogramFloat<T>
fn clone(&self) -> HistogramFloat<T>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<T> Debug for HistogramFloat<T>where
T: Debug,
impl<T> Debug for HistogramFloat<T>where
T: Debug,
sourceimpl<'de, T> Deserialize<'de> for HistogramFloat<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for HistogramFloat<T>where
T: Deserialize<'de>,
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<HistogramFloat<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<HistogramFloat<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
sourceimpl<T> From<AtomicHistogramFloat<T>> for HistogramFloat<T>
impl<T> From<AtomicHistogramFloat<T>> for HistogramFloat<T>
sourcefn from(other: AtomicHistogramFloat<T>) -> HistogramFloat<T>
fn from(other: AtomicHistogramFloat<T>) -> HistogramFloat<T>
sourceimpl<T> From<HistogramFloat<T>> for AtomicHistogramFloat<T>
impl<T> From<HistogramFloat<T>> for AtomicHistogramFloat<T>
sourcefn from(other: HistogramFloat<T>) -> AtomicHistogramFloat<T>
fn from(other: HistogramFloat<T>) -> AtomicHistogramFloat<T>
sourceimpl<T> Histogram for HistogramFloat<T>
impl<T> Histogram for HistogramFloat<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 HistogramFloat<T>where
T: Float + FromPrimitive + Zero + NumCast,
impl<T> HistogramIntervalDistance<T> for HistogramFloat<T>where
T: Float + FromPrimitive + Zero + NumCast,
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> HistogramVal<T> for HistogramFloat<T>where
T: Float + Zero + NumCast,
impl<T> HistogramVal<T> for HistogramFloat<T>where
T: Float + Zero + NumCast,
sourcefn borders_clone(&self) -> Result<Vec<T, Global>, HistErrors>
fn borders_clone(&self) -> Result<Vec<T, Global>, HistErrors>
consider using self.borders()
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