vSMC
vSMC: Scalable Monte Carlo
Public Types | Public Member Functions | Protected Member Functions | List of all members
vsmc::WeightSet Class Reference

Weight set class. More...

#include <vsmc/core/weight_set.hpp>

Public Types

typedef std::size_t size_type
 

Public Member Functions

 WeightSet (size_type N)
 
 WeightSet (const WeightSet &)=default
 
 WeightSet (WeightSet &&)=default
 
virtual ~WeightSet ()
 
template<typename InputIter >
void add_log_weight (InputIter first)
 Set normalized weight, unnormalized logarithm weight and ESS by adding to the unnormalized logarithm weights with (possible unormalized) logarithm incremental weights through an input iterator. More...
 
template<typename RandomIter >
void add_log_weight (RandomIter first, int stride)
 Set normalized weight, unnormalized logarithm weight and ESS by adding to the unnormalized logarithm weights with (possible unormalized) logarithm incremental weights through a ranodm access iterator with (possible non-uniform) stride. More...
 
template<typename InputIter >
double cess (InputIter first, bool use_log) const
 Compute CESS given (log) incremental weights. More...
 
template<typename RandomIter >
double cess (RandomIter first, int stride, bool use_log) const
 Compute CESS given (log) incremental weights. More...
 
template<typename URNG >
size_type draw (URNG &eng) const
 Draw a sample according to the weights. More...
 
double ess () const
 ESS of the particle collection based on the current weights. More...
 
template<typename InputIter >
double ess (InputIter first, bool use_log) const
 Compute ESS given (log) incremental weights. More...
 
template<typename RandomIter >
double ess (RandomIter first, int stride, bool use_log) const
 Compute ESS given (log) incremental weights. More...
 
double log_weight (size_type id) const
 Get the unnormalized logarithm weight of the id'th particle. More...
 
const double * log_weight_data () const
 Read only access to the raw data of logarithm weight. More...
 
template<typename InputIter >
void mul_weight (InputIter first)
 Set normalized weight, unnormalized logarithm weight and ESS by multiply the normalized weight with (possible unnormalized) incremental weights through an input iterator. More...
 
template<typename RandomIter >
void mul_weight (RandomIter first, int stride)
 Set normalized weight, unnormalized logarithm weight and ESS by multiply the normalized weight with (possible unnormalized) incremental weights through a random access iterator with (possible non-uniform) stride. More...
 
WeightSetoperator= (const WeightSet &)=default
 
WeightSetoperator= (WeightSet &&)=default
 
template<typename OutputIter >
void read_log_weight (OutputIter first) const
 Read unnormalized logarithm weights through an output iterator. More...
 
template<typename RandomIter >
void read_log_weight (RandomIter first, int stride) const
 Read unnormalized logarithm weights through a random access iterator with (possible non-uniform stride) More...
 
virtual void read_resample_weight (double *first) const
 Read normalized weights through an output iterator for the purpose of resampling. More...
 
template<typename OutputIter >
void read_weight (OutputIter first) const
 Read normalized weights through an output iterator. More...
 
template<typename RandomIter >
void read_weight (RandomIter first, int stride) const
 Read normalized weights through a random access iterator with (possible non-uniform stride) More...
 
virtual size_type resample_size () const
 Size of the weight set for the purpose of resampling. More...
 
virtual const double * resample_weight_data () const
 Read only access to the resampling weights. More...
 
void set_equal_weight ()
 Set normalized weight, unnormalized logarithm weight and ESS such that each particle has a equal weight. More...
 
template<typename InputIter >
void set_log_weight (InputIter first)
 Set normalized weight, unnormalized logarithm weight and ESS by changing the (possible unnormalized) logarithm weights directly through an input iterator. More...
 
template<typename RandomIter >
void set_log_weight (RandomIter first, int stride)
 Set normalized weight, unnormalized logarithm weight and ESS by changing the (possible unnormalized) logarithm weights directly through a random access iterator with (possible non-uniform) stride. More...
 
template<typename InputIter >
void set_weight (InputIter first)
 Set normalized weight, unnormalized logarithm weight and ESS by changing the (possible unnormalized) weights directly through an input iterator. More...
 
template<typename RandomIter >
void set_weight (RandomIter first, int stride)
 Set normalized weight, unnormalized logarithm weight and ESS by changing the (possible unnormalized) weights directly through a random access iterator with (possible non-uniform) stride. More...
 
size_type size () const
 
double weight (size_type id) const
 Get the normalized weight of the id'th particle. More...
 
const double * weight_data () const
 Read only access to the raw data of weight. More...
 

Protected Member Functions

virtual double compute_cess (const double *first, bool use_log) const
 Compute CESS given (logarithm) unormalized incremental weights. More...
 
virtual double compute_ess (const double *first, bool use_log) const
 Compute ESS given (logarithm) unormalzied incremental weights. More...
 
virtual void log_weight2weight ()
 Compute unormalized logarithm weights from normalized weights. More...
 
double * mutable_log_weight_data ()
 
double * mutable_weight_data ()
 
virtual void normalize_log_weight ()
 Normalize logarithm weights such that the maximum is zero. More...
 
virtual void normalize_weight ()
 Normalize weights such that the summation is one. More...
 
void set_ess (double e)
 
virtual void weight2log_weight ()
 Compute unormalized weights from normalized logarithm weights. More...
 

Detailed Description

Weight set class.

Definition at line 43 of file weight_set.hpp.

Member Typedef Documentation

typedef std::size_t vsmc::WeightSet::size_type

Definition at line 47 of file weight_set.hpp.

Constructor & Destructor Documentation

vsmc::WeightSet::WeightSet ( size_type  N)
inlineexplicit

Definition at line 49 of file weight_set.hpp.

vsmc::WeightSet::WeightSet ( const WeightSet )
default
vsmc::WeightSet::WeightSet ( WeightSet &&  )
default
virtual vsmc::WeightSet::~WeightSet ( )
inlinevirtual

Definition at line 94 of file weight_set.hpp.

Member Function Documentation

template<typename InputIter >
void vsmc::WeightSet::add_log_weight ( InputIter  first)
inline

Set normalized weight, unnormalized logarithm weight and ESS by adding to the unnormalized logarithm weights with (possible unormalized) logarithm incremental weights through an input iterator.

Definition at line 295 of file weight_set.hpp.

template<typename RandomIter >
void vsmc::WeightSet::add_log_weight ( RandomIter  first,
int  stride 
)
inline

Set normalized weight, unnormalized logarithm weight and ESS by adding to the unnormalized logarithm weights with (possible unormalized) logarithm incremental weights through a ranodm access iterator with (possible non-uniform) stride.

Definition at line 308 of file weight_set.hpp.

template<typename InputIter >
double vsmc::WeightSet::cess ( InputIter  first,
bool  use_log 
) const
inline

Compute CESS given (log) incremental weights.

Definition at line 131 of file weight_set.hpp.

template<typename RandomIter >
double vsmc::WeightSet::cess ( RandomIter  first,
int  stride,
bool  use_log 
) const
inline

Compute CESS given (log) incremental weights.

Definition at line 147 of file weight_set.hpp.

virtual double vsmc::WeightSet::compute_cess ( const double *  first,
bool  use_log 
) const
inlineprotectedvirtual

Compute CESS given (logarithm) unormalized incremental weights.

Definition at line 395 of file weight_set.hpp.

virtual double vsmc::WeightSet::compute_ess ( const double *  first,
bool  use_log 
) const
inlineprotectedvirtual

Compute ESS given (logarithm) unormalzied incremental weights.

Definition at line 369 of file weight_set.hpp.

template<typename URNG >
size_type vsmc::WeightSet::draw ( URNG &  eng) const
inline

Draw a sample according to the weights.

Definition at line 318 of file weight_set.hpp.

double vsmc::WeightSet::ess ( ) const
inline

ESS of the particle collection based on the current weights.

Definition at line 99 of file weight_set.hpp.

template<typename InputIter >
double vsmc::WeightSet::ess ( InputIter  first,
bool  use_log 
) const
inline

Compute ESS given (log) incremental weights.

Definition at line 103 of file weight_set.hpp.

template<typename RandomIter >
double vsmc::WeightSet::ess ( RandomIter  first,
int  stride,
bool  use_log 
) const
inline

Compute ESS given (log) incremental weights.

Definition at line 119 of file weight_set.hpp.

double vsmc::WeightSet::log_weight ( size_type  id) const
inline

Get the unnormalized logarithm weight of the id'th particle.

Definition at line 199 of file weight_set.hpp.

virtual void vsmc::WeightSet::log_weight2weight ( )
inlineprotectedvirtual

Compute unormalized logarithm weights from normalized weights.

Definition at line 339 of file weight_set.hpp.

const double* vsmc::WeightSet::log_weight_data ( ) const
inline

Read only access to the raw data of logarithm weight.

Definition at line 328 of file weight_set.hpp.

template<typename InputIter >
void vsmc::WeightSet::mul_weight ( InputIter  first)
inline

Set normalized weight, unnormalized logarithm weight and ESS by multiply the normalized weight with (possible unnormalized) incremental weights through an input iterator.

Definition at line 242 of file weight_set.hpp.

template<typename RandomIter >
void vsmc::WeightSet::mul_weight ( RandomIter  first,
int  stride 
)
inline

Set normalized weight, unnormalized logarithm weight and ESS by multiply the normalized weight with (possible unnormalized) incremental weights through a random access iterator with (possible non-uniform) stride.

Definition at line 255 of file weight_set.hpp.

double* vsmc::WeightSet::mutable_log_weight_data ( )
inlineprotected

Definition at line 336 of file weight_set.hpp.

double* vsmc::WeightSet::mutable_weight_data ( )
inlineprotected

Definition at line 334 of file weight_set.hpp.

virtual void vsmc::WeightSet::normalize_log_weight ( )
inlineprotectedvirtual

Normalize logarithm weights such that the maximum is zero.

Definition at line 347 of file weight_set.hpp.

virtual void vsmc::WeightSet::normalize_weight ( )
inlineprotectedvirtual

Normalize weights such that the summation is one.

Definition at line 360 of file weight_set.hpp.

WeightSet& vsmc::WeightSet::operator= ( const WeightSet )
default
WeightSet& vsmc::WeightSet::operator= ( WeightSet &&  )
default
template<typename OutputIter >
void vsmc::WeightSet::read_log_weight ( OutputIter  first) const
inline

Read unnormalized logarithm weights through an output iterator.

Definition at line 182 of file weight_set.hpp.

template<typename RandomIter >
void vsmc::WeightSet::read_log_weight ( RandomIter  first,
int  stride 
) const
inline

Read unnormalized logarithm weights through a random access iterator with (possible non-uniform stride)

Definition at line 188 of file weight_set.hpp.

virtual void vsmc::WeightSet::read_resample_weight ( double *  first) const
inlinevirtual

Read normalized weights through an output iterator for the purpose of resampling.

Definition at line 162 of file weight_set.hpp.

template<typename OutputIter >
void vsmc::WeightSet::read_weight ( OutputIter  first) const
inline

Read normalized weights through an output iterator.

Definition at line 167 of file weight_set.hpp.

template<typename RandomIter >
void vsmc::WeightSet::read_weight ( RandomIter  first,
int  stride 
) const
inline

Read normalized weights through a random access iterator with (possible non-uniform stride)

Definition at line 173 of file weight_set.hpp.

virtual size_type vsmc::WeightSet::resample_size ( ) const
inlinevirtual

Size of the weight set for the purpose of resampling.

Definition at line 158 of file weight_set.hpp.

virtual const double* vsmc::WeightSet::resample_weight_data ( ) const
inlinevirtual

Read only access to the resampling weights.

Definition at line 322 of file weight_set.hpp.

void vsmc::WeightSet::set_equal_weight ( )
inline

Set normalized weight, unnormalized logarithm weight and ESS such that each particle has a equal weight.

Definition at line 203 of file weight_set.hpp.

void vsmc::WeightSet::set_ess ( double  e)
inlineprotected

Definition at line 332 of file weight_set.hpp.

template<typename InputIter >
void vsmc::WeightSet::set_log_weight ( InputIter  first)
inline

Set normalized weight, unnormalized logarithm weight and ESS by changing the (possible unnormalized) logarithm weights directly through an input iterator.

Definition at line 267 of file weight_set.hpp.

template<typename RandomIter >
void vsmc::WeightSet::set_log_weight ( RandomIter  first,
int  stride 
)
inline

Set normalized weight, unnormalized logarithm weight and ESS by changing the (possible unnormalized) logarithm weights directly through a random access iterator with (possible non-uniform) stride.

Definition at line 283 of file weight_set.hpp.

template<typename InputIter >
void vsmc::WeightSet::set_weight ( InputIter  first)
inline

Set normalized weight, unnormalized logarithm weight and ESS by changing the (possible unnormalized) weights directly through an input iterator.

Definition at line 214 of file weight_set.hpp.

template<typename RandomIter >
void vsmc::WeightSet::set_weight ( RandomIter  first,
int  stride 
)
inline

Set normalized weight, unnormalized logarithm weight and ESS by changing the (possible unnormalized) weights directly through a random access iterator with (possible non-uniform) stride.

Definition at line 230 of file weight_set.hpp.

size_type vsmc::WeightSet::size ( ) const
inline

Definition at line 96 of file weight_set.hpp.

double vsmc::WeightSet::weight ( size_type  id) const
inline

Get the normalized weight of the id'th particle.

Definition at line 196 of file weight_set.hpp.

virtual void vsmc::WeightSet::weight2log_weight ( )
inlineprotectedvirtual

Compute unormalized weights from normalized logarithm weights.

Definition at line 343 of file weight_set.hpp.

const double* vsmc::WeightSet::weight_data ( ) const
inline

Read only access to the raw data of weight.

Definition at line 325 of file weight_set.hpp.