mxnet
Public Member Functions | List of all members
mshadow::Random< cpu, DType > Class Template Reference

CPU random number generator. More...

#include <random.h>

Collaboration diagram for mshadow::Random< cpu, DType >:
Collaboration graph

Public Member Functions

 Random (int seed)
 constructor of random engine More...
 
 ~Random (void)
 
void Seed (int seed)
 seed random number generator using this seed More...
 
unsigned GetSeed () const
 get random seed used in random generator More...
 
void set_stream (Stream< cpu > *stream)
 set the stream of computation More...
 
unsigned GetRandInt ()
 get some random integer More...
 
void GetRandInt (const Tensor< cpu, 1, unsigned > &dst)
 get a set of random integers More...
 
template<int dim, class Sampler >
void SampleDistribution (Tensor< cpu, dim, DType > *dst, Sampler sampler)
 generate data from a distribution More...
 
template<int dim, typename PType >
void SampleUniform (Tensor< cpu, dim, DType > *dst, PType a=0.0f, PType b=1.0f)
 generate data from uniform [a,b) More...
 
template<int dim, typename PType >
void SampleGaussian (Tensor< cpu, dim, DType > *dst, PType mu=0.0f, PType sigma=1.0f)
 generate data from standard gaussian More...
 
template<int dim, typename PType >
void SampleGamma (Tensor< cpu, dim, DType > *dst, PType alpha, PType beta)
 generate data from a gamma distribution More...
 
template<int dim, typename PType >
void SampleExponential (Tensor< cpu, dim, DType > *dst, PType lambda)
 generate data from an exponential distribution More...
 
template<int dim, typename PType >
void SamplePoisson (Tensor< cpu, dim, DType > *dst, PType lambda)
 generate data from a poisson distribution More...
 
template<int dim, typename PType1 , typename PType2 >
void SampleNegativeBinomial (Tensor< cpu, dim, DType > *dst, PType1 k, PType2 p)
 generate data from a negative binomial distribution More...
 
template<int dim, typename PType >
void SampleGeneralizedNegativeBinomial (Tensor< cpu, dim, DType > *dst, PType mu, PType alpha)
 generate data from a generalized negative binomial distribution More...
 
template<int dim>
expr::ReshapeExp< Tensor< cpu, 1, DType >, DType, dim, 1 > gaussian (Shape< dim > shape)
 return a temporal expression storing standard gaussian random variables the temporal tensor is only valid before next call of gaussian or uniform can be used as part of expression Caution: this means expression such as A = gaussian(s1) * gaussian(s2) will give invalid result, since second call of gaussian(s2) makes gaussian(s1) invalid A = gaussian(s1)*B+C; is correct; use one gaussian/uniform in each expression More...
 
template<int dim>
expr::ReshapeExp< Tensor< cpu, 1, DType >, DType, dim, 1 > uniform (Shape< dim > shape)
 return a temporal expression storing standard uniform [0,1) the temporal tensor is only valid before next call of gaussian or uniform can be used as part of expression Caution: this means expression such as A = uniform(s1) * uniform(s2) will give invalid result, since second call of gaussian(s2) makes gaussian(s1) invalid A = gaussian(s1)*B+C; is correct; use one gaussian/uniform in each expression More...
 
std::mt19937 & GetRndEngine ()
 

Detailed Description

template<typename DType>
class mshadow::Random< cpu, DType >

CPU random number generator.

Constructor & Destructor Documentation

◆ Random()

template<typename DType >
mshadow::Random< cpu, DType >::Random ( int  seed)
inlineexplicit

constructor of random engine

Parameters
seedrandom number seed

◆ ~Random()

template<typename DType >
mshadow::Random< cpu, DType >::~Random ( void  )
inline

Member Function Documentation

◆ gaussian()

template<typename DType >
template<int dim>
expr::ReshapeExp<Tensor<cpu, 1, DType>, DType, dim, 1> mshadow::Random< cpu, DType >::gaussian ( Shape< dim >  shape)
inline

return a temporal expression storing standard gaussian random variables the temporal tensor is only valid before next call of gaussian or uniform can be used as part of expression Caution: this means expression such as A = gaussian(s1) * gaussian(s2) will give invalid result, since second call of gaussian(s2) makes gaussian(s1) invalid A = gaussian(s1)*B+C; is correct; use one gaussian/uniform in each expression

Parameters
shapeshape of the tensor
Returns
a temporal expression storing standard gaussian random variables
Template Parameters
dimdimension of tensor

◆ GetRandInt() [1/2]

template<typename DType >
unsigned mshadow::Random< cpu, DType >::GetRandInt ( )
inline

get some random integer

Returns
integer as unsigned

◆ GetRandInt() [2/2]

template<typename DType >
void mshadow::Random< cpu, DType >::GetRandInt ( const Tensor< cpu, 1, unsigned > &  dst)
inline

get a set of random integers

◆ GetRndEngine()

template<typename DType >
std::mt19937& mshadow::Random< cpu, DType >::GetRndEngine ( )
inline

◆ GetSeed()

template<typename DType >
unsigned mshadow::Random< cpu, DType >::GetSeed ( ) const
inline

get random seed used in random generator

Returns
seed in unsigned

◆ SampleDistribution()

template<typename DType >
template<int dim, class Sampler >
void mshadow::Random< cpu, DType >::SampleDistribution ( Tensor< cpu, dim, DType > *  dst,
Sampler  sampler 
)
inline

generate data from a distribution

Parameters
dstdestination
Template Parameters
dimdimension of tensor
Parameters
samplersampler of the distribution

◆ SampleExponential()

template<typename DType >
template<int dim, typename PType >
void mshadow::Random< cpu, DType >::SampleExponential ( Tensor< cpu, dim, DType > *  dst,
PType  lambda 
)
inline

generate data from an exponential distribution

Parameters
dstdestination
lambdaparameter (rate) of the distribution
Template Parameters
dimdimension of tensor

◆ SampleGamma()

template<typename DType >
template<int dim, typename PType >
void mshadow::Random< cpu, DType >::SampleGamma ( Tensor< cpu, dim, DType > *  dst,
PType  alpha,
PType  beta 
)
inline

generate data from a gamma distribution

Parameters
dstdestination
alpha(shape) parameter
beta(scale) parameter
Template Parameters
dimdimension of tensor

◆ SampleGaussian()

template<typename DType >
template<int dim, typename PType >
void mshadow::Random< cpu, DType >::SampleGaussian ( Tensor< cpu, dim, DType > *  dst,
PType  mu = 0.0f,
PType  sigma = 1.0f 
)
inline

generate data from standard gaussian

Parameters
dstdestination
mumean variable
sigmastandard deviation
Template Parameters
dimdimension of tensor

◆ SampleGeneralizedNegativeBinomial()

template<typename DType >
template<int dim, typename PType >
void mshadow::Random< cpu, DType >::SampleGeneralizedNegativeBinomial ( Tensor< cpu, dim, DType > *  dst,
PType  mu,
PType  alpha 
)
inline

generate data from a generalized negative binomial distribution

Parameters
dstdestination
muparameter (mean) of the distribution
alphaparameter (over dispersion) of the distribution (for alpha=0 this gives a Poisson)
Template Parameters
dimdimension of tensor

◆ SampleNegativeBinomial()

template<typename DType >
template<int dim, typename PType1 , typename PType2 >
void mshadow::Random< cpu, DType >::SampleNegativeBinomial ( Tensor< cpu, dim, DType > *  dst,
PType1  k,
PType2  p 
)
inline

generate data from a negative binomial distribution

Parameters
dstdestination
klimit on number of failures
psuccess probability
Template Parameters
dimdimension of tensor

◆ SamplePoisson()

template<typename DType >
template<int dim, typename PType >
void mshadow::Random< cpu, DType >::SamplePoisson ( Tensor< cpu, dim, DType > *  dst,
PType  lambda 
)
inline

generate data from a poisson distribution

Parameters
dstdestination
lambdaparameter (rate) of the distribution
Template Parameters
dimdimension of tensor

◆ SampleUniform()

template<typename DType >
template<int dim, typename PType >
void mshadow::Random< cpu, DType >::SampleUniform ( Tensor< cpu, dim, DType > *  dst,
PType  a = 0.0f,
PType  b = 1.0f 
)
inline

generate data from uniform [a,b)

Parameters
dstdestination
alower bound of uniform
bupper bound of uniform
Template Parameters
dimdimension of tensor

◆ Seed()

template<typename DType >
void mshadow::Random< cpu, DType >::Seed ( int  seed)
inline

seed random number generator using this seed

Parameters
seedseed of prng

◆ set_stream()

template<typename DType >
void mshadow::Random< cpu, DType >::set_stream ( Stream< cpu > *  stream)
inline

set the stream of computation

Parameters
streamcomputation stream

◆ uniform()

template<typename DType >
template<int dim>
expr::ReshapeExp<Tensor<cpu, 1, DType>, DType, dim, 1> mshadow::Random< cpu, DType >::uniform ( Shape< dim >  shape)
inline

return a temporal expression storing standard uniform [0,1) the temporal tensor is only valid before next call of gaussian or uniform can be used as part of expression Caution: this means expression such as A = uniform(s1) * uniform(s2) will give invalid result, since second call of gaussian(s2) makes gaussian(s1) invalid A = gaussian(s1)*B+C; is correct; use one gaussian/uniform in each expression

Parameters
shapeshape of the tensor
Returns
a temporal expression storing standard uniform [0,1)
Template Parameters
dimdimension of tensor

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