test1.cpp

Go to the documentation of this file.
00001 #include "indii/ml/aux/GaussianPdf.hpp"
00002 #include "indii/ml/aux/vector.hpp"
00003 #include "indii/ml/aux/matrix.hpp"
00004 #include "indii/ml/aux/Random.hpp"
00005 
00006 #include "gsl/gsl_statistics_double.h"
00007 
00008 #include <iostream>
00009 
00010 using namespace std;
00011 
00012 namespace aux = indii::ml::aux;
00013 
00014 /**
00015  * @file test1.cpp
00016  *
00017  * Basic test of GaussianPdf.
00018  *
00019  * This test creates a one dimensional Gaussian with a random mean and
00020  * variance. It then samples from this distribution and calculates the
00021  * sample mean and variance for comparison.
00022  *
00023  * Results are as follows:
00024  *
00025  * @include test1.out
00026  */
00027 
00028 /**
00029  * Number of samples to take.
00030  */
00031 unsigned int N = 100000;
00032 
00033 /**
00034  * Run tests.
00035  */
00036 int main(int argc, const char* argv[]) {
00037   aux::vector mu(1);
00038   aux::symmetric_matrix sigma(1);
00039   aux::vector sample;
00040   double data[N];
00041   unsigned int i;
00042 
00043   /* set up distribution */
00044   mu(0) = aux::Random::uniform(-5.0, 5.0);
00045   sigma(0,0) = aux::Random::uniform(0.0, 5.0);
00046   aux::GaussianPdf pdf(mu, sigma);
00047 
00048   /* sample from distribution */
00049   for (i = 0; i < N; i++) {
00050     sample = pdf.sample();
00051     data[i] = sample(0);
00052   }
00053 
00054   /* calculate mean and variance of samples */
00055   cout << "True mean = " << mu(0) << endl;
00056   cout << "True variance = " << sigma(0,0) << endl;
00057   cout << "Sample mean = " << gsl_stats_mean(data, 1, N) << endl;
00058   cout << "Sample variance = " << gsl_stats_variance(data, 1, N) << endl;
00059 }

Generated on Wed Dec 17 15:01:30 2008 for dysii Probability Distributions Test Suite by  doxygen 1.5.3