nbc_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  */
00059 #include "simple_nbc.h"
00060 
00061 const fx_entry_doc parm_nbc_main_entries[] = {
00062   {"train", FX_REQUIRED, FX_STR, NULL,
00063    " A file containing the training set\n"},
00064   {"test", FX_REQUIRED, FX_STR, NULL,
00065    " A file containing the test set\n"},
00066   {"output", FX_PARAM, FX_STR, NULL,
00067    " The file in which the output of the test would be "
00068    "written (defaults to 'output.csv')\n"},
00069   FX_ENTRY_DOC_DONE
00070 };
00071 
00072 const fx_submodule_doc parm_nbc_main_submodules[] = {
00073   {"nbc", &parm_nbc_doc,
00074    " Trains on a given set and number of classes and "
00075    "tests them on a given set\n"},
00076   FX_SUBMODULE_DOC_DONE
00077 };
00078 
00079 const fx_module_doc parm_nbc_main_doc = {
00080   parm_nbc_main_entries, parm_nbc_main_submodules,
00081   "This program test drives the Parametric Naive Bayes \n"
00082   "Classifier assuming that the features are sampled \n"
00083   "from a Gaussian distribution.\n"
00084 };
00085 
00086 int main(int argc, char* argv[]) {
00087 
00088   fx_module *root = fx_init(argc, argv, &parm_nbc_main_doc);
00089 
00091 
00092   const char *training_data_filename = fx_param_str_req(root, "train");
00093   Matrix training_data;
00094   data::Load(training_data_filename, &training_data);
00095 
00096   const char *testing_data_filename = fx_param_str_req(root, "test");
00097   Matrix testing_data;
00098   data::Load(testing_data_filename, &testing_data);
00099 
00101 
00103   SimpleNaiveBayesClassifier nbc;
00104 
00105   struct datanode* nbc_module = fx_submodule(root, "nbc");
00106   
00108   fx_timer_start(nbc_module, "training");
00109 
00111   nbc.InitTrain(training_data, nbc_module);
00112 
00113   fx_timer_stop(nbc_module, "training");
00114 
00117   Vector results;
00118 
00119   fx_timer_start(nbc_module, "testing");
00120 
00122   nbc.Classify(testing_data, &results);
00123 
00124   fx_timer_stop(nbc_module, "testing");
00125 
00127 
00128   const char *output_filename = fx_param_str(root, "output", "output.csv");
00129 
00130   FILE *output_file = fopen(output_filename, "w");
00131 
00132   ot::Print(results, output_file);
00133 
00134   fclose(output_file);
00135 
00136   fx_done(root);
00137 
00138   return 1;
00139 }
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3