mog_em_main.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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 }