SHOGUN  6.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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  {
109  /* possibly delete old range values */
110  delete_values();
111  m_values=values.vector;
112  m_values_length=values.vlen;
113  m_value_type=value_type;
114  }
115 
121  void print_tree(int prefix_num=0);
122 
132 
144 
147  float64_t step=1.0, float64_t type_base=2.0);
148 
150  void* vector, index_t* size, float64_t step=1.0,
151  float64_t type_base=2.0);
152 
154  void* vector, float64_t step=1.0, float64_t type_base=2.0);
155 
157  void build_values(int32_t min, int32_t max, ERangeType type, int32_t step=1,
158  int32_t type_base=2);
159 
160  void build_values_vector(int32_t min, int32_t max, ERangeType type,
161  void* vector, index_t* size, int32_t step=1,
162  int32_t type_base=2);
163 
164  void build_values_sgvector(int32_t min, int32_t max, ERangeType type, void* vector,
165  int32_t step=1, int32_t type_base=2);
166 
168  virtual const char* get_name() const
169  {
170  return "ModelSelectionParameters";
171  }
172 
173 private:
174  void init();
175 
177  void delete_values();
178 
180  void build_values(EMSParamType param_type, void* min, void* max,
181  ERangeType type, void* step, void* type_base);
182 
183 protected:
188  bool has_children() const
189  {
190  return m_child_nodes->get_num_elements()>0;
191  }
192 
193 private:
194  CSGObject* m_sgobject;
195  const char* m_node_name;
196  void* m_values;
197  index_t m_values_length;
198  index_t* m_vector_length;
199  CDynamicObjectArray* m_child_nodes;
200  EMSParamType m_value_type;
201  void* m_vector;
202 };
203 
217 template <class T> SGVector<T> create_range_array(T min, T max,
218  ERangeType type, T step, T type_base)
219 {
220  if (max<min)
221  SG_SERROR("unable build values: max=%f < min=%f\n", max, min)
222 
223  /* create value vector, no ref-counting */
224  index_t num_values=CMath::round((max-min)/step)+1;
225  SGVector<T> result(num_values, false);
226 
227  /* fill array */
228  for (index_t i=0; i<num_values; ++i)
229  {
230  T current=min+i*step;
231 
232  switch (type)
233  {
234  case R_LINEAR:
235  result.vector[i]=current;
236  break;
237  case R_EXP:
238  result.vector[i]=CMath::pow((float64_t)type_base, current);
239  break;
240  case R_LOG:
241  if (current<=0)
242  SG_SERROR("log(x) with x=%f\n", current)
243 
244  /* custom base b: log_b(i*step)=log_2(i*step)/log_2(b) */
245  result.vector[i]=CMath::log2(current)/CMath::log2(type_base);
246  break;
247  default:
248  SG_SERROR("unknown range type!\n")
249  break;
250  }
251  }
252 
253  return result;
254 }
255 
256 }
257 #endif /* __MODELSELECTIONPARAMETERS_H_ */
int32_t index_t
Definition: common.h:72
Class to select parameters and their ranges for model selection. The structure is organized as a tree...
index_t vlen
Definition: SGVector.h:545
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:125
shogun vector
virtual const char * get_name() const
double float64_t
Definition: common.h:60
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:904
SGVector< T > create_range_array(T min, T max, ERangeType type, T step, T type_base)
#define SG_SERROR(...)
Definition: SGIO.h:178
static float64_t round(float64_t d)
Definition: Math.h:393
T max(const Container< T > &a)
void append_child(CModelSelectionParameters *child)
static int32_t pow(bool x, int32_t n)
Definition: Math.h:530

SHOGUN Machine Learning Toolbox - Documentation