faunus
Public Member Functions | Public Attributes | List of all members
Faunus::WeightedDistribution< T > Class Template Reference

Stores a series of elements with given weight. More...

#include <random.h>

Public Member Functions

auto size () const
 Number of data points.
 
bool empty () const
 True if no data points.
 
size_t getLastIndex () const
 index of last get() or addGroup() element
 
void clear ()
 Clear all data.
 
template<typename Iterator >
void setWeight (Iterator begin, Iterator end)
 Set weights for all data points in vec More...
 
void push_back (const T &value, double weight=1.0)
 Add data and it's weight. More...
 
template<typename RandomGenerator >
const Tsample (RandomGenerator &engine)
 Get random data point respecting the weighted distribution. More...
 

Public Attributes

std::vector< Tdata
 raw vector of T
 

Detailed Description

template<typename T>
class Faunus::WeightedDistribution< T >

Stores a series of elements with given weight.

Elements is accessed with get() that will randomly pick from the weighted distribution. Add elements with addGroup() where the default weight is unity.

Template Parameters
TData type to store

Member Function Documentation

◆ push_back()

template<typename T>
void Faunus::WeightedDistribution< T >::push_back ( const T value,
double  weight = 1.0 
)
inline

Add data and it's weight.

Parameters
valuedata
weightweight (default: 1.0)

◆ sample()

template<typename T>
template<typename RandomGenerator >
const T& Faunus::WeightedDistribution< T >::sample ( RandomGenerator &  engine)
inline

Get random data point respecting the weighted distribution.

Parameters
engineRandom number engine
Returns
Reference to data point

◆ setWeight()

template<typename T>
template<typename Iterator >
void Faunus::WeightedDistribution< T >::setWeight ( Iterator  begin,
Iterator  end 
)
inline

Set weights for all data points in vec

Parameters
beginBegin iterator for weights
endEnd iterator for weights

The iterable range must match the size() of the stored data, otherwise an exception is thrown.


The documentation for this class was generated from the following file: