vSMC
vSMC: Scalable Monte Carlo
|
Draw a single sample given weights. More...
#include <vsmc/rng/discrete_distribution.hpp>
Public Types | |
typedef std::vector< double > | param_type |
typedef IntType | result_type |
Public Member Functions | |
DiscreteDistribution () | |
template<typename InputIter > | |
DiscreteDistribution (InputIter first, InputIter last) | |
template<typename UnaryOperation > | |
DiscreteDistribution (std::size_t count, double xmin, double xmax, UnaryOperation unary_op) | |
DiscreteDistribution (const param_type ¶m) | |
DiscreteDistribution (param_type &¶m) | |
result_type | max () const |
result_type | min () const |
template<typename URNG > | |
result_type | operator() (URNG &eng) const |
template<typename URNG , typename InputIter > | |
result_type | operator() (URNG &eng, InputIter first, InputIter last, bool normalized=false) const |
Draw sample with external probabilities. More... | |
param_type | param () const |
void | param (const param_type ¶m) |
void | param (param_type &¶m) |
std::vector< double > | probability () const |
void | reset () |
Friends | |
bool | operator!= (const DiscreteDistribution< IntType > &rdisc1, const DiscreteDistribution< IntType > &rdisc2) |
template<typename CharT , typename Traits > | |
std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &os, const DiscreteDistribution< IntType > &rdisc) |
bool | operator== (const DiscreteDistribution< IntType > &rdisc1, const DiscreteDistribution< IntType > &rdisc2) |
template<typename CharT , typename Traits > | |
std::basic_istream< CharT, Traits > & | operator>> (std::basic_istream< CharT, Traits > &is, DiscreteDistribution< IntType > &rdisc) |
Draw a single sample given weights.
Definition at line 47 of file discrete_distribution.hpp.
typedef std::vector<double> vsmc::DiscreteDistribution< IntType >::param_type |
Definition at line 52 of file discrete_distribution.hpp.
typedef IntType vsmc::DiscreteDistribution< IntType >::result_type |
Definition at line 51 of file discrete_distribution.hpp.
|
inline |
Definition at line 54 of file discrete_distribution.hpp.
|
inline |
Definition at line 57 of file discrete_distribution.hpp.
|
inline |
Definition at line 74 of file discrete_distribution.hpp.
|
inlineexplicit |
Definition at line 86 of file discrete_distribution.hpp.
|
inlineexplicit |
Definition at line 94 of file discrete_distribution.hpp.
|
inline |
Definition at line 123 of file discrete_distribution.hpp.
|
inline |
Definition at line 122 of file discrete_distribution.hpp.
|
inline |
Definition at line 129 of file discrete_distribution.hpp.
|
inline |
Draw sample with external probabilities.
eng | A uniform random number generator |
first | The first iterator of the weights sequence. |
last | The one past the end iterator of the weights sequence. |
normalized | If the weights are already normalized |
Given weights \((W_1,\dots,\W_N)\), it is possible to draw the index \(i\) using the std::discrete_distribuiton
template. However, there are two drawbacks with this approach. First, if the weightsa are already normalized, this template does uncessary extra work to normalized the weights. Second, whenever the weights change, a new distribution need to be constructed (the param_type
of the distribution is implementation defined and cannot be used to write portable code), which will lead to uncessary dynamic memory allocation.
This function requires the normalized weights, specified using the iterators first
and last
, and return the index (counting from zero) of the random draw. No dynamic memory allocaiton will be invovled by calling this function.
Definition at line 155 of file discrete_distribution.hpp.
|
inline |
Definition at line 102 of file discrete_distribution.hpp.
|
inline |
Definition at line 104 of file discrete_distribution.hpp.
|
inline |
Definition at line 112 of file discrete_distribution.hpp.
|
inline |
Definition at line 126 of file discrete_distribution.hpp.
|
inline |
Definition at line 120 of file discrete_distribution.hpp.
|
friend |
Definition at line 198 of file discrete_distribution.hpp.
|
friend |
Definition at line 204 of file discrete_distribution.hpp.
|
friend |
Definition at line 193 of file discrete_distribution.hpp.
|
friend |
Definition at line 229 of file discrete_distribution.hpp.