SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ParameterCombination.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  * Written (W) 2013 Roman Votyakov
9  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
10  */
11 
12 #ifndef __PARAMETERCOMBINATION_H__
13 #define __PARAMETERCOMBINATION_H__
14 
15 #include <shogun/lib/config.h>
16 
18 #include <shogun/lib/Map.h>
19 
20 namespace shogun
21 {
22 class CModelSelectionParameters;
23 class CMachine;
24 class Parameter;
25 
44 {
46 
47 public:
50 
56 
66 
70  virtual ~CParameterCombination();
71 
77  void print_tree(int prefix_num=0) const;
78 
86  void apply_to_modsel_parameter(Parameter* parameter) const;
87 
93  void apply_to_machine(CMachine* machine) const;
94 
100 
106 
114 
128  const CDynamicObjectArray& sets,
129  const CParameterCombination* new_root);
130 
140  template <typename T>
141  bool set_parameter(const char* name,
142  T value, CSGObject* parent, index_t index = -1)
143  {
144  bool match = false;
145 
146  if (m_param)
147  {
148  for (index_t i = 0; i < m_param->get_num_parameters(); ++i)
149  {
150  void* param = m_param->get_parameter(i)->m_parameter;
151 
153  ==PT_SGOBJECT)
154  {
155  if (parent == (*((CSGObject**)param)))
156  match = true;
157  }
158 
159  }
160 
161  }
162 
163  bool result = false;
164 
165  for (index_t i = 0; i < m_child_nodes->get_num_elements(); ++i)
166  {
169 
170  if (!match)
171  result |= child->set_parameter(name, value, parent, index);
172 
173  else
174  result |= child->set_parameter_helper(name, value, index);
175 
176  SG_UNREF(child);
177 
178  }
179 
180  return result;
181  }
182 
190  TParameter* get_parameter(const char* name, CSGObject* parent);
191 
196  bool has_children() const
197  {
198  return m_child_nodes->get_num_elements()>0;
199  }
200 
209  const DynArray<Parameter*>& set_1,
210  const DynArray<Parameter*>& set_2);
211 
213  virtual const char* get_name() const
214  {
215  return "ParameterCombination";
216  }
217 
223  CSGObject* param_combination)
224  {
225  if (param_combination)
226  {
227  CParameterCombination* casted = dynamic_cast<CParameterCombination*>(param_combination);
228  REQUIRE(casted, "Error, provided object of class \"%s\" is not a subclass of"
229  " CParameterCombination!\n",
230  param_combination->get_name());
231  return casted;
232  }
233  else
234  return NULL;
235  }
236 
241  virtual uint32_t get_parameters_length() { return m_parameters_length; }
242 
249  virtual void build_parameter_values_map(
250  CMap<TParameter*, SGVector<float64_t> >* values_map);
251 
256  virtual void build_parameter_parent_map(
257  CMap<TParameter*, CSGObject*>* parent_map);
258 
259 protected:
271  const CDynamicObjectArray* sets,
272  const CParameterCombination* new_root);
273 
283  const CDynamicObjectArray* sets, const char* desired_name);
284 
290  TParameter* get_parameter_helper(const char* name);
291 
300  bool set_parameter_helper(const char* name, bool value, index_t index);
301 
310  bool set_parameter_helper(const char* name, int32_t value, index_t index);
311 
320  bool set_parameter_helper(const char* name, float64_t value, index_t index);
321 
322 private:
323  void init();
324 
325 protected:
328 
331 
334 };
335 }
336 #endif /* __PARAMETERCOMBINATION_H__ */
virtual const char * get_name() const =0
int32_t index_t
Definition: common.h:62
bool set_parameter(const char *name, T value, CSGObject *parent, index_t index=-1)
virtual int32_t get_num_parameters()
void apply_to_modsel_parameter(Parameter *parameter) const
TParameter * get_parameter(const char *name, CSGObject *parent)
TParameter * get_parameter(int32_t idx)
virtual const char * get_name() const
parameter struct
#define REQUIRE(x,...)
Definition: SGIO.h:206
void print_tree(int prefix_num=0) const
CParameterCombination * copy_tree() const
A generic learning machine interface.
Definition: Machine.h:143
Class to select parameters and their ranges for model selection. The structure is organized as a tree...
static CParameterCombination * obtain_from_generic(CSGObject *param_combination)
TSGDataType m_datatype
Parameter class.
CDynamicObjectArray * m_child_nodes
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
void merge_with(CParameterCombination *node)
Template Dynamic array class that creates an array that can be used like a list or an array...
Definition: DynArray.h:32
static CDynamicObjectArray * extract_trees_with_name(const CDynamicObjectArray *sets, const char *desired_name)
double float64_t
Definition: common.h:50
void append_child(CParameterCombination *child)
bool set_parameter_helper(const char *name, bool value, index_t index)
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 ...
virtual void build_parameter_parent_map(CMap< TParameter *, CSGObject * > *parent_map)
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
TParameter * get_parameter_helper(const char *name)
CSGObject * get_element(int32_t index) const
virtual uint32_t get_parameters_length()
virtual void build_parameter_values_map(CMap< TParameter *, SGVector< float64_t > > *values_map)
EPrimitiveType m_ptype
Definition: DataType.h:75
void apply_to_machine(CMachine *machine) const
static CDynamicObjectArray * non_value_tree_multiplication(const CDynamicObjectArray *sets, const CParameterCombination *new_root)
static DynArray< Parameter * > * parameter_set_multiplication(const DynArray< Parameter * > &set_1, const DynArray< Parameter * > &set_2)
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
Definition: SGObject.h:39
static CDynamicObjectArray * leaf_sets_multiplication(const CDynamicObjectArray &sets, const CParameterCombination *new_root)

SHOGUN Machine Learning Toolbox - Documentation