Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
Brush::Util::Rnd Class Reference

Defines a multi-core random number generator and its operators. More...

#include <rnd.h>

Collaboration diagram for Brush::Util::Rnd:

Public Member Functions

void set_seed (unsigned int seed)
int rnd_int (int lowerLimit, int upperLimit)
float rnd_flt (float min=0.0, float max=1.0)
float rnd_alpha_beta (float alpha, float beta)
float rnd_dbl (float min=0.0, float max=1.0)
float operator() (unsigned i)
float operator() ()
template<class RandomAccessIterator>
void shuffle (RandomAccessIterator first, RandomAccessIterator last)
vector< size_t > shuffled_index (size_t n)
 returns a shuffled index vector of length n
template<typename Iter>
Iter select_randomly (Iter start, Iter end)
template<typename Iter, typename Iter2>
Iter select_randomly (Iter start, Iter end, Iter2 wstart, Iter2 wend)
 select randomly with weighted distribution.
template<typename T>
T random_choice (const map< T, float > &m)
template<class V, class T>
T random_choice (const V &v)
template<template< class, class > class C, class T>
T random_choice (const C< T, std::allocator< T > > &v, const vector< float > &w)
float gasdev ()

Static Public Member Functions

static Rnd * initRand ()
static void destroy ()

Private Member Functions

 Rnd ()
 ~Rnd ()

Private Attributes

vector< std::mt19937 > rg
bool has_spare_normal = false
float spare_normal = 0.0f

Static Private Attributes

static Rnd * instance = NULL

Detailed Description

Defines a multi-core random number generator and its operators.

Definition at line 28 of file rnd.h.

Constructor & Destructor Documentation

◆ Rnd()

Brush::Util::Rnd::Rnd ( )
private

need a random generator for each core to do multiprocessing. The constructor will resize the random generators based on the number of available cores.

Definition at line 12 of file rnd.cpp.

Here is the caller graph for this function:

◆ ~Rnd()

Brush::Util::Rnd::~Rnd ( )
private

Definition at line 162 of file rnd.cpp.

Member Function Documentation

◆ destroy()

void Brush::Util::Rnd::destroy ( )
static

Definition at line 38 of file rnd.cpp.

◆ gasdev()

float Brush::Util::Rnd::gasdev ( )

Definition at line 122 of file rnd.cpp.

Here is the call graph for this function:

◆ initRand()

Rnd * Brush::Util::Rnd::initRand ( )
static

Definition at line 26 of file rnd.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator()() [1/2]

float Brush::Util::Rnd::operator() ( )

Definition at line 120 of file rnd.cpp.

Here is the call graph for this function:

◆ operator()() [2/2]

float Brush::Util::Rnd::operator() ( unsigned i)

Definition at line 115 of file rnd.cpp.

Here is the call graph for this function:

◆ random_choice() [1/3]

template<template< class, class > class C, class T>
T Brush::Util::Rnd::random_choice ( const C< T, std::allocator< T > > & v,
const vector< float > & w )
inline

return a weighted random element of an STL container

Definition at line 130 of file rnd.h.

Here is the call graph for this function:

◆ random_choice() [2/3]

template<typename T>
T Brush::Util::Rnd::random_choice ( const map< T, float > & m)
inline

return a weighted random key of a map, where the values are weights.

Definition at line 98 of file rnd.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ random_choice() [3/3]

template<class V, class T>
T Brush::Util::Rnd::random_choice ( const V & v)
inline

return a random element of a vector.

Definition at line 119 of file rnd.h.

Here is the call graph for this function:

◆ rnd_alpha_beta()

float Brush::Util::Rnd::rnd_alpha_beta ( float alpha,
float beta )

Definition at line 83 of file rnd.cpp.

◆ rnd_dbl()

float Brush::Util::Rnd::rnd_dbl ( float min = 0.0,
float max = 1.0 )

Definition at line 109 of file rnd.cpp.

Here is the caller graph for this function:

◆ rnd_flt()

float Brush::Util::Rnd::rnd_flt ( float min = 0.0,
float max = 1.0 )

Definition at line 77 of file rnd.cpp.

Here is the caller graph for this function:

◆ rnd_int()

int Brush::Util::Rnd::rnd_int ( int lowerLimit,
int upperLimit )

Definition at line 71 of file rnd.cpp.

◆ select_randomly() [1/2]

template<typename Iter>
Iter Brush::Util::Rnd::select_randomly ( Iter start,
Iter end )
inline

Definition at line 63 of file rnd.h.

Here is the caller graph for this function:

◆ select_randomly() [2/2]

template<typename Iter, typename Iter2>
Iter Brush::Util::Rnd::select_randomly ( Iter start,
Iter end,
Iter2 wstart,
Iter2 wend )
inline

select randomly with weighted distribution.

Definition at line 75 of file rnd.h.

◆ set_seed()

void Brush::Util::Rnd::set_seed ( unsigned int seed)

set seeds for each core's random number generator.

Definition at line 46 of file rnd.cpp.

Here is the caller graph for this function:

◆ shuffle()

template<class RandomAccessIterator>
void Brush::Util::Rnd::shuffle ( RandomAccessIterator first,
RandomAccessIterator last )
inline

Definition at line 51 of file rnd.h.

Here is the caller graph for this function:

◆ shuffled_index()

vector< size_t > Brush::Util::Rnd::shuffled_index ( size_t n)

returns a shuffled index vector of length n

Definition at line 155 of file rnd.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ has_spare_normal

bool Brush::Util::Rnd::has_spare_normal = false
private

Definition at line 173 of file rnd.h.

◆ instance

Rnd * Brush::Util::Rnd::instance = NULL
staticprivate

Definition at line 178 of file rnd.h.

◆ rg

vector<std::mt19937> Brush::Util::Rnd::rg
private

Definition at line 165 of file rnd.h.

◆ spare_normal

float Brush::Util::Rnd::spare_normal = 0.0f
private

Definition at line 174 of file rnd.h.


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