forked from aportelli/LatAnalyze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexRand.cpp
40 lines (34 loc) · 1.07 KB
/
exRand.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/CompiledFunction.hpp>
#include <LatAnalyze/Plot.hpp>
using namespace std;
using namespace Latan;
constexpr Index nDraw = 20000;
const string stateFileName = "exRand.seed";
int main(void)
{
random_device rd;
mt19937 gen(rd());
normal_distribution<> dis;
DVec gauss(nDraw);
Plot p;
Histogram h;
cout << "-- generating " << nDraw << " Gaussian random numbers..." << endl;
FOR_VEC(gauss, i)
{
gauss(i) = dis(gen);
}
h.setFromData(gauss, -5., 5., 40);
h.normalize();
cout << " median= " << h.median() << endl;
for (double s = 1.; s < 5.; ++s)
{
auto ci = h.confidenceInterval(s);
cout << static_cast<int>(s) << " sigma(s) interval= [";
cout << ci.first << ", " << ci.second << "]" << endl;
}
p << PlotHistogram(h);
p << PlotFunction(compile("return exp(-x_0^2/2)/sqrt(2*pi);", 1), -5., 5.);
p.display();
return EXIT_SUCCESS;
}