Run for uniform,gauss,layer
This commit is contained in:
parent
fb42b93a5f
commit
a3ac1c6d3d
|
@ -10,22 +10,19 @@
|
||||||
|
|
||||||
class BM1DProcess {
|
class BM1DProcess {
|
||||||
public:
|
public:
|
||||||
BM1DProcess(Int_t n); //n is the number of steps
|
BM1DProcess();
|
||||||
~BM1DProcess();
|
~BM1DProcess();
|
||||||
|
|
||||||
void SetP0(Double_t p0_new){p0 = p0_new;}
|
void Run(int nSteps, int nRuns, double p0, double p1);
|
||||||
void SetP1(Double_t p1_new){p1 = p1_new;}
|
void Run(int nSteps, int nRuns, double p0, double mu, double sigma);
|
||||||
|
void Run(int nSteps, int nRuns, double p0, double x1, double x2, double mu1, double sigma1, double mu2, double sigma2);
|
||||||
void Init();
|
|
||||||
void Run();
|
|
||||||
|
|
||||||
std::vector<Double_t> GetT(){return t;}
|
std::vector<Double_t> GetT(){return t;}
|
||||||
std::vector<Double_t> GetX(){return x;}
|
std::vector<Double_t> GetX(){return x;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Int_t nSteps;
|
|
||||||
Double_t p0,p1,p2,p3,p4;
|
|
||||||
TRandom* randomGenerator;
|
TRandom* randomGenerator;
|
||||||
|
TRandom* randomGeneratorGauss;
|
||||||
Double_t rand1;
|
Double_t rand1;
|
||||||
std::vector<Double_t> t;
|
std::vector<Double_t> t;
|
||||||
std::vector<Double_t> x;
|
std::vector<Double_t> x;
|
||||||
|
|
|
@ -1,40 +1,113 @@
|
||||||
#include "BM1DProcess.hh"
|
#include "BM1DProcess.hh"
|
||||||
|
|
||||||
BM1DProcess::BM1DProcess(Int_t nP) :
|
BM1DProcess::BM1DProcess()
|
||||||
nSteps (nP), p0(0.5), p1(0.3)
|
|
||||||
{
|
{
|
||||||
randomGenerator = new TRandom();
|
randomGenerator = new TRandom();
|
||||||
|
randomGeneratorGauss = new TRandom();
|
||||||
}
|
}
|
||||||
|
|
||||||
BM1DProcess::~BM1DProcess()
|
BM1DProcess::~BM1DProcess()
|
||||||
{
|
{
|
||||||
;
|
delete randomGenerator;
|
||||||
|
delete randomGeneratorGauss;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BM1DProcess::Init(){
|
|
||||||
t.push_back(0.0); //let's start at t=0, x=0, you can change it if you vant, please use Set methods
|
void BM1DProcess::Run(int nRuns, int nSteps, double p0, double p1)
|
||||||
x.push_back(0.0);
|
{
|
||||||
|
for(int i = 0; i < nRuns; i++) //multiple runs
|
||||||
|
{
|
||||||
|
t.push_back(0.0); //let's start at t=0, x=0, you can change it if you vant, please use Set methods
|
||||||
|
x.push_back(0.0);
|
||||||
|
|
||||||
|
for(int ii = 0; ii < nSteps ; ii++)
|
||||||
|
{
|
||||||
|
|
||||||
|
rand1 = randomGenerator->Uniform();
|
||||||
|
|
||||||
|
if(rand1 < p0) //step in time, but no step in x
|
||||||
|
{
|
||||||
|
t.push_back(t.back() + 1);
|
||||||
|
x.push_back(x.back());
|
||||||
|
}
|
||||||
|
|
||||||
|
else //step left or right
|
||||||
|
{
|
||||||
|
if(rand1 < p0 + p1)
|
||||||
|
{
|
||||||
|
t.push_back(t.back()+1);
|
||||||
|
x.push_back(x.back()+1); //one step right
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t.push_back(t.back() + 1);
|
||||||
|
x.push_back(x.back() - 1); //one step left
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BM1DProcess::Run(){
|
void BM1DProcess::Run(int nRuns, int nSteps, double p0, double mu, double sigma)
|
||||||
for (Int_t i = 1;i < nSteps;i++)
|
{
|
||||||
{
|
for(int i = 0; i < nRuns; i++) //multiple runs
|
||||||
rand1 = randomGenerator->Uniform();
|
{
|
||||||
if(rand1 < p0) { //step in time, but no step in x
|
t.push_back(0.0); //let's start at t=0, x=0, you can change it if you vant, please use Set methods
|
||||||
t.push_back(t[i-1] + 1);
|
x.push_back(0.0);
|
||||||
x.push_back(x[i-1]);
|
|
||||||
}
|
for(int ii = 0; ii < nSteps ; ii++)
|
||||||
else {//step left or right
|
{
|
||||||
if(rand1 < p0 + p1)
|
rand1 = randomGenerator->Uniform();
|
||||||
{
|
|
||||||
t.push_back(t[i-1]+1);
|
if(rand1 < p0) //step in time, but no step in x
|
||||||
x.push_back(x[i-1]+1); //one step right
|
{
|
||||||
}
|
t.push_back(t.back() + 1);
|
||||||
else
|
x.push_back(x.back());
|
||||||
{
|
}
|
||||||
t.push_back(t[i-1]+1);
|
|
||||||
x.push_back(x[i-1]-1); //one step left
|
else //step left or right
|
||||||
}
|
{
|
||||||
}
|
double randGauss = randomGeneratorGauss -> Gaus(mu,sigma);
|
||||||
}
|
t.push_back(t.back() + 1);
|
||||||
|
x.push_back(x.back() + randGauss); //one step right
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BM1DProcess::Run(int nRuns, int nSteps, double p0, double x1, double x2, double mu1, double sigma1, double mu2, double sigma2)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < nRuns; i++) //multiple runs
|
||||||
|
{
|
||||||
|
t.push_back(0.0); //let's start at t=0, x=0, you can change it if you vant, please use Set methods
|
||||||
|
x.push_back(0.0);
|
||||||
|
|
||||||
|
double randGauss;
|
||||||
|
|
||||||
|
for(int ii = 0; ii < nSteps ; ii++)
|
||||||
|
{
|
||||||
|
rand1 = randomGenerator->Uniform();
|
||||||
|
|
||||||
|
if(rand1 < p0) //step in time, but no step in x
|
||||||
|
{
|
||||||
|
t.push_back(t.back() + 1);
|
||||||
|
x.push_back(x.back());
|
||||||
|
}
|
||||||
|
|
||||||
|
else //step left or right
|
||||||
|
{
|
||||||
|
if(x.back() < x2 && x.back() > x1)
|
||||||
|
{
|
||||||
|
randGauss = randomGeneratorGauss -> Gaus(mu1,sigma1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
randGauss = randomGeneratorGauss -> Gaus(mu2,sigma2);
|
||||||
|
}
|
||||||
|
|
||||||
|
t.push_back(t.back() + 1);
|
||||||
|
x.push_back(x.back() + randGauss); //one step right
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue