Skip to main content

ImportanceSampling

Struct ImportanceSampling 

Source
pub struct ImportanceSampling {
    pub n_samples: usize,
    pub self_normalized: bool,
}
Expand description

Configuration for importance sampling.

Fields§

§n_samples: usize

Number of samples.

§self_normalized: bool

Whether to use self-normalized estimator.

Implementations§

Source§

impl ImportanceSampling

Source

pub fn new(n_samples: usize) -> Self

Create new importance sampling configuration.

Source

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.

Source

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)
where S: Fn(&mut R::State) -> f32, F: Fn(f32) -> f32, LP: Fn(f32) -> f32, LQ: Fn(f32) -> f32,

Estimate E_p[f(X)] using importance sampling.

§Arguments
  • state - RNG state
  • sample_q - Function to sample from proposal distribution q
  • f - Function to estimate expectation of
  • log_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

Source§

fn clone(&self) -> ImportanceSampling

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ImportanceSampling

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ImportanceSampling

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.