Public Member Functions | Private Attributes | List of all members
WireCell::Gen::Random Class Reference

#include <Random.h>

Inheritance diagram for WireCell::Gen::Random:
WireCell::IRandom WireCell::IConfigurable WireCell::IComponent< IRandom > WireCell::IComponent< IConfigurable > WireCell::Interface WireCell::Interface

Public Member Functions

 Random (const std::string &generator="default", const std::vector< unsigned int > seeds={0, 0, 0, 0, 0})
 
virtual ~Random ()
 
virtual void configure (const WireCell::Configuration &config)
 Accept a configuration. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
virtual int binomial (int max, double prob)
 Sample a binomial distribution. More...
 
virtual int poisson (double mean)
 Sample a Poisson distribution. More...
 
virtual double normal (double mean, double sigma)
 Sample a normal distribution. More...
 
virtual double uniform (double begin, double end)
 Sample a uniform distribution. More...
 
virtual double exponential (double mean)
 Sample an exponential distribution. More...
 
virtual int range (int first, int last)
 Sample a uniform integer range. More...
 
- Public Member Functions inherited from WireCell::IRandom
virtual ~IRandom ()
 
- Public Member Functions inherited from WireCell::IComponent< IRandom >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 
- Public Member Functions inherited from WireCell::IConfigurable
virtual ~IConfigurable ()
 
- Public Member Functions inherited from WireCell::IComponent< IConfigurable >
virtual ~IComponent ()
 

Private Attributes

std::string m_generator
 
std::vector< unsigned int > m_seeds
 
IRandomm_pimpl
 

Additional Inherited Members

- Public Types inherited from WireCell::IComponent< IRandom >
typedef std::shared_ptr< IRandompointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Public Types inherited from WireCell::Interface
typedef std::shared_ptr< Interfacepointer
 
- Public Types inherited from WireCell::IComponent< IConfigurable >
typedef std::shared_ptr< IConfigurablepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 

Detailed Description

Definition at line 14 of file Random.h.

Constructor & Destructor Documentation

Gen::Random::Random ( const std::string generator = "default",
const std::vector< unsigned int >  seeds = {0,0,0,0,0} 
)

Definition at line 25 of file Random.cxx.

28  , m_seeds(seeds.begin(), seeds.end())
29  , m_pimpl(nullptr)
30 {
31 }
std::string m_generator
Definition: Random.h:43
std::vector< unsigned int > m_seeds
Definition: Random.h:44
generator
Definition: train.py:468
IRandom * m_pimpl
Definition: Random.h:45
virtual WireCell::Gen::Random::~Random ( )
inlinevirtual

Definition at line 18 of file Random.h.

18 {}

Member Function Documentation

int Gen::Random::binomial ( int  max,
double  prob 
)
virtual

Sample a binomial distribution.

Implements WireCell::IRandom.

Definition at line 109 of file Random.cxx.

110 {
111  return m_pimpl->binomial(max, prob);
112 }
static int max(int a, int b)
IRandom * m_pimpl
Definition: Random.h:45
virtual int binomial(int max, double prob)=0
Sample a binomial distribution.
void Gen::Random::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 71 of file Random.cxx.

72 {
73  auto jseeds = cfg["seeds"];
74  if (not jseeds.isNull()) {
75  std::vector<unsigned int> seeds;
76  for (auto jseed : jseeds) {
77  seeds.push_back(jseed.asInt());
78  }
79  m_seeds = seeds;
80  }
81  auto gen = get(cfg,"generator",m_generator);
82  if (m_pimpl) {
83  delete m_pimpl;
84  }
85  if (gen == "default") {
87  }
88  else if (gen == "twister") {
90  }
91  else {
92  warn("Gen::Random::configure: warning: unknown random engine: \"{}\" using default", gen);
94  }
95 }
cfg
Definition: dbjson.py:29
std::string m_generator
Definition: Random.h:43
std::vector< unsigned int > m_seeds
Definition: Random.h:44
IRandom * m_pimpl
Definition: Random.h:45
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:13
WireCell::Configuration Gen::Random::default_configuration ( ) const
virtual

Optional, override to return a hard-coded default configuration.

Reimplemented from WireCell::IConfigurable.

Definition at line 97 of file Random.cxx.

98 {
100  cfg["generator"] = m_generator;
101  Json::Value jseeds(Json::arrayValue);
102  for (auto seed : m_seeds) {
103  jseeds.append(seed);
104  }
105  cfg["seeds"] = jseeds;
106  return cfg;
107 }
cfg
Definition: dbjson.py:29
std::string m_generator
Definition: Random.h:43
std::vector< unsigned int > m_seeds
Definition: Random.h:44
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2106
Json::Value Configuration
Definition: Configuration.h:50
double Gen::Random::exponential ( double  mean)
virtual

Sample an exponential distribution.

Implements WireCell::IRandom.

Definition at line 128 of file Random.cxx.

129 {
130  return m_pimpl->exponential(mean);
131 }
virtual double exponential(double mean)=0
Sample an exponential distribution.
IRandom * m_pimpl
Definition: Random.h:45
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:15
double Gen::Random::normal ( double  mean,
double  sigma 
)
virtual

Sample a normal distribution.

Implements WireCell::IRandom.

Definition at line 118 of file Random.cxx.

119 {
120  return m_pimpl->normal(mean, sigma);
121 }
virtual double normal(double mean, double sigma)=0
Sample a normal distribution.
IRandom * m_pimpl
Definition: Random.h:45
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:15
int Gen::Random::poisson ( double  mean)
virtual

Sample a Poisson distribution.

Implements WireCell::IRandom.

Definition at line 113 of file Random.cxx.

114 {
115  return m_pimpl->poisson(mean);
116 }
virtual int poisson(double mean)=0
Sample a Poisson distribution.
IRandom * m_pimpl
Definition: Random.h:45
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:15
int Gen::Random::range ( int  first,
int  last 
)
virtual

Sample a uniform integer range.

Implements WireCell::IRandom.

Definition at line 133 of file Random.cxx.

134 {
135  return m_pimpl->range(first, last);
136 }
IRandom * m_pimpl
Definition: Random.h:45
virtual int range(int first, int last)=0
Sample a uniform integer range.
double Gen::Random::uniform ( double  begin,
double  end 
)
virtual

Sample a uniform distribution.

Implements WireCell::IRandom.

Definition at line 123 of file Random.cxx.

124 {
125  return m_pimpl->uniform(begin, end);
126 }
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:72
virtual double uniform(double begin, double end)=0
Sample a uniform distribution.
IRandom * m_pimpl
Definition: Random.h:45
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:67

Member Data Documentation

std::string WireCell::Gen::Random::m_generator
private

Definition at line 43 of file Random.h.

IRandom* WireCell::Gen::Random::m_pimpl
private

Definition at line 45 of file Random.h.

std::vector<unsigned int> WireCell::Gen::Random::m_seeds
private

Definition at line 44 of file Random.h.


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