2019-02-10 00:23:36 +00:00
|
|
|
#include <LatAnalyze/Io/Io.hpp>
|
|
|
|
#include <LatAnalyze/Functional/CompiledFunction.hpp>
|
|
|
|
#include <LatAnalyze/Core/Plot.hpp>
|
2019-03-25 23:20:09 +00:00
|
|
|
#include <LatAnalyze/Statistics/Random.hpp>
|
|
|
|
#include <LatAnalyze/Statistics/MatSample.hpp>
|
2014-02-10 16:01:39 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Latan;
|
|
|
|
|
2023-06-20 15:47:58 +01:00
|
|
|
constexpr Index n = 8;
|
2015-09-28 18:18:54 +01:00
|
|
|
constexpr Index nDraw = 20000;
|
2019-03-25 23:20:09 +00:00
|
|
|
constexpr Index nSample = 2000;
|
2015-09-28 18:18:54 +01:00
|
|
|
const string stateFileName = "exRand.seed";
|
2014-02-10 16:01:39 +00:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2016-04-06 20:04:23 +01:00
|
|
|
random_device rd;
|
|
|
|
mt19937 gen(rd());
|
|
|
|
normal_distribution<> dis;
|
|
|
|
DVec gauss(nDraw);
|
|
|
|
Plot p;
|
|
|
|
Histogram h;
|
2014-02-10 16:01:39 +00:00
|
|
|
|
2015-09-28 18:18:54 +01:00
|
|
|
cout << "-- generating " << nDraw << " Gaussian random numbers..." << endl;
|
|
|
|
FOR_VEC(gauss, i)
|
|
|
|
{
|
2016-04-06 20:04:23 +01:00
|
|
|
gauss(i) = dis(gen);
|
2015-09-28 18:18:54 +01:00
|
|
|
}
|
|
|
|
h.setFromData(gauss, -5., 5., 40);
|
|
|
|
h.normalize();
|
2015-11-24 16:27:47 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-09-28 18:18:54 +01:00
|
|
|
p << PlotHistogram(h);
|
|
|
|
p << PlotFunction(compile("return exp(-x_0^2/2)/sqrt(2*pi);", 1), -5., 5.);
|
|
|
|
p.display();
|
|
|
|
|
2023-06-20 15:47:58 +01:00
|
|
|
DMat var(n, n);
|
|
|
|
DVec mean(n);
|
|
|
|
DMatSample sample(nSample, n, 1);
|
2019-03-25 23:20:09 +00:00
|
|
|
|
|
|
|
cout << "-- generating " << nSample << " Gaussian random vectors..." << endl;
|
2023-06-20 15:47:58 +01:00
|
|
|
var = DMat::Random(n, n);
|
2019-03-25 23:20:09 +00:00
|
|
|
var *= var.adjoint();
|
2023-06-20 15:47:58 +01:00
|
|
|
mean = DVec::Random(n);
|
2019-03-25 23:20:09 +00:00
|
|
|
RandomNormal mgauss(mean, var, rd());
|
|
|
|
sample[central] = mgauss();
|
|
|
|
FOR_STAT_ARRAY(sample, s)
|
|
|
|
{
|
|
|
|
sample[s] = mgauss();
|
|
|
|
}
|
|
|
|
cout << "* original variance matrix:\n" << var << endl;
|
|
|
|
cout << "* measured variance matrix:\n" << sample.varianceMatrix() << endl;
|
|
|
|
cout << "* original mean:\n" << mean << endl;
|
|
|
|
cout << "* measured mean:\n" << sample.mean() << endl;
|
|
|
|
|
2014-02-10 16:01:39 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|