NEST main@f146f75
Loading...
Searching...
No Matches
nest::RandomGenerator< RandomEngineT > Class Template Referencefinal

Wrapper for RNG engines. More...

#include <random_generators.h>

Inheritance diagram for nest::RandomGenerator< RandomEngineT >:
[legend]
Collaboration diagram for nest::RandomGenerator< RandomEngineT >:
[legend]

Public Types

using result_type = typename RandomEngineT::result_type

Public Member Functions

 RandomGenerator ()=delete
 RandomGenerator (const RandomEngineT &rng)=delete
 RandomGenerator (std::initializer_list< std::uint32_t > seed)
unsigned long operator() (std::uniform_int_distribution< unsigned long > &d) override
 Calls the provided distribution with the wrapped RNG engine.
double operator() (std::uniform_real_distribution<> &d) override
double operator() (std::normal_distribution<> &d) override
double operator() (std::lognormal_distribution<> &d) override
unsigned long operator() (std::binomial_distribution< unsigned long > &d) override
double operator() (std::gamma_distribution<> &d) override
double operator() (std::exponential_distribution<> &d) override
unsigned long operator() (std::discrete_distribution< unsigned long > &d) override
unsigned long operator() (std::poisson_distribution< unsigned long > &d) override
unsigned long operator() (std::uniform_int_distribution< unsigned long > &d, std::uniform_int_distribution< unsigned long >::param_type &p) override
 Calls the provided distribution with the wrapped RNG engine, using provided distribution parameters.
double operator() (std::uniform_real_distribution<> &d, std::uniform_real_distribution<>::param_type &p) override
double operator() (std::normal_distribution<> &d, std::normal_distribution<>::param_type &p) override
double operator() (std::lognormal_distribution<> &d, std::lognormal_distribution<>::param_type &p) override
unsigned long operator() (std::binomial_distribution< unsigned long > &d, std::binomial_distribution< unsigned long >::param_type &p) override
double operator() (std::gamma_distribution<> &d, std::gamma_distribution<>::param_type &p) override
double operator() (std::exponential_distribution<> &d, std::exponential_distribution<>::param_type &p) override
unsigned long operator() (std::discrete_distribution< unsigned long > &d, std::discrete_distribution< unsigned long >::param_type &p) override
unsigned long operator() (std::poisson_distribution< unsigned long > &d, std::poisson_distribution< unsigned long >::param_type &p) override
double drand () override
 Uses the wrapped RNG engine to draw a double from a uniform distribution in the range [0, 1).
unsigned long ulrand (unsigned long N) override
 Uses the wrapped RNG engine to draw an unsigned long from a uniform distribution in the range [0, N).
void stable_sample (NodeCollection::const_iterator first, NodeCollection::const_iterator last, std::back_insert_iterator< std::vector< NodeIDTriple > > dest, size_t n) override
 Wrap std::sample for selection from NodeCollection.
void partial_shuffle (std::vector< size_t > &data, const size_t n) override
 Select randomly shuffled elements from vector.
Public Member Functions inherited from nest::BaseRandomGenerator
virtual ~BaseRandomGenerator ()

Private Attributes

RandomEngineT rng_
 Wrapped RNG engine.
std::uniform_int_distribution< unsigned long > uniform_ulong_dist_
std::uniform_real_distribution uniform_double_dist_0_1_

Detailed Description

template<typename RandomEngineT>
class nest::RandomGenerator< RandomEngineT >

Wrapper for RNG engines.

Template Parameters
RandomEngineTType of the wrapped engine, must conform with the C++11 random engine interface.

Member Typedef Documentation

◆ result_type

template<typename RandomEngineT>
using nest::RandomGenerator< RandomEngineT >::result_type = typename RandomEngineT::result_type

Constructor & Destructor Documentation

◆ RandomGenerator() [1/3]

template<typename RandomEngineT>
nest::RandomGenerator< RandomEngineT >::RandomGenerator ( )
delete

◆ RandomGenerator() [2/3]

template<typename RandomEngineT>
nest::RandomGenerator< RandomEngineT >::RandomGenerator ( const RandomEngineT & rng)
delete

◆ RandomGenerator() [3/3]

template<typename RandomEngineT>
nest::RandomGenerator< RandomEngineT >::RandomGenerator ( std::initializer_list< std::uint32_t > seed)
inlineexplicit

References rng_, and uniform_double_dist_0_1_.

Member Function Documentation

◆ drand()

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::drand ( )
inlineoverridevirtual

Uses the wrapped RNG engine to draw a double from a uniform distribution in the range [0, 1).

Implements nest::BaseRandomGenerator.

References rng_, and uniform_double_dist_0_1_.

◆ operator()() [1/18]

template<typename RandomEngineT>
unsigned long nest::RandomGenerator< RandomEngineT >::operator() ( std::binomial_distribution< unsigned long > & d)
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [2/18]

template<typename RandomEngineT>
unsigned long nest::RandomGenerator< RandomEngineT >::operator() ( std::binomial_distribution< unsigned long > & d,
std::binomial_distribution< unsigned long >::param_type & p )
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [3/18]

template<typename RandomEngineT>
unsigned long nest::RandomGenerator< RandomEngineT >::operator() ( std::discrete_distribution< unsigned long > & d)
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [4/18]

template<typename RandomEngineT>
unsigned long nest::RandomGenerator< RandomEngineT >::operator() ( std::discrete_distribution< unsigned long > & d,
std::discrete_distribution< unsigned long >::param_type & p )
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [5/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::exponential_distribution<> & d)
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [6/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::exponential_distribution<> & d,
std::exponential_distribution<>::param_type & p )
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [7/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::gamma_distribution<> & d)
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [8/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::gamma_distribution<> & d,
std::gamma_distribution<>::param_type & p )
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [9/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::lognormal_distribution<> & d)
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [10/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::lognormal_distribution<> & d,
std::lognormal_distribution<>::param_type & p )
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [11/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::normal_distribution<> & d)
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [12/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::normal_distribution<> & d,
std::normal_distribution<>::param_type & p )
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [13/18]

template<typename RandomEngineT>
unsigned long nest::RandomGenerator< RandomEngineT >::operator() ( std::poisson_distribution< unsigned long > & d)
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [14/18]

template<typename RandomEngineT>
unsigned long nest::RandomGenerator< RandomEngineT >::operator() ( std::poisson_distribution< unsigned long > & d,
std::poisson_distribution< unsigned long >::param_type & p )
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [15/18]

template<typename RandomEngineT>
unsigned long nest::RandomGenerator< RandomEngineT >::operator() ( std::uniform_int_distribution< unsigned long > & d)
inlineoverridevirtual

Calls the provided distribution with the wrapped RNG engine.

One operator per distribution must be defined.

Parameters
dDistribution that will be called.

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [16/18]

template<typename RandomEngineT>
unsigned long nest::RandomGenerator< RandomEngineT >::operator() ( std::uniform_int_distribution< unsigned long > & d,
std::uniform_int_distribution< unsigned long >::param_type & p )
inlineoverridevirtual

Calls the provided distribution with the wrapped RNG engine, using provided distribution parameters.

One operator per distribution must be defined.

Parameters
dDistribution that will be called.
pDistribution parameters.

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [17/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::uniform_real_distribution<> & d)
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ operator()() [18/18]

template<typename RandomEngineT>
double nest::RandomGenerator< RandomEngineT >::operator() ( std::uniform_real_distribution<> & d,
std::uniform_real_distribution<>::param_type & p )
inlineoverridevirtual

Implements nest::BaseRandomGenerator.

References rng_.

◆ partial_shuffle()

template<typename RandomEngineT>
void nest::RandomGenerator< RandomEngineT >::partial_shuffle ( std::vector< size_t > & data,
const size_t n )
inlineoverridevirtual

Select randomly shuffled elements from vector.

Places n elements chosen from data without replacement, in random order, at the beginning of data and then reduces the size of data to n. If n exceeds data.size(), all elements are kept and only shuffled.

Parameters
dataVector to be shuffled and possibly shortened.
nNumber of elements to select.

Implements nest::BaseRandomGenerator.

References ulrand().

Here is the call graph for this function:

◆ stable_sample()

template<typename RandomEngineT>
void nest::RandomGenerator< RandomEngineT >::stable_sample ( NodeCollection::const_iterator first,
NodeCollection::const_iterator last,
std::back_insert_iterator< std::vector< NodeIDTriple > > dest,
size_t n )
inlineoverridevirtual

Wrap std::sample for selection from NodeCollection.

Inserts random stable sample without replacement of size n from range [first, last)into dest.

Note
Running this with different random seeds will select different elements, but the order of elements will always be the same as in the node collection from which we sample. In particular, if n == nc.size(), then dest will contain the original node collection (as an explicit vector).

Implements nest::BaseRandomGenerator.

References rng_.

◆ ulrand()

template<typename RandomEngineT>
unsigned long nest::RandomGenerator< RandomEngineT >::ulrand ( unsigned long N)
inlineoverridevirtual

Uses the wrapped RNG engine to draw an unsigned long from a uniform distribution in the range [0, N).

Parameters
NMaximum value that can be drawn.

Implements nest::BaseRandomGenerator.

References rng_, and uniform_ulong_dist_.

Referenced by partial_shuffle().

Here is the caller graph for this function:

Member Data Documentation

◆ rng_

◆ uniform_double_dist_0_1_

template<typename RandomEngineT>
std::uniform_real_distribution nest::RandomGenerator< RandomEngineT >::uniform_double_dist_0_1_
private

Referenced by drand(), and RandomGenerator().

◆ uniform_ulong_dist_

template<typename RandomEngineT>
std::uniform_int_distribution< unsigned long > nest::RandomGenerator< RandomEngineT >::uniform_ulong_dist_
private

Referenced by ulrand().


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