SHOGUN  v3.2.0
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  virtual const char* get_name() const
159  {
160  return "ModelSelectionParameters";
161  }
162 
163 private:
164  void init();
165 
167  void delete_values();
168 
170  void build_values(EMSParamType param_type, void* min, void* max,
171  ERangeType type, void* step, void* type_base);
172 
173 protected:
178  bool has_children() const
179  {
180  return m_child_nodes->get_num_elements()>0;
181  }
182 
183 private:
184  CSGObject* m_sgobject;
185  const char* m_node_name;
186  void* m_values;
187  index_t m_values_length;
188  index_t* m_vector_length;
189  CDynamicObjectArray* m_child_nodes;
190  EMSParamType m_value_type;
191  void* m_vector;
192 };
193 
207 template <class T> SGVector<T> create_range_array(T min, T max,
208  ERangeType type, T step, T type_base)
209 {
210  if (max<min)
211  SG_SERROR("unable build values: max=%f < min=%f\n", max, min)
212 
213  /* create value vector, no ref-counting */
214  index_t num_values=CMath::round((max-min)/step)+1;
215  SGVector<T> result(num_values, false);
216 
217  /* fill array */
218  for (index_t i=0; i<num_values; ++i)
219  {
220  T current=min+i*step;
221 
222  switch (type)
223  {
224  case R_LINEAR:
225  result.vector[i]=current;
226  break;
227  case R_EXP:
228  result.vector[i]=CMath::pow((float64_t)type_base, current);
229  break;
230  case R_LOG:
231  if (current<=0)
232  SG_SERROR("log(x) with x=%f\n", current)
233 
234  /* custom base b: log_b(i*step)=log_2(i*step)/log_2(b) */
235  result.vector[i]=CMath::log2(current)/CMath::log2(type_base);
236  break;
237  default:
238  SG_SERROR("unknown range type!\n")
239  break;
240  }
241  }
242 
243  return result;
244 }
245 
246 }
247 #endif /* __MODELSELECTIONPARAMETERS_H_ */
int32_t index_t
Definition: common.h:60
Class to select parameters and their ranges for model selection. The structure is organized as a tree...
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:102
virtual const char * get_name() const
double float64_t
Definition: common.h:48
void set_values(const SGVector< T > &values, EMSParamType value_type)
void build_values_vector(float64_t min, float64_t max, ERangeType type, void *vector, index_t *size, float64_t step=1.0, float64_t type_base=2.0)
void build_values(float64_t min, float64_t max, ERangeType type, float64_t step=1.0, float64_t type_base=2.0)
Dynamic array class for CSGObject pointers that creates an array that can be used like a list or an a...
Class that holds ONE combination of parameters for a learning machine. The structure is organized as ...
CParameterCombination * get_single_combination(bool rand=true)
void build_values_sgvector(float64_t min, float64_t max, ERangeType type, void *vector, float64_t step=1.0, float64_t type_base=2.0)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
CDynamicObjectArray * get_combinations(index_t prefix_num=1)
static float64_t log2(float64_t v)
log10(x), x being a complex128_t
Definition: Math.h:411
SGVector< T > create_range_array(T min, T max, ERangeType type, T step, T type_base)
#define SG_SERROR(...)
Definition: SGIO.h:181
static float64_t round(float64_t d)
Definition: Math.h:203
void append_child(CModelSelectionParameters *child)
static int32_t pow(bool x, int32_t n)
Definition: Math.h:304

SHOGUN Machine Learning Toolbox - Documentation