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
00039 #include "fastlib/fastlib.h"
00040 #include "bandwidth_lscv.h"
00041 #include "dataset_scaler.h"
00042 #include "dualtree_kde.h"
00043 #include "naive_kde.h"
00044
00110 int main(int argc, char *argv[]) {
00111
00112
00113 fx_init(argc, argv, &kde_main_doc);
00114
00116
00117
00118
00119
00120
00121 struct datanode* kde_module = fx_submodule(fx_root, "kde");
00122
00123
00124 const char* references_file_name = fx_param_str_req(fx_root, "data");
00125
00126
00127 const char* queries_file_name =
00128 fx_param_str(fx_root, "query", references_file_name);
00129
00130
00131 Matrix references;
00132 Matrix reference_weights;
00133 Matrix queries;
00134
00135
00136 bool queries_equal_references =
00137 !strcmp(queries_file_name, references_file_name);
00138
00139
00140 data::Load(references_file_name, &references);
00141 if(queries_equal_references) {
00142 queries.Alias(references);
00143 }
00144 else {
00145 data::Load(queries_file_name, &queries);
00146 }
00147
00148
00149
00150 if(fx_param_exists(fx_root, "dwgts")) {
00151 data::Load(fx_param_str(fx_root, "dwgts", NULL), &reference_weights);
00152 }
00153 else {
00154 reference_weights.Init(1, queries.n_cols());
00155 reference_weights.SetAll(1);
00156 }
00157
00158
00159 if(!strcmp(fx_param_str(kde_module, "scaling", "none"), "range")) {
00160 DatasetScaler::ScaleDataByMinMax(queries, references,
00161 queries_equal_references);
00162 }
00163 else if(!strcmp(fx_param_str(kde_module, "scaling", "none"),
00164 "standardize")) {
00165 DatasetScaler::StandardizeData(queries, references,
00166 queries_equal_references);
00167 }
00168
00169
00170
00171 if(!strcmp(fx_param_str(kde_module, "task", "optimize"), "optimize")) {
00172
00173
00174 if(!strcmp(fx_param_str(kde_module, "kernel", "gaussian"), "gaussian")) {
00175 BandwidthLSCV::Optimize<GaussianKernelAux>(references,
00176 reference_weights);
00177 }
00178 else if(!strcmp(fx_param_str(kde_module, "kernel", "epan"), "epan")) {
00179
00180
00181
00182
00183
00184 BandwidthLSCV::Optimize<GaussianKernelAux>(references,
00185 reference_weights);
00186 }
00187 }
00188 else if(!strcmp(fx_param_str(kde_module, "task", "lscvscore"),
00189 "lscvscore")) {
00190
00191
00192 double bandwidth = fx_param_double(kde_module, "bandwidth", 0.1);
00193
00194
00195 if(!strcmp(fx_param_str(kde_module, "kernel", "gaussian"), "gaussian")) {
00196 BandwidthLSCV::ComputeLSCVScore<GaussianKernelAux>
00197 (references, reference_weights, bandwidth);
00198 }
00199 else if(!strcmp(fx_param_str(kde_module, "kernel", "epan"), "epan")) {
00200
00201
00202
00203
00204
00205 BandwidthLSCV::ComputeLSCVScore<GaussianKernelAux>
00206 (references, reference_weights, bandwidth);
00207 }
00208 }
00209
00210 fx_done(fx_root);
00211 return 0;
00212 }