pub struct ImportanceSampling {
pub n_samples: usize,
pub self_normalized: bool,
}Expand description
Configuration for importance sampling.
Fields§
§n_samples: usizeNumber of samples.
self_normalized: boolWhether to use self-normalized estimator.
Implementations§
Source§impl ImportanceSampling
impl ImportanceSampling
Sourcepub fn self_normalized(self) -> Self
pub fn self_normalized(self) -> Self
Use self-normalized importance sampling.
The self-normalized estimator divides by sum of weights:
sum(w_i * f_i) / sum(w_i)
This is biased but can have lower variance and doesn’t require knowing the normalizing constant of p.
Sourcepub fn estimate<R: GpuRng, S, F, LP, LQ>(
&self,
state: &mut R::State,
sample_q: S,
f: F,
log_p: LP,
log_q: LQ,
) -> (f32, f32)
pub fn estimate<R: GpuRng, S, F, LP, LQ>( &self, state: &mut R::State, sample_q: S, f: F, log_p: LP, log_q: LQ, ) -> (f32, f32)
Estimate E_p[f(X)] using importance sampling.
§Arguments
state- RNG statesample_q- Function to sample from proposal distribution qf- Function to estimate expectation oflog_p- Log of target density (unnormalized OK if self_normalized)log_q- Log of proposal density
§Returns
(estimate, effective_sample_size)
Trait Implementations§
Source§impl Clone for ImportanceSampling
impl Clone for ImportanceSampling
Source§fn clone(&self) -> ImportanceSampling
fn clone(&self) -> ImportanceSampling
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ImportanceSampling
impl Debug for ImportanceSampling
Auto Trait Implementations§
impl Freeze for ImportanceSampling
impl RefUnwindSafe for ImportanceSampling
impl Send for ImportanceSampling
impl Sync for ImportanceSampling
impl Unpin for ImportanceSampling
impl UnwindSafe for ImportanceSampling
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more