SHOGUN  v3.2.0
ParameterCombination.h
浏览该文件的文档.
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 
16 #include <shogun/lib/Map.h>
17 
18 namespace shogun
19 {
20 class CModelSelectionParameters;
21 class CMachine;
22 class Parameter;
23 
42 {
44 
45 public:
48 
54 
64 
68  virtual ~CParameterCombination();
69 
75  void print_tree(int prefix_num=0) const;
76 
84  void apply_to_modsel_parameter(Parameter* parameter) const;
85 
91  void apply_to_machine(CMachine* machine) const;
92 
98 
104 
112 
126  const CDynamicObjectArray& sets,
127  const CParameterCombination* new_root);
128 
138  template <typename T>
139  bool set_parameter(const char* name,
140  T value, CSGObject* parent, index_t index = -1)
141  {
142  bool match = false;
143 
144  if (m_param)
145  {
146  for (index_t i = 0; i < m_param->get_num_parameters(); ++i)
147  {
148  void* param = m_param->get_parameter(i)->m_parameter;
149 
151  ==PT_SGOBJECT)
152  {
153  if (parent == (*((CSGObject**)param)))
154  match = true;
155  }
156 
157  }
158 
159  }
160 
161  bool result = false;
162 
163  for (index_t i = 0; i < m_child_nodes->get_num_elements(); ++i)
164  {
167 
168  if (!match)
169  result |= child->set_parameter(name, value, parent, index);
170 
171  else
172  result |= child->set_parameter_helper(name, value, index);
173 
174  SG_UNREF(child);
175 
176  }
177 
178  return result;
179  }
180 
188  TParameter* get_parameter(const char* name, CSGObject* parent);
189 
194  bool has_children() const
195  {
196  return m_child_nodes->get_num_elements()>0;
197  }
198 
207  const DynArray<Parameter*>& set_1,
208  const DynArray<Parameter*>& set_2);
209 
211  virtual const char* get_name() const
212  {
213  return "ParameterCombination";
214  }
215 
220  virtual uint32_t get_parameters_length() { return m_parameters_length; }
221 
228  virtual void build_parameter_values_map(
229  CMap<TParameter*, SGVector<float64_t> >* values_map);
230 
235  virtual void build_parameter_parent_map(
236  CMap<TParameter*, CSGObject*>* parent_map);
237 
238 protected:
250  const CDynamicObjectArray* sets,
251  const CParameterCombination* new_root);
252 
262  const CDynamicObjectArray* sets, const char* desired_name);
263 
269  TParameter* get_parameter_helper(const char* name);
270 
279  bool set_parameter_helper(const char* name, bool value, index_t index);
280 
289  bool set_parameter_helper(const char* name, int32_t value, index_t index);
290 
299  bool set_parameter_helper(const char* name, float64_t value, index_t index);
300 
301 private:
302  void init();
303 
304 protected:
307 
310 
313 };
314 }
315 #endif /* __PARAMETERCOMBINATION_H__ */
int32_t index_t
Definition: common.h:60
bool set_parameter(const char *name, T value, CSGObject *parent, index_t index=-1)
virtual int32_t get_num_parameters()
Definition: Parameter.h:244
void apply_to_modsel_parameter(Parameter *parameter) const
TParameter * get_parameter(const char *name, CSGObject *parent)
#define SG_UNREF(x)
Definition: SGRefObject.h:35
TParameter * get_parameter(int32_t idx)
Definition: Parameter.h:277
virtual const char * get_name() const
parameter struct
Definition: Parameter.h:26
void print_tree(int prefix_num=0) const
CParameterCombination * copy_tree() const
A generic learning machine interface.
Definition: Machine.h:138
Class to select parameters and their ranges for model selection. The structure is organized as a tree...
TSGDataType m_datatype
Definition: Parameter.h:156
Parameter class.
Definition: Parameter.h:216
CDynamicObjectArray * m_child_nodes
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:102
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:30
static CDynamicObjectArray * extract_trees_with_name(const CDynamicObjectArray *sets, const char *desired_name)
double float64_t
Definition: common.h:48
void append_child(CParameterCombination *child)
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
Definition: SGObject.h:40
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)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
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:74
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)
static CDynamicObjectArray * leaf_sets_multiplication(const CDynamicObjectArray &sets, const CParameterCombination *new_root)

SHOGUN Machine Learning Toolbox - Documentation