vSMC
v3.0.0
Scalable Monte Carlo
|
Draw a single sample given weights. More...
#include <vsmc/rng/discrete_distribution.hpp>
Classes | |
class | param_type |
Public Types | |
using | distribution_type = DiscreteDistribution< IntType > |
using | result_type = IntType |
Public Member Functions | |
DiscreteDistribution () | |
template<typename InputIter > | |
DiscreteDistribution (InputIter first, InputIter last) | |
DiscreteDistribution (std::initializer_list< double > weights) | |
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 RNGType > | |
result_type | operator() (RNGType &rng) const |
template<typename RNGType , typename InputIter > | |
result_type | operator() (RNGType &rng, InputIter first, InputIter last, bool normalized=false) const |
Draw sample with external probabilities. More... | |
Vector< double > | probability () const |
Friends | |
bool | operator!= (const distribution_type &dist1, const distribution_type &dist2) |
template<typename CharT , typename Traits > | |
std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &os, const distribution_type &dist) |
bool | operator== (const distribution_type &dist1, const distribution_type &dist2) |
template<typename CharT , typename Traits > | |
std::basic_istream< CharT, Traits > & | operator>> (std::basic_istream< CharT, Traits > &is, distribution_type &dist) |
Draw a single sample given weights.
Definition at line 48 of file discrete_distribution.hpp.
using vsmc::DiscreteDistribution< IntType >::distribution_type = DiscreteDistribution<IntType> |
Definition at line 52 of file discrete_distribution.hpp.
using vsmc::DiscreteDistribution< IntType >::result_type = IntType |
Definition at line 51 of file discrete_distribution.hpp.
|
inline |
Definition at line 174 of file discrete_distribution.hpp.
|
inline |
Definition at line 177 of file discrete_distribution.hpp.
|
inline |
Definition at line 181 of file discrete_distribution.hpp.
|
inline |
Definition at line 187 of file discrete_distribution.hpp.
|
inlineexplicit |
Definition at line 193 of file discrete_distribution.hpp.
|
inlineexplicit |
Definition at line 195 of file discrete_distribution.hpp.
|
inline |
Definition at line 202 of file discrete_distribution.hpp.
|
inline |
Definition at line 200 of file discrete_distribution.hpp.
|
inline |
Definition at line 210 of file discrete_distribution.hpp.
|
inline |
Draw sample with external probabilities.
rng | 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 weights 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 does not use dynamic memory and improve performance for normalized weights.
Definition at line 235 of file discrete_distribution.hpp.
|
inline |
Definition at line 207 of file discrete_distribution.hpp.
|
friend |
Definition at line 279 of file discrete_distribution.hpp.
|
friend |
Definition at line 286 of file discrete_distribution.hpp.
|
friend |
Definition at line 273 of file discrete_distribution.hpp.
|
friend |
Definition at line 295 of file discrete_distribution.hpp.