This example demonstrates how to find the parameters of a MOG model via using the kmeans and EM based optimisers. Synthetic data is utilised.
#include <fstream>
#include <iostream>
#include <iomanip>
#include <ios>
using std::cout;
using std::endl;
using std::fixed;
using std::setprecision;
{
int N = 100000;
int D = 3;
int K = 5;
for (
int n = 0;n < N;n++) {
X(n).
set_size(D);
X(n) = 0.0; }
mu(0) = "-6, -4, -2";
mu(1) = "-4, -2, 0";
mu(2) = "-2, 0, 2";
mu(3) = " 0, +2, +4";
mu(4) = "+2, +4, +6";
var(0) = "0.1, 0.2, 0.3";
var(1) = "0.2, 0.3, 0.1";
var(2) = "0.3, 0.1, 0.2";
var(3) = "0.1, 0.2, 0.3";
var(4) = "0.2, 0.3, 0.1";
cout << "user configured means and variances:" << endl;
cout << "mu = " << mu << endl;
cout << "var = " << var << endl;
for (int n = 0;n < N;n++) {
for (int d = 0;d < D;d++) {
}
}
for (int n = 0;n < N;n++) {
for (int d = 0;d < D;d++) {
}
}
cout << endl << endl;
cout << "stats for X:" << endl;
for (int k = 0;k < K;k++) {
for (
int d = 0;d < D;d++) cout <<
" d = " << d <<
" mu_test = " <<
mu_test(k)(d) <<
" var_test = " <<
var_test(k)(d) << endl;
cout << endl;
}
cout << endl;
cout <<
"mog.avg_log_lhood(X) = " << mog.avg_log_lhood(
X) << endl;
cout << endl << endl;
cout << "running kmeans optimiser" << endl << endl;
cout << "mog.get_means() = " << endl << mog.get_means() << endl;
cout << "mog.get_diag_covs() = " << endl << mog.get_diag_covs() << endl;
cout << "mog.get_weights() = " << endl << mog.get_weights() << endl;
cout << endl;
cout <<
"mog.avg_log_lhood(X) = " << mog.avg_log_lhood(
X) << endl;
cout << endl << endl;
cout << "running ML optimiser" << endl << endl;
cout << "mog.get_means() = " << endl << mog.get_means() << endl;
cout << "mog.get_diag_covs() = " << endl << mog.get_diag_covs() << endl;
cout << "mog.get_weights() = " << endl << mog.get_weights() << endl;
cout << endl;
cout <<
"mog.avg_log_lhood(X) = " << mog.avg_log_lhood(
X) << endl;
return 0;
}
void set_size(int n, bool copy=false)
Resizing an Array<T>.
Diagonal Mixture of Gaussians (MOG) class.
void MOG_diag_ML(MOG_diag &model_in, Array< vec > &X_in, int max_iter_in, double var_floor_in, double weight_floor_in, bool verbose_in)
void MOG_diag_kmeans(MOG_diag &model_in, Array< vec > &X_in, int max_iter_in, double trust_in, bool normalise_in, bool verbose_in)
Include file for the IT++ statistics module.