Skip to main content

rejection_sample_1d

Function rejection_sample_1d 

Source
pub fn rejection_sample_1d(
    pdf: impl Fn(f64) -> f64,
    lo: f64,
    hi: f64,
    envelope: f64,
    n: usize,
    rng: &mut Lcg,
) -> Vec<f64>
Expand description

Draw n samples from an arbitrary 1-D PDF using rejection sampling.

pdf must be non-negative; envelope must satisfy pdf(x) ≤ envelope for all x ∈ \[lo, hi).

§Arguments

  • pdf – target density function
  • lo, hi – support of the distribution
  • envelope – upper bound of pdf over the support
  • n – number of samples to draw
  • rng – LCG random source