SHOGUN  3.2.1
 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/lib/config.h>
15 
16 #include <shogun/base/SGObject.h>
18 #include <shogun/lib/SGVector.h>
19 
20 namespace shogun
21 {
22 
23 class CParameterCombination;
24 
27 {
29 };
30 
33 {
36 
37  /* float64_t */
39 
40  /* int32_t */
42 
44 
46 
48 
50 };
51 
72 {
73 public:
76 
81  CModelSelectionParameters(const char* node_name);
82 
88  CModelSelectionParameters(const char* node_name, CSGObject* sgobject);
89 
92 
98 
106  template <class T>
107  void set_values(const SGVector<T>& values, EMSParamType value_type);
108 
114  void print_tree(int prefix_num=0);
115 
125 
137 
140  float64_t step=1.0, float64_t type_base=2.0);
141 
143  void* vector, index_t* size, float64_t step=1.0,
144  float64_t type_base=2.0);
145 
147  void* vector, float64_t step=1.0, float64_t type_base=2.0);
148 
150  void build_values(int32_t min, int32_t max, ERangeType type, int32_t step=1,
151  int32_t type_base=2);
152 
153  void build_values_vector(int32_t min, int32_t max, ERangeType type,
154  void* vector, index_t* size, int32_t step=1,
155  int32_t type_base=2);
156 
157  void build_values_sgvector(int32_t min, int32_t max, ERangeType type, void* vector,
158  int32_t step=1, int32_t type_base=2);
159 
161  virtual const char* get_name() const
162  {
163  return "ModelSelectionParameters";
164  }
165 
166 private:
167  void init();
168 
170  void delete_values();
171 
173  void build_values(EMSParamType param_type, void* min, void* max,
174  ERangeType type, void* step, void* type_base);
175 
176 protected:
181  bool has_children() const
182  {
183  return m_child_nodes->get_num_elements()>0;
184  }
185 
186 private:
187  CSGObject* m_sgobject;
188  const char* m_node_name;
189  void* m_values;
190  index_t m_values_length;
191  index_t* m_vector_length;
192  CDynamicObjectArray* m_child_nodes;
193  EMSParamType m_value_type;
194  void* m_vector;
195 };
196 
210 template <class T> SGVector<T> create_range_array(T min, T max,
211  ERangeType type, T step, T type_base)
212 {
213  if (max<min)
214  SG_SERROR("unable build values: max=%f < min=%f\n", max, min)
215 
216  /* create value vector, no ref-counting */
217  index_t num_values=CMath::round((max-min)/step)+1;
218  SGVector<T> result(num_values, false);
219 
220  /* fill array */
221  for (index_t i=0; i<num_values; ++i)
222  {
223  T current=min+i*step;
224 
225  switch (type)
226  {
227  case R_LINEAR:
228  result.vector[i]=current;
229  break;
230  case R_EXP:
231  result.vector[i]=CMath::pow((float64_t)type_base, current);
232  break;
233  case R_LOG:
234  if (current<=0)
235  SG_SERROR("log(x) with x=%f\n", current)
236 
237  /* custom base b: log_b(i*step)=log_2(i*step)/log_2(b) */
238  result.vector[i]=CMath::log2(current)/CMath::log2(type_base);
239  break;
240  default:
241  SG_SERROR("unknown range type!\n")
242  break;
243  }
244  }
245 
246  return result;
247 }
248 
249 }
250 #endif /* __MODELSELECTIONPARAMETERS_H_ */

SHOGUN Machine Learning Toolbox - Documentation