Struct rgsl::types::histograms::HistogramPdf
source · [−]pub struct HistogramPdf { /* private fields */ }
Expand description
The probability distribution function for a histogram consists of a set of bins which measure the probability of an event falling into a given range of a continuous variable x. A probability distribution function is defined by the following struct, which actually stores the cumulative probability distribution function. This is the natural quantity for generating samples via the inverse transform method, because there is a one-to-one mapping between the cumulative probability distribution and the range [0,1]. It can be shown that by taking a uniform random number in this range and finding its corresponding coordinate in the cumulative probability distribution we obtain samples with the desired probability distribution.
Implementations
sourceimpl HistogramPdf
impl HistogramPdf
sourcepub fn new(n: usize) -> Option<HistogramPdf>
pub fn new(n: usize) -> Option<HistogramPdf>
This function allocates memory for a probability distribution with n bins and returns a pointer to a newly initialized gsl_histogram_pdf struct. If insufficient memory is available a null pointer is returned and the error handler is invoked with an error code of Value::NoMem.
sourcepub fn init(&mut self, h: &Histogram) -> Value
pub fn init(&mut self, h: &Histogram) -> Value
This function initializes the probability distribution self with the contents of the histogram h. If any of the bins of h are negative then the error handler is invoked with an error code of Value::Dom because a probability distribution cannot contain negative values.
sourcepub fn sample(&self, r: f64) -> f64
pub fn sample(&self, r: f64) -> f64
This function uses r, a uniform random number between zero and one, to compute a single random sample from the probability distribution self. The algorithm used to compute the sample s is given by the following formula,
s = range[i] + delta * (range[i+1] - range[i])
where i is the index which satisfies sum[i] <= r < sum[i+1]
and delta
is
(r - sum[i])/(sum[i+1] - sum[i])
.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for HistogramPdf
impl !Send for HistogramPdf
impl !Sync for HistogramPdf
impl Unpin for HistogramPdf
impl UnwindSafe for HistogramPdf
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more