SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GridSearchModelSelection.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011 Heiko Strathmann
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
10 
15 #include <shogun/machine/Machine.h>
16 
17 using namespace shogun;
18 
20  CModelSelection(NULL, NULL)
21 {
22 
23 }
24 
26  CModelSelectionParameters* model_parameters,
27  CCrossValidation* cross_validation) :
28  CModelSelection(model_parameters, cross_validation)
29 {
30 
31 }
32 
34 {
35 }
36 
38 {
39  /* Retrieve all possible parameter combinations */
42 
43  CrossValidationResult best_result;
44 
45  CParameterCombination* best_combination=NULL;
47  best_result.mean=CMath::ALMOST_NEG_INFTY;
48  else
49  best_result.mean=CMath::ALMOST_INFTY;
50 
51  /* underlying learning machine */
53 
54  /* apply all combinations and search for best one */
55  for (index_t i=0; i<combinations->get_num_elements(); ++i)
56  {
57  CParameterCombination* current_combination=combinations->get_element(i);
58  current_combination->apply_to_modsel_parameter(
59  machine->m_model_selection_parameters);
61 
62  /* check if current result is better, delete old combinations */
64  {
65  if (result.mean>best_result.mean)
66  {
67  if (best_combination)
68  SG_UNREF(best_combination);
69 
70  best_combination=combinations->get_element(i);
71  best_result=result;
72  }
73  else
74  {
75  CParameterCombination* combination=combinations->get_element(i);
76  SG_UNREF(combination);
77  }
78  }
79  else
80  {
81  if (result.mean<best_result.mean)
82  {
83  if (best_combination)
84  SG_UNREF(best_combination);
85 
86  best_combination=combinations->get_element(i);
87  best_result=result;
88  }
89  else
90  {
91  CParameterCombination* combination=combinations->get_element(i);
92  SG_UNREF(combination);
93  }
94  }
95 
96  SG_UNREF(current_combination);
97  }
98 
99  SG_UNREF(machine);
100  SG_UNREF(combinations);
101 
102  return best_combination;
103 }
104 

SHOGUN Machine Learning Toolbox - Documentation