1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-18 15:27:05 +01:00

multivariate Gaussian RNG

This commit is contained in:
2019-03-25 23:20:09 +00:00
parent 0bf6d8c8ae
commit e37f2ab124
4 changed files with 130 additions and 0 deletions

View File

@ -1,11 +1,15 @@
#include <LatAnalyze/Io/Io.hpp>
#include <LatAnalyze/Functional/CompiledFunction.hpp>
#include <LatAnalyze/Core/Plot.hpp>
#include <LatAnalyze/Statistics/Random.hpp>
#include <LatAnalyze/Statistics/MatSample.hpp>
using namespace std;
using namespace Latan;
constexpr Index size = 8;
constexpr Index nDraw = 20000;
constexpr Index nSample = 2000;
const string stateFileName = "exRand.seed";
int main(void)
@ -36,5 +40,24 @@ int main(void)
p << PlotFunction(compile("return exp(-x_0^2/2)/sqrt(2*pi);", 1), -5., 5.);
p.display();
DMat var(size, size);
DVec mean(size);
DMatSample sample(nSample, size, 1);
cout << "-- generating " << nSample << " Gaussian random vectors..." << endl;
var = DMat::Random(size, size);
var *= var.adjoint();
mean = DVec::Random(size);
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;
return EXIT_SUCCESS;
}