mog_em_main.cc

Go to the documentation of this file.
00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00055 #include "mog_em.h"
00056 
00057 const fx_entry_doc mog_em_main_entries[] = {
00058   {"data", FX_REQUIRED, FX_STR, NULL,
00059    " A file containing the data on which the model"
00060    " has to be fit.\n"},
00061   {"output", FX_PARAM, FX_STR, NULL,
00062    " The file into which the output is to be written into.\n"},
00063   FX_ENTRY_DOC_DONE
00064 };
00065 
00066 const fx_submodule_doc mog_em_main_submodules[] = {
00067   {"mog_em", &mog_em_doc,
00068    " Responsible for intializing the model and"
00069    " computing the parameters.\n"},
00070   FX_SUBMODULE_DOC_DONE
00071 };
00072 
00073 const fx_module_doc mog_em_main_doc = {
00074   mog_em_main_entries, mog_em_main_submodules,
00075   " This program test drives the parametric estimation "
00076   "of a Gaussian mixture model using maximum likelihood.\n"
00077 };
00078 
00079 int main(int argc, char* argv[]) {
00080 
00081   fx_module *root = 
00082     fx_init(argc, argv, &mog_em_main_doc);
00083 
00085   
00086   const char *data_filename = fx_param_str_req(root, "data");
00087 
00088   Matrix data_points;
00089   data::Load(data_filename, &data_points);
00090 
00092 
00093   MoGEM mog;
00094 
00095   struct datanode* mog_em_module = 
00096     fx_submodule(root, "mog_em");
00097   fx_param_int(mog_em_module, "K", 1);
00098   fx_set_param_int(mog_em_module, "D", data_points.n_rows());
00099 
00101   fx_timer_start(mog_em_module, "model_init");
00102   mog.Init(mog_em_module);
00103   fx_timer_stop(mog_em_module, "model_init");
00104 
00106   ArrayList<double> results;
00107 
00108   fx_timer_start(mog_em_module, "EM");
00109   mog.ExpectationMaximization(data_points);
00110   fx_timer_stop(mog_em_module, "EM");
00111   
00112   mog.Display();
00113   mog.OutputResults(&results);
00114 
00116 
00117   const char *output_filename = fx_param_str(NULL, "output", "output.csv");
00118 
00119   FILE *output_file = fopen(output_filename, "w");
00120 
00121   ot::Print(results, output_file);
00122   fclose(output_file);
00123   fx_done(root);
00124 
00125   return 1;
00126 }
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3