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