SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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_ */
int32_t index_t
Definition: common.h:62
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:115
shogun vector
virtual const char * get_name() const
double float64_t
Definition: common.h:50
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:18
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:909
SGVector< T > create_range_array(T min, T max, ERangeType type, T step, T type_base)
#define SG_SERROR(...)
Definition: SGIO.h:179
Matrix::Scalar max(Matrix m)
Definition: Redux.h:68
static float64_t round(float64_t d)
Definition: Math.h:398
void append_child(CModelSelectionParameters *child)
static int32_t pow(bool x, int32_t n)
Definition: Math.h:535

SHOGUN Machine Learning Toolbox - Documentation