NeoPZ
TPZNormalRandom.h
Go to the documentation of this file.
1 /*
2  * File: TPZNormalRandom.h
3  * Author: quinelato
4  *
5  * Created on 5 de Dezembro de 2017, 15:25
6  */
7 
8 #ifndef TPZNORMALRANDOM_H
9 #define TPZNORMALRANDOM_H
10 
11 #include <random>
12 #include <functional>
13 #include <ctime>
14 #include "TPZRandom.h"
15 
16 template <typename TVar>
17 class TPZNormalRandom : virtual public TPZRandom<TVar> {
18 public:
19  TPZNormalRandom(TVar mean, TVar stdev) : mean(mean), stdev(stdev), generator(std::bind(std::normal_distribution<TVar>(mean, stdev), std::default_random_engine(clock()))){
20 
21  }
22 
24 
25  }
26 
27  virtual TPZRandom<TVar> *clone(){
28  return new TPZNormalRandom<TVar>(*this);
29  }
30 
31  virtual TVar next(){
32  return generator();
33  }
34 
35  TVar cdf(TVar x){
36  return 0.5*(1+std::erf((x-mean)/(stdev*M_SQRT2)));
37  }
38 
39  TVar pdf(TVar x){
40  TVar stdev_2 = pow(stdev,2.);
41  return 1./(sqrt(2*M_PI*stdev_2))*exp(-pow(x-mean,2)/(2*stdev_2));
42  }
43  virtual ~TPZNormalRandom(){
44 
45  }
46 protected:
47  TVar mean, stdev;
48 private :
49  std::function<TVar()> generator;
50 };
51 
52 #endif /* TPZNORMALRANDOM_H */
53 
virtual ~TPZNormalRandom()
virtual TVar next()
TVar pdf(TVar x)
virtual TPZRandom< TVar > * clone()
REAL erf(REAL arg)
Definition: pzreal.cpp:60
TPZNormalRandom(TVar mean, TVar stdev)
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
TPZNormalRandom(const TPZNormalRandom &orig)
TVar cdf(TVar x)
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
Definition: pzreal.h:487
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ exp
Definition: tfadfunc.h:125
std::function< TVar()> generator