SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-2012 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 
41 
43 
45 
47 };
48 
69 {
70 public:
73 
78  CModelSelectionParameters(const char* node_name);
79 
85  CModelSelectionParameters(const char* node_name, CSGObject* sgobject);
86 
89 
95 
103  template <class T>
104  void set_values(const SGVector<T>& values, EMSParamType value_type);
105 
111  void print_tree(int prefix_num=0);
112 
122 
134 
136  void build_values(float64_t min, float64_t max, ERangeType type,
137  float64_t step=1.0, float64_t type_base=2.0);
138 
140  void* vector, index_t* size, float64_t step=1.0,
141  float64_t type_base=2.0);
142 
144  void* vector, float64_t step=1.0, float64_t type_base=2.0);
145 
147  void build_values(int32_t min, int32_t max, ERangeType type, int32_t step=1,
148  int32_t type_base=2);
149 
150  void build_values_vector(int32_t min, int32_t max, ERangeType type,
151  void* vector, index_t* size, int32_t step=1,
152  int32_t type_base=2);
153 
154  void build_values_sgvector(int32_t min, int32_t max, ERangeType type, void* vector,
155  int32_t step=1, int32_t type_base=2);
156 
158  inline virtual const char* get_name() const
159  {
160  return "ModelSelectionParameters";
161  }
162 
165  const char* prefix="", int32_t param_version=VERSION_PARAMETER)
166  {
167  SG_ERROR("Serialization is not allowed for %s!\n", get_name());
168  return false;
169  }
170 
173  const char* prefix="", int32_t param_version=VERSION_PARAMETER)
174  {
175  SG_ERROR("Serialization is not allowed for %s!\n", get_name());
176  return false;
177  }
178 
179 private:
180  void init();
181 
183  void delete_values();
184 
186  void build_values(EMSParamType param_type, void* min, void* max,
187  ERangeType type, void* step, void* type_base);
188 
189 protected:
194  bool has_children() const
195  {
196  return m_child_nodes->get_num_elements()>0;
197  }
198 
199 private:
200  CSGObject* m_sgobject;
201  const char* m_node_name;
202  void* m_values;
203  index_t m_values_length;
204  index_t* m_vector_length;
205  CDynamicObjectArray* m_child_nodes;
206  EMSParamType m_value_type;
207  void* m_vector;
208 };
209 
223 template <class T> SGVector<T> create_range_array(T min, T max,
224  ERangeType type, T step, T type_base)
225 {
226  if (max<min)
227  SG_SERROR("unable build values: max=%f < min=%f\n", max, min);
228 
229  /* create value vector, no ref-counting */
230  index_t num_values=CMath::round((max-min)/step)+1;
231  SGVector<T> result(num_values, false);
232 
233  /* fill array */
234  for (index_t i=0; i<num_values; ++i)
235  {
236  T current=min+i*step;
237 
238  switch (type)
239  {
240  case R_LINEAR:
241  result.vector[i]=current;
242  break;
243  case R_EXP:
244  result.vector[i]=CMath::pow((float64_t)type_base, current);
245  break;
246  case R_LOG:
247  if (current<=0)
248  SG_SERROR("log(x) with x=%f\n", current);
249 
250  /* custom base b: log_b(i*step)=log_2(i*step)/log_2(b) */
251  result.vector[i]=CMath::log2(current)/CMath::log2(type_base);
252  break;
253  default:
254  SG_SERROR("unknown range type!\n");
255  break;
256  }
257  }
258 
259  return result;
260 }
261 
262 }
263 #endif /* __MODELSELECTIONPARAMETERS_H_ */

SHOGUN Machine Learning Toolbox - Documentation