SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ParameterCombination.h
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2011-2012 Heiko Strathmann
00008  * Written (W) 2013 Roman Votyakov
00009  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
00010  */
00011 
00012 #ifndef __PARAMETERCOMBINATION_H__
00013 #define __PARAMETERCOMBINATION_H__
00014 
00015 #include <shogun/lib/DynamicObjectArray.h>
00016 #include <shogun/lib/Map.h>
00017 
00018 namespace shogun
00019 {
00020 class CModelSelectionParameters;
00021 class CMachine;
00022 class Parameter;
00023 
00041 class CParameterCombination : public CSGObject
00042 {
00043 friend class CModelSelectionParameters;
00044 
00045 public:
00047     CParameterCombination();
00048 
00053     CParameterCombination(Parameter* param);
00054 
00063     CParameterCombination(CSGObject* obj);
00064 
00068     virtual ~CParameterCombination();
00069 
00075     void print_tree(int prefix_num=0) const;
00076 
00084     void apply_to_modsel_parameter(Parameter* parameter) const;
00085 
00091     void apply_to_machine(CMachine* machine) const;
00092 
00097     void append_child(CParameterCombination* child);
00098 
00103     void merge_with(CParameterCombination* node);
00104 
00111     CParameterCombination* copy_tree() const;
00112 
00125     static CDynamicObjectArray* leaf_sets_multiplication(
00126             const CDynamicObjectArray& sets,
00127             const CParameterCombination* new_root);
00128 
00138     template <typename T>
00139     bool set_parameter(const char* name,
00140             T value, CSGObject* parent, index_t index = -1)
00141     {
00142         bool match = false;
00143 
00144         if (m_param)
00145         {
00146             for (index_t i = 0; i < m_param->get_num_parameters(); ++i)
00147             {
00148                     void* param = m_param->get_parameter(i)->m_parameter;
00149 
00150                     if (m_param->get_parameter(i)->m_datatype.m_ptype
00151                             ==PT_SGOBJECT)
00152                     {
00153                         if (parent == (*((CSGObject**)param)))
00154                             match = true;
00155                     }
00156 
00157             }
00158 
00159         }
00160 
00161         bool result = false;
00162 
00163         for (index_t i = 0; i < m_child_nodes->get_num_elements(); ++i)
00164         {
00165             CParameterCombination* child = (CParameterCombination*)
00166                     m_child_nodes->get_element(i);
00167 
00168             if (!match)
00169                  result |= child->set_parameter(name, value, parent, index);
00170 
00171             else
00172                  result |= child->set_parameter_helper(name, value, index);
00173 
00174             SG_UNREF(child);
00175 
00176         }
00177 
00178         return result;
00179     }
00180 
00188     TParameter* get_parameter(const char* name, CSGObject* parent);
00189 
00194     bool has_children() const
00195     {
00196         return m_child_nodes->get_num_elements()>0;
00197     }
00198 
00206     static DynArray<Parameter*>* parameter_set_multiplication(
00207             const DynArray<Parameter*>& set_1,
00208             const DynArray<Parameter*>& set_2);
00209 
00211     virtual const char* get_name() const
00212     {
00213         return "ParameterCombination";
00214     }
00215 
00220     virtual uint32_t get_parameters_length() { return m_parameters_length; }
00221 
00228     virtual void build_parameter_values_map(
00229             CMap<TParameter*, SGVector<float64_t> >* values_map);
00230 
00235     virtual void build_parameter_parent_map(
00236             CMap<TParameter*, CSGObject*>* parent_map);
00237 
00238 protected:
00249     static CDynamicObjectArray* non_value_tree_multiplication(
00250                 const CDynamicObjectArray* sets,
00251                 const CParameterCombination* new_root);
00252 
00261     static CDynamicObjectArray* extract_trees_with_name(
00262             const CDynamicObjectArray* sets, const char* desired_name);
00263 
00269     TParameter* get_parameter_helper(const char* name);
00270 
00279     bool set_parameter_helper(const char* name, bool value, index_t index);
00280 
00289     bool set_parameter_helper(const char* name, int32_t value, index_t index);
00290 
00299     bool set_parameter_helper(const char* name, float64_t value, index_t index);
00300 
00301 private:
00302     void init();
00303 
00304 protected:
00306     Parameter* m_param;
00307 
00309     CDynamicObjectArray* m_child_nodes;
00310 
00312     uint32_t m_parameters_length;
00313 };
00314 }
00315 #endif /* __PARAMETERCOMBINATION_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation