From dba50f2be70b444ea53778284c06ad878bcff047 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Fri, 29 Jul 2011 11:31:23 +0200 Subject: [PATCH] -made search space smaller -removed stuff from stacdk to heap to be able to trace memory blocks -cleaned up comments --- .../modelselection_grid_search_kernel.cpp | 26 ++++++++++--------- .../modelselection_grid_search_linear.cpp | 8 +++--- ...delselection_grid_search_string_kernel.cpp | 16 +++++++----- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/examples/undocumented/libshogun/modelselection_grid_search_kernel.cpp b/examples/undocumented/libshogun/modelselection_grid_search_kernel.cpp index c73a122817e..9684fc83b13 100644 --- a/examples/undocumented/libshogun/modelselection_grid_search_kernel.cpp +++ b/examples/undocumented/libshogun/modelselection_grid_search_kernel.cpp @@ -36,18 +36,18 @@ CModelSelectionParameters* create_param_tree() CModelSelectionParameters* c1=new CModelSelectionParameters("C1"); root->append_child(c1); - c1->build_values(-5.0, 3.0, R_EXP); + c1->build_values(-1.0, 1.0, R_EXP); CModelSelectionParameters* c2=new CModelSelectionParameters("C2"); root->append_child(c2); - c2->build_values(-5.0, 3.0, R_EXP); + c2->build_values(-1.0, 1.0, R_EXP); CGaussianKernel* gaussian_kernel=new CGaussianKernel(); CModelSelectionParameters* param_gaussian_kernel= new CModelSelectionParameters("kernel", gaussian_kernel); CModelSelectionParameters* gaussian_kernel_width= new CModelSelectionParameters("width"); - gaussian_kernel_width->build_values(-5.0, 3.0, R_EXP, 1.0, 2.0); + gaussian_kernel_width->build_values(-1.0, 1.0, R_EXP, 1.0, 2.0); param_gaussian_kernel->append_child(gaussian_kernel_width); root->append_child(param_gaussian_kernel); @@ -59,7 +59,7 @@ CModelSelectionParameters* create_param_tree() CModelSelectionParameters* param_power_kernel_degree= new CModelSelectionParameters("degree"); - param_power_kernel_degree->build_values(1.0, 3.0, R_LINEAR); + param_power_kernel_degree->build_values(1.0, 2.0, R_LINEAR); param_power_kernel->append_child(param_power_kernel_degree); CMinkowskiMetric* m_metric=new CMinkowskiMetric(10); @@ -70,7 +70,7 @@ CModelSelectionParameters* create_param_tree() CModelSelectionParameters* param_power_kernel_metric1_k= new CModelSelectionParameters("k"); - param_power_kernel_metric1_k->build_values(1.0, 3.0, R_LINEAR); + param_power_kernel_metric1_k->build_values(1.0, 2.0, R_LINEAR); param_power_kernel_metric1->append_child(param_power_kernel_metric1_k); return root; @@ -98,7 +98,7 @@ int main(int argc, char **argv) for (index_t i=0; iset_label(i, i%2==0 ? 1 : -1); - /* create linear classifier (use -s 2 option to avoid warnings) */ + /* create svm */ CLibSVM* classifier=new CLibSVM(); /* splitting strategy */ @@ -109,26 +109,27 @@ int main(int argc, char **argv) CContingencyTableEvaluation* evaluation_criterium= new CContingencyTableEvaluation(ACCURACY); - /* cross validation class for evaluation in model selection, 3 repetitions */ + /* cross validation class for evaluation in model selection */ CCrossValidation* cross=new CCrossValidation(classifier, features, labels, splitting_strategy, evaluation_criterium); - cross->set_num_runs(3); + cross->set_num_runs(1); /* model parameter selection, deletion is handled by modsel class (SG_UNREF) */ CModelSelectionParameters* param_tree=create_param_tree(); param_tree->print_tree(); - /* this is on the stack and handles all of the above structures in memory */ - CGridSearchModelSelection grid_search(param_tree, cross); + /* handles all of the above structures in memory */ + CGridSearchModelSelection* grid_search=new CGridSearchModelSelection( + param_tree, cross); - CParameterCombination* best_combination=grid_search.select_model(); + CParameterCombination* best_combination=grid_search->select_model(); SG_SPRINT("best parameter(s):\n"); best_combination->print_tree(); best_combination->apply_to_machine(classifier); /* larger number of runs to have tighter confidence intervals */ - cross->set_num_runs(100); + cross->set_num_runs(10); cross->set_conf_int_alpha(0.01); CrossValidationResult result=cross->evaluate(); SG_SPRINT("result: "); @@ -136,6 +137,7 @@ int main(int argc, char **argv) /* clean up destroy result parameter */ SG_UNREF(best_combination); + SG_UNREF(grid_search); SG_SPRINT("\nEND\n"); exit_shogun(); diff --git a/examples/undocumented/libshogun/modelselection_grid_search_linear.cpp b/examples/undocumented/libshogun/modelselection_grid_search_linear.cpp index 317ba06afc4..8bdd4f9c5ac 100644 --- a/examples/undocumented/libshogun/modelselection_grid_search_linear.cpp +++ b/examples/undocumented/libshogun/modelselection_grid_search_linear.cpp @@ -79,9 +79,11 @@ int main(int argc, char **argv) /* model parameter selection, deletion is handled by modsel class (SG_UNREF) */ CModelSelectionParameters* param_tree=create_param_tree(); + param_tree->print_tree(); - /* this is on the stack and handles all of the above structures in memory */ - CGridSearchModelSelection* grid_search=new CGridSearchModelSelection(param_tree, cross); + /* handles all of the above structures in memory */ + CGridSearchModelSelection* grid_search=new CGridSearchModelSelection( + param_tree, cross); CParameterCombination* best_combination=grid_search->select_model(); SG_SPRINT("best parameter(s):\n"); @@ -91,7 +93,7 @@ int main(int argc, char **argv) CrossValidationResult result=cross->evaluate(); result.print_result(); - /* clean up destroy result parameter */ + /* clean up */ SG_UNREF(best_combination); SG_UNREF(grid_search); diff --git a/examples/undocumented/libshogun/modelselection_grid_search_string_kernel.cpp b/examples/undocumented/libshogun/modelselection_grid_search_string_kernel.cpp index 5f1f58e56f9..6c65358c94c 100644 --- a/examples/undocumented/libshogun/modelselection_grid_search_string_kernel.cpp +++ b/examples/undocumented/libshogun/modelselection_grid_search_string_kernel.cpp @@ -111,33 +111,35 @@ int main(int argc, char **argv) CContingencyTableEvaluation* evaluation_criterium= new CContingencyTableEvaluation(ACCURACY); - /* cross validation class for evaluation in model selection, 3 repetitions */ + /* cross validation class for evaluation in model selection */ CCrossValidation* cross=new CCrossValidation(classifier, features, labels, splitting_strategy, evaluation_criterium); - cross->set_num_runs(3); + cross->set_num_runs(2); /* model parameter selection, deletion is handled by modsel class (SG_UNREF) */ CModelSelectionParameters* param_tree=create_param_tree(); param_tree->print_tree(); - /* this is on the stack and handles all of the above structures in memory */ - CGridSearchModelSelection grid_search(param_tree, cross); + /* handles all of the above structures in memory */ + CGridSearchModelSelection* grid_search=new CGridSearchModelSelection( + param_tree, cross); - CParameterCombination* best_combination=grid_search.select_model(); + CParameterCombination* best_combination=grid_search->select_model(); SG_SPRINT("best parameter(s):\n"); best_combination->print_tree(); best_combination->apply_to_machine(classifier); /* larger number of runs to have tighter confidence intervals */ - cross->set_num_runs(100); + cross->set_num_runs(10); cross->set_conf_int_alpha(0.01); CrossValidationResult result=cross->evaluate(); SG_SPRINT("result: "); result.print_result(); - /* clean up destroy result parameter */ + /* clean up */ SG_UNREF(best_combination); + SG_UNREF(grid_search); exit_shogun();