Skip to main content

Histogram

Struct Histogram 

Source
pub struct Histogram { /* private fields */ }
Expand description

A simple weighted histogram with explicit bin edges.

Implementations§

Source§

impl Histogram

Source

pub fn new(counts: Vec<f64>, bin_edges: Vec<f64>) -> LadduPhysicsResult<Self>

Construct and validate a histogram from weighted bin counts and bin edges.

The argument order matches numpy.histogram, so its result can be forwarded directly.

§Errors

Returns LadduPhysicsError when counts or edges are non-finite, the edge count is inconsistent with the bins, or edges are not increasing.

Source

pub fn new_with_flow( counts: Vec<f64>, bin_edges: Vec<f64>, underflow: f64, overflow: f64, ) -> LadduPhysicsResult<Self>

Construct a histogram including explicit underflow and overflow weights.

§Errors

Returns LadduPhysicsError when counts, flow weights, or edges are non-finite, lengths are inconsistent, or edges are not increasing.

Source

pub fn empty(bins: usize, limits: (f64, f64)) -> LadduPhysicsResult<Self>

Construct an empty, uniformly binned histogram.

§Errors

Returns LadduPhysicsError when bins is zero or the limits are non-finite or not increasing.

Source

pub fn empty_with_edges(bin_edges: Vec<f64>) -> LadduPhysicsResult<Self>

Construct an empty histogram from explicit bin edges.

§Errors

Returns LadduPhysicsError when fewer than two finite, strictly increasing edges are supplied.

Source

pub fn from_values( values: &[f64], bins: usize, limits: (f64, f64), weights: Option<&[f64]>, ) -> LadduPhysicsResult<Self>

Fill a uniformly binned histogram from values and optional weights.

§Errors

Returns LadduPhysicsError when histogram geometry is invalid, weights have the wrong length, or a value or weight is non-finite.

Source

pub fn from_values_with_edges( values: &[f64], bin_edges: Vec<f64>, weights: Option<&[f64]>, ) -> LadduPhysicsResult<Self>

Fill an explicitly binned histogram from values and optional weights.

§Errors

Returns LadduPhysicsError when edges are invalid, weights have the wrong length, or a value or weight is non-finite.

Source

pub fn set_errors(&mut self, errors: &[f64]) -> LadduPhysicsResult<()>

Replace the uncertainties on all bins.

§Errors

Returns LadduPhysicsError when errors has the wrong length or contains a negative or non-finite uncertainty.

Source

pub fn fill(&mut self, value: f64) -> LadduPhysicsResult<()>

Add one unit-weight entry.

§Errors

Returns LadduPhysicsError when value is non-finite.

Source

pub fn fill_weighted( &mut self, value: f64, weight: f64, ) -> LadduPhysicsResult<()>

Add an entry with an explicit weight.

§Errors

Returns LadduPhysicsError when value or weight is non-finite.

§Panics

Panics if this histogram’s validated edge list is unexpectedly empty.

Source

pub fn fill_with_error( &mut self, value: f64, error: f64, ) -> LadduPhysicsResult<()>

Add one unit-weight entry with the given entry uncertainty.

§Errors

Returns LadduPhysicsError when value is non-finite or error is negative or non-finite.

Source

pub fn fill_weighted_with_error( &mut self, value: f64, weight: f64, error: f64, ) -> LadduPhysicsResult<()>

Add an entry with an explicit weight and uncertainty.

§Errors

Returns LadduPhysicsError when value or weight is non-finite, or error is negative or non-finite.

§Panics

Panics if this histogram’s validated edge list is unexpectedly empty.

Source

pub fn counts(&self) -> &[f64]

Return the number of weighted counts in each bin.

Source

pub fn set_counts(&mut self, counts: &[f64]) -> LadduPhysicsResult<()>

Replace the contents of all bins without changing their uncertainties.

§Errors

Returns LadduPhysicsError when counts has the wrong length or contains a non-finite value.

Source

pub fn set_count( &mut self, bin_index: usize, value: f64, ) -> LadduPhysicsResult<()>

Manually set the counts in a bin.

§Errors

Returns LadduPhysicsError when bin_index is out of range or value is non-finite.

Source

pub fn set_error( &mut self, bin_index: usize, error: f64, ) -> LadduPhysicsResult<()>

Manually set the uncertainty in a bin.

§Errors

Returns LadduPhysicsError when bin_index is out of range or error is negative or non-finite.

Source

pub fn errors(&self) -> &[f64]

Return the uncertainties on each bin.

§Note

Histograms filled from values use the square root of the sum of squared weights. Histograms constructed from counts default to sqrt(abs(count)).

Source

pub fn bin_edges(&self) -> &[f64]

Return the bin edges.

Source

pub fn underflow(&self) -> f64

Return the accumulated underflow weight.

Source

pub fn overflow(&self) -> f64

Return the accumulated overflow weight.

Source

pub fn total_weight(&self) -> f64

Return the total histogram weight.

Source

pub fn total_weight_with_flow(&self) -> f64

Return total weight including underflow and overflow.

Source

pub fn limits(&self) -> (f64, f64)

Return the lowest and highest bin edges.

Source

pub fn bins(&self) -> usize

Return the number of bins.

Source

pub fn bin_index(&self, value: f64) -> Option<usize>

Return the bin index for a value.

The lower edge is inclusive and the upper edge is exclusive.

Source

pub fn normalized(&self) -> LadduPhysicsResult<Self>

Return a normalized histogram whose in-range bin counts sum to 1.

Underflow and overflow are discarded because they are outside the histogram domain.

Negative bin counts are allowed, so this is an algebraic normalization, not necessarily a probability distribution.

§Errors

Returns LadduPhysicsError when the histogram is invalid or has zero or non-finite in-range total weight.

Source

pub fn normalized_with_flow(&self) -> LadduPhysicsResult<Self>

Return a normalized histogram whose bins plus underflow/overflow sum to 1.

Negative counts are allowed, so this is algebraic normalization, not necessarily a probability distribution.

§Errors

Returns LadduPhysicsError when the histogram is invalid or has zero or non-finite total weight including flow bins.

Source

pub fn density(&self) -> LadduPhysicsResult<Self>

Return a probability density histogram.

Requires nonnegative in-range counts. Underflow and overflow are discarded because they do not have finite bin widths.

§Errors

Returns LadduPhysicsError when bin counts are negative or non-finite, or their in-range total is not positive and finite.

Source

pub fn signed_density(&self) -> LadduPhysicsResult<Self>

Return a signed density histogram.

This allows negative weights and is useful for weighted MC, interference terms, or background-subtracted histograms. It should not be sampled from.

§Errors

Returns LadduPhysicsError when the histogram is invalid or has zero or non-finite in-range total weight.

Source

pub fn sample(&self, rng: &mut Rng) -> LadduPhysicsResult<f64>

Sample a value from the histogram, assuming counts define bin probabilities.

Samples uniformly within the selected bin.

§Errors

Returns LadduPhysicsError when counts are negative or non-finite, or their total is not positive and finite.

Source

pub fn bin_center(&self, index: usize) -> Option<f64>

Return the center of a bin.

Trait Implementations§

Source§

impl Clone for Histogram

Source§

fn clone(&self) -> Histogram

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Histogram

Source§

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

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

impl<'de> Deserialize<'de> for Histogram

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 PartialEq for Histogram

Source§

fn eq(&self, other: &Histogram) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Histogram

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
Source§

impl StructuralPartialEq for Histogram

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.