pub struct HistogramDistribution { /* private fields */ }
Expand description
Distribution described by non-normalised histogram
The distribution is given as a table of x
and pdf
which follows histogram
interpolation. For x ∈ [xᵢ₊₁; xᵢ]
probability if pdf(x) = pdfᵢ
. The
cumulative distribution function becomes piece-wise linear which makes
sampling form the table quite easy.
To support better approximation of different pdfs, the grid is not equal-spaced in general. Hence binary search is needed to find correct bin.
Implementations§
Source§impl HistogramDistribution
impl HistogramDistribution
Sourcepub fn new(x: Vec<f64>, pdf: Vec<f64>) -> Result<Self, SetupError>
pub fn new(x: Vec<f64>, pdf: Vec<f64>) -> Result<Self, SetupError>
Create a new instance of the histogram distribution
The cumulative distribution function will be calculated.
Condition x.len() == pdf.len() > 1
, must be met.
Thus the last value in the pdf
vector will be ignored.
Sourcepub fn sample_with_value<RNG>(&self, rng: &mut RNG) -> (f64, f64)
pub fn sample_with_value<RNG>(&self, rng: &mut RNG) -> (f64, f64)
Sample a value from the histogram and return the value of non-normalised probability
§Result
Tuple (s, p)
where s
is the sample and p
probability in the bin
We need a way to sample while returning probability value in the bin as well to implement rejection sampling scheme without repeating a binary search of the grid.
Trait Implementations§
Source§impl Clone for HistogramDistribution
impl Clone for HistogramDistribution
Source§fn clone(&self) -> HistogramDistribution
fn clone(&self) -> HistogramDistribution
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for HistogramDistribution
impl Debug for HistogramDistribution
Source§impl Distribution<f64> for HistogramDistribution
Draws samples from the histogram distribution
impl Distribution<f64> for HistogramDistribution
Draws samples from the histogram distribution