Skip to main content

rejection_sample_2d

Function rejection_sample_2d 

Source
pub fn rejection_sample_2d<F>(
    f: F,
    x_range: (f64, f64),
    y_range: (f64, f64),
    n: usize,
    rng: &mut impl Rng,
) -> Vec<[f64; 2]>
where F: Fn(f64, f64) -> f64,
Expand description

2-D rejection sampling.

Draws n uniform samples from [x_range.0, x_range.1) × [y_range.0, y_range.1) and accepts (x, y) when u < f(x, y) where u ~ U[0, max_f].

f must be non-negative; the function evaluates an internal upper bound by sampling a small grid.