original_ifgt_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 "original_ifgt.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 *ifgt_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 
00112   // The query data file defaults to the references.
00113   const char* queries_file_name =
00114     fx_param_str(NULL, "query", references_file_name);
00115 
00116   // query and reference datasets
00117   Matrix references;
00118   Matrix queries;
00119 
00120   // flag for telling whether references are equal to queries
00121   bool queries_equal_references =
00122     !strcmp(queries_file_name, references_file_name);
00123 
00124   // data::Load inits a matrix with the contents of a .csv or .arff.
00125   data::Load(references_file_name, &references);
00126   if(queries_equal_references) {
00127     queries.Alias(references);
00128   }
00129   else {
00130     data::Load(queries_file_name, &queries);
00131   }
00132 
00133   // confirm whether the user asked for scaling of the dataset
00134   if(!strcmp(fx_param_str(ifgt_kde_module, "scaling", "none"), "range")) {
00135     DatasetScaler::ScaleDataByMinMax(queries, references,
00136                                      queries_equal_references);
00137   }
00138 
00139   // declare IFGT-based KDE computation object and the vector holding
00140   // the final results
00141   OriginalIFGT ifgt_kde;
00142   Vector ifgt_kde_results;
00143   ifgt_kde.Init(queries, references, ifgt_kde_module);
00144   ifgt_kde.Compute();
00145   ifgt_kde.get_density_estimates(&ifgt_kde_results);
00146 
00147   // print out the results if the user specified the flag for output
00148   if(fx_param_exists(ifgt_kde_module, "ifgt_kde_output")) {
00149     ifgt_kde.PrintDebug();
00150   }
00151 
00152   // do naive computation and compare to the FGT computations if the
00153   // user specified --do_naive flag
00154   if(fx_param_exists(ifgt_kde_module, "do_naive")) {
00155     NaiveKde<GaussianKernel> naive_kde;
00156     naive_kde.Init(queries, references, ifgt_kde_module);
00157     naive_kde.Compute();
00158     
00159     if(fx_param_exists(ifgt_kde_module, "naive_kde_output")) {
00160       naive_kde.PrintDebug();
00161     }
00162     naive_kde.ComputeMaximumRelativeError(ifgt_kde_results);
00163   }
00164 
00165   fx_done(NULL);
00166   return 0;
00167 }
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3