fgt_kde_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  */
00039 #include <fastlib/fastlib.h>
00040 #include "dataset_scaler.h"
00041 #include "fgt_kde.h"
00042 #include "naive_kde.h"
00043 
00095 int main(int argc, char *argv[]) {
00096 
00097   // initialize FastExec (parameter handling stuff)
00098   fx_init(argc, argv, NULL);
00099   
00101 
00102   // FASTexec organizes parameters and results into submodules.  Think
00103   // of this as creating a new folder named "fgt_kde_module" under the
00104   // root directory (NULL) for the Kde object to work inside.  Here,
00105   // we initialize it with all parameters defined "--kde/...=...".
00106   struct datanode *fgt_kde_module =
00107     fx_submodule(fx_root, "kde");
00108 
00109   // The reference data file is a required parameter.
00110   const char* references_file_name = fx_param_str_req(NULL, "data");
00111   printf("%s\n",references_file_name);
00112 
00113   // The query data file defaults to the references.
00114   const char* queries_file_name =
00115     fx_param_str(NULL, "query", references_file_name);
00116 
00117   // query and reference datasets
00118   Matrix references;
00119   Matrix queries;
00120 
00121   // flag for telling whether references are equal to queries
00122   bool queries_equal_references =
00123     !strcmp(queries_file_name, references_file_name);
00124 
00125   // data::Load inits a matrix with the contents of a .csv or .arff.
00126   data::Load(references_file_name, &references);
00127   if(queries_equal_references) {
00128     queries.Alias(references);
00129   }
00130   else {
00131     data::Load(queries_file_name, &queries);
00132   }
00133 
00134   // confirm whether the user asked for scaling of the dataset
00135   if(!strcmp(fx_param_str(fgt_kde_module, "scaling", "none"), "range")) {
00136     DatasetScaler::ScaleDataByMinMax(queries, references,
00137                                      queries_equal_references);
00138   }
00139 
00140   // declare FGT-based KDE computation object and the vector holding
00141   // the final results
00142   FGTKde fgt_kde;
00143   Vector fgt_kde_results;
00144 
00145   fgt_kde.Init(queries, references, fgt_kde_module);
00146   fgt_kde.Compute();
00147   fgt_kde.get_density_estimates(&fgt_kde_results);
00148 
00149   // print out the results if the user specified the flag for output
00150   if(fx_param_exists(fgt_kde_module, "fgt_kde_output")) {
00151     fgt_kde.PrintDebug();
00152   }
00153 
00154   // do naive computation and compare to the FGT computations if the
00155   // user specified --do_naive flag
00156   if(fx_param_exists(fgt_kde_module, "do_naive")) {
00157     NaiveKde<GaussianKernel> naive_kde;
00158     naive_kde.Init(queries, references, fgt_kde_module);
00159     naive_kde.Compute();
00160     
00161     if(fx_param_exists(fgt_kde_module, "naive_kde_output")) {
00162       naive_kde.PrintDebug();
00163     }
00164     naive_kde.ComputeMaximumRelativeError(fgt_kde_results);
00165   }
00166 
00167   fx_done(fx_root);
00168   return 0;
00169 }
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3