Type Alias HistF64

Source
pub type HistF64 = HistogramFloat<f64>;
Expand description

Histogram for binning f64 - alias for HistogramFloat<f64>

Aliased Type§

struct HistF64 { /* private fields */ }

Implementations

Source§

impl<T> HistogramFloat<T>

Source

pub fn borders(&self) -> &Vec<T>

similar to self.borders_clone but does not allocate memory

Source§

impl<T> HistogramFloat<T>

Source

pub fn new(left: T, right: T, bins: usize) -> Result<Self, HistErrors>

§Create a new Histogram
  • right exclusive, left inclusive
  • if you want right to behave (almost) the same as an inclusive border, consider using new(left, right + T::EPSILON, bins) (make sure, that adding Epsilon actually changes the value!)
Source

pub fn interval_length(&self) -> T

Returns the length of the interval

Source

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);
Source

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);
Source

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

Source

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>

Source§

fn clone(&self) -> HistogramFloat<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for HistogramFloat<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> From<AtomicHistogramFloat<T>> for HistogramFloat<T>

Source§

fn from(other: AtomicHistogramFloat<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> Histogram for HistogramFloat<T>

Source§

fn bin_count(&self) -> usize

How many bins the histogram contains Read more
Source§

fn hist(&self) -> &Vec<usize>

the created histogram Read more
Source§

fn increment_index_by( &mut self, index: usize, count: usize, ) -> Result<(), HistErrors>

self.hist[index] += count, Err() if index out of bounds Read more
Source§

fn reset(&mut self)

reset the histogram to zero
Source§

fn increment_index(&mut self, index: usize) -> Result<(), HistErrors>

self.hist[index] += 1, Err() if index out of bounds Read more
Source§

fn any_bin_zero(&self) -> bool

check if any bin was not hit yet
Source§

impl<T> HistogramIntervalDistance<T> for HistogramFloat<T>

Source§

fn interval_distance_overlap<V: Borrow<T>>( &self, val: V, overlap: NonZeroUsize, ) -> usize

Distance metric for how far a value is from a valid interval Read more
Source§

impl<T> HistogramVal<T> for HistogramFloat<T>

Source§

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_iter is more efficient
Source§

fn count_val<V: Borrow<T>>(&mut self, val: V) -> Result<usize, HistErrors>

count val. Ok(index), if inside of hist, Err(_) if val is invalid
Source§

fn distance<V: Borrow<T>>(&self, val: V) -> f64

calculates some sort of absolute distance to the nearest valid bin Read more
Source§

fn first_border(&self) -> T

get the left most border (inclusive)
Source§

fn last_border(&self) -> T

get last border from the right Read more
Source§

fn last_border_is_inclusive(&self) -> bool

True if last border is inclusive, false otherwise Read more
Source§

fn is_inside<V: Borrow<T>>(&self, val: V) -> bool

does a value correspond to a valid bin?
Source§

fn not_inside<V: Borrow<T>>(&self, val: V) -> bool

opposite of is_inside
Source§

fn get_bin_index<V: Borrow<T>>(&self, val: V) -> Result<usize, HistErrors>

convert val to the respective histogram index
Source§

impl<T> Serialize for HistogramFloat<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more