0

I am trying to use armadillo's expectation maximization maximization gmm_diag class, but when I try to compile it I get "error gmm_diag was not declared in this scope".

My code is as follows:

#include <stdio.h>
#include <iostream>
#include <vector>
#include <armadillo>
#include <omp.h>
using namespace std;
using namespace arma;
  int main()
  {


    // create synthetic data with 2 Gaussians

    uword N = 10000;
    uword d = 5;

    mat data(d, N, fill::zeros);

    vec mean0 = linspace<vec>(1,d,d);
    vec mean1 = mean0 + 2;

    uword i = 0;

    while(i < N)
      {
      if(i < N)  { data.col(i) = mean0 + randn<vec>(d); ++i; }
      if(i < N)  { data.col(i) = mean0 + randn<vec>(d); ++i; }
      if(i < N)  { data.col(i) = mean1 + randn<vec>(d); ++i; }
      }


    gmm_diag model;
    model.learn(data, 2, maha_dist, random_subset, 10, 5, 1e-10, true);
    model.means.print("means:");
    double  scalar_likelihood = model.log_p( data.col(0)    );
    rowvec     set_likelihood = model.log_p( data.cols(0,9));
    double overall_likelihood = model.avg_log_p(data);

    uword   gaus_id  = model.assign( data.col(0),    eucl_dist );
    urowvec gaus_ids = model.assign( data.cols(0,9), prob_dist );

    urowvec hist1 = model.raw_hist (data, prob_dist);
    rowvec hist2 = model.norm_hist(data, eucl_dist);

    model.save("my_model.gmm");
    // the table is now initialized
 }
Alex Riley
  • 169,130
  • 45
  • 262
  • 238
Sisay Zinabu
  • 71
  • 2
  • 14
  • You need to upgrade to a newer version of Armadillo. The [gmm_diag class](http://arma.sourceforge.net/docs.html#gmm_diag) is available from version 4.400 onwards. See the list of [Armadillo API additions](http://arma.sourceforge.net/docs.html#api_additions). – mtall Oct 29 '14 at 02:23
  • Thank u mtall it works well really thank u. But now I need some brief explanetion how I give input for expectation maximization I have 15 dimentional multi-variant data thank u very much for your help please – Sisay Zinabu Oct 29 '14 at 04:22
  • I need more rather than this http://arma.sourceforge.net/docs.html#gmm_diag – Sisay Zinabu Oct 29 '14 at 04:27
  • I need out put from expectation maximization the last estimated mean, covariance and mixture waight – Sisay Zinabu Oct 29 '14 at 04:51
  • as explained in the documentation, the .learn() function runs the expectation maximization (EM) algorithm – mtall Oct 29 '14 at 07:29
  • you are right mtall what I am not understand there is I expect 15X15 co-variance output based on my input, but it gives me 15X1 co-variance for each Gaussian and also how can i get posterior probability – Sisay Zinabu Oct 29 '14 at 08:16
  • I know this is an old post, but nonetheless; the sample code posted above has dimension 5, hence the fcovs should be of dimensions 5x5. – StarShine Jan 05 '21 at 15:35

0 Answers0