SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ModelSelectionParameters.h
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 
11 #ifndef __MODELSELECTIONPARAMETERS_H_
12 #define __MODELSELECTIONPARAMETERS_H_
13 
14 #include <shogun/base/SGObject.h>
16 
17 namespace shogun
18 {
19 
20 class CParameterCombination;
21 
24 {
26 };
27 
30 {
33 
34  /* float64_t */
36 
37  /* int32_t */
39 };
40 
61 {
62 public:
65 
70  CModelSelectionParameters(const char* node_name);
71 
77  CModelSelectionParameters(const char* node_name, CSGObject* sgobject);
78 
81 
87 
94  template <class T>
95  void set_values(SGVector<T> values);
96 
102  void print_tree(int prefix_num=0);
103 
112 
114  void build_values(float64_t min, float64_t max, ERangeType type,
115  float64_t step=1.0, float64_t type_base=2.0);
116 
118  void build_values(int32_t min, int32_t max, ERangeType type, int32_t step=1,
119  int32_t type_base=2);
120 
122  inline virtual const char* get_name() const
123  {
124  return "ModelSelectionParameters";
125  }
126 
127 private:
128  void init();
129 
131  void delete_values();
132 
134  void build_values(EMSParamType param_type, void* min, void* max,
135  ERangeType type, void* step, void* type_base);
136 
137 protected:
142  bool has_children() const
143  {
144  return m_child_nodes->get_num_elements()>0;
145  }
146 
147 private:
148  CSGObject* m_sgobject;
149  const char* m_node_name;
150  SGVector<char> m_values; // dummy void type char
152  EMSParamType m_value_type;
153 };
154 
168 template <class T> SGVector<T> create_range_array(T min, T max,
169  ERangeType type, T step, T type_base)
170 {
171  if (max<min)
172  SG_SERROR("unable build values: max=%f < min=%f\n", max, min);
173 
174  /* create value vector */
175  index_t num_values=CMath::round(max-min)/step+1;
176  SGVector<T> result(num_values);
177 
178  /* fill array */
179  for (index_t i=0; i<num_values; ++i)
180  {
181  T current=min+i*step;
182 
183  switch (type)
184  {
185  case R_LINEAR:
186  result.vector[i]=current;
187  break;
188  case R_EXP:
189  result.vector[i]=CMath::pow((float64_t)type_base, current);
190  break;
191  case R_LOG:
192  if (current<=0)
193  SG_SERROR("log(x) with x=%f\n", current);
194 
195  /* custom base b: log_b(i*step)=log_2(i*step)/log_2(b) */
196  result.vector[i]=CMath::log2(current)/CMath::log2(type_base);
197  break;
198  default:
199  SG_SERROR("unknown range type!\n");
200  break;
201  }
202  }
203 
204  return result;
205 }
206 
207 }
208 #endif /* __MODELSELECTIONPARAMETERS_H_ */

SHOGUN Machine Learning Toolbox - Documentation