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 
base class for cross-validation evaluation. Given a learning machine, a splitting strategy...
T * get_element(int32_t index) const
void apply_to_modsel_parameter(Parameter *parameter) const
CrossValidationResult evaluate()
virtual CParameterCombination * select_model()
CCrossValidation * m_cross_validation
CDynamicObjectArray< CParameterCombination > * get_combinations()
A generic learning machine interface.
Definition: Machine.h:96
Class to select parameters and their ranges for model selection. The structure is organized as a tree...
type to encapsulate the results of an evaluation run. May contain confidence interval (if conf_int_al...
static const float64_t ALMOST_NEG_INFTY
almost neg (log) infinity
Definition: Math.h:1598
Abstract base class for model selection. Takes a parameter tree which specifies parameters for model ...
CMachine * get_machine() const
CModelSelectionParameters * m_model_parameters
Template Dynamic array class that creates an array that can be used like a list or an array...
Definition: DynArray.h:21
class that holds ONE combination of parameters for a learning machine. The structure is organized as ...
#define SG_UNREF(x)
Definition: SGObject.h:45
EEvaluationDirection get_evaluation_direction()
static const float64_t ALMOST_INFTY
Definition: Math.h:1595
int32_t index_t
Definition: DataType.h:25

SHOGUN Machine Learning Toolbox - Documentation