pub struct HistogramFloat<T> { /* private fields */ }Expand description
Generic Histogram struct
Implementations§
Source§impl<T> HistogramFloat<T>
impl<T> HistogramFloat<T>
Source§impl<T> HistogramFloat<T>
impl<T> HistogramFloat<T>
Sourcepub fn new(left: T, right: T, bins: usize) -> Result<Self, HistErrors>
pub fn new(left: T, right: T, bins: usize) -> Result<Self, HistErrors>
§Create a new Histogram
- right exclusive, left inclusive
- if you want
rightto 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: Borrow<T>>(&mut self, val: B) -> Result<usize, HistErrors>
pub fn increment<B: Borrow<T>>(&mut self, val: B) -> Result<usize, HistErrors>
§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: Borrow<T>>(&mut self, val: B)
pub fn increment_quiet<B: Borrow<T>>(&mut self, val: B)
§Increment hit count
Increments the hit count of the bin corresponding to val.
If no bin corresponding to val exists, nothing happens
Trait Implementations§
Source§impl<T: Clone> Clone for HistogramFloat<T>
impl<T: Clone> Clone for HistogramFloat<T>
Source§fn clone(&self) -> HistogramFloat<T>
fn clone(&self) -> HistogramFloat<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for HistogramFloat<T>
impl<T: Debug> Debug for HistogramFloat<T>
Source§impl<'de, T> Deserialize<'de> for HistogramFloat<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for HistogramFloat<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T> From<AtomicHistogramFloat<T>> for HistogramFloat<T>
impl<T> From<AtomicHistogramFloat<T>> for HistogramFloat<T>
Source§fn from(other: AtomicHistogramFloat<T>) -> Self
fn from(other: AtomicHistogramFloat<T>) -> Self
Source§impl<T> From<HistogramFloat<T>> for AtomicHistogramFloat<T>
impl<T> From<HistogramFloat<T>> for AtomicHistogramFloat<T>
Source§fn from(other: HistogramFloat<T>) -> Self
fn from(other: HistogramFloat<T>) -> Self
Source§impl<T> Histogram for HistogramFloat<T>
impl<T> Histogram for HistogramFloat<T>
Source§fn increment_index_by(
&mut self,
index: usize,
count: usize,
) -> Result<(), HistErrors>
fn increment_index_by( &mut self, index: usize, count: usize, ) -> Result<(), HistErrors>
Source§fn increment_index(&mut self, index: usize) -> Result<(), HistErrors>
fn increment_index(&mut self, index: usize) -> Result<(), HistErrors>
Source§fn any_bin_zero(&self) -> bool
fn any_bin_zero(&self) -> bool
Source§impl<T> HistogramIntervalDistance<T> for HistogramFloat<T>
impl<T> HistogramIntervalDistance<T> for HistogramFloat<T>
Source§fn interval_distance_overlap<V: Borrow<T>>(
&self,
val: V,
overlap: NonZeroUsize,
) -> usize
fn interval_distance_overlap<V: Borrow<T>>( &self, val: V, overlap: NonZeroUsize, ) -> usize
Source§impl<T> HistogramVal<T> for HistogramFloat<T>
impl<T> HistogramVal<T> for HistogramFloat<T>
Source§fn bin_enum_iter(&self) -> Box<dyn Iterator<Item = Bin<T>> + '_>
fn bin_enum_iter(&self) -> Box<dyn Iterator<Item = Bin<T>> + '_>
§consider using self.bin_iter() instead
- This gives you a dynamic iterator over all bins-
- For this type all bins are InclusiveExclusive -> Usage of
self.bin_iteris more efficient
Source§fn count_val<V: Borrow<T>>(&mut self, val: V) -> Result<usize, HistErrors>
fn count_val<V: Borrow<T>>(&mut self, val: V) -> Result<usize, HistErrors>
Ok(index), if inside of hist, Err(_) if val is invalidSource§fn distance<V: Borrow<T>>(&self, val: V) -> f64
fn distance<V: Borrow<T>>(&self, val: V) -> f64
Source§fn first_border(&self) -> T
fn first_border(&self) -> T
Source§fn last_border(&self) -> T
fn last_border(&self) -> T
Source§fn last_border_is_inclusive(&self) -> bool
fn last_border_is_inclusive(&self) -> bool
Source§fn not_inside<V: Borrow<T>>(&self, val: V) -> bool
fn not_inside<V: Borrow<T>>(&self, val: V) -> bool
is_insideSource§fn get_bin_index<V: Borrow<T>>(&self, val: V) -> Result<usize, HistErrors>
fn get_bin_index<V: Borrow<T>>(&self, val: V) -> Result<usize, HistErrors>
Auto Trait Implementations§
impl<T> Freeze for HistogramFloat<T>
impl<T> RefUnwindSafe for HistogramFloat<T>where
T: RefUnwindSafe,
impl<T> Send for HistogramFloat<T>where
T: Send,
impl<T> Sync for HistogramFloat<T>where
T: Sync,
impl<T> Unpin for HistogramFloat<T>where
T: Unpin,
impl<T> UnwindSafe for HistogramFloat<T>where
T: UnwindSafe,
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