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  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
00009  */
00010 
00011 #ifndef __PARAMETERCOMBINATION_H__
00012 #define __PARAMETERCOMBINATION_H__
00013 
00014 #include <shogun/lib/DynamicObjectArray.h>
00015 
00016 namespace shogun
00017 {
00018 
00019 class CModelSelectionParameters;
00020 class CMachine;
00021 class Parameter;
00022 
00042 class CParameterCombination : public CSGObject
00043 {
00044 
00045 friend class CModelSelectionParameters;
00046 
00047 public:
00049     CParameterCombination();
00050 
00056     void print_tree(int prefix_num=0) const;
00057 
00059     CParameterCombination(Parameter* param);
00060 
00063     virtual ~CParameterCombination();
00064 
00071     void apply_to_modsel_parameter(Parameter* parameter) const;
00072 
00078     void apply_to_machine(CMachine* machine) const;
00079 
00084     void append_child(CParameterCombination* child);
00085 
00090     void merge_with(CParameterCombination* node);
00091 
00098     CParameterCombination* copy_tree() const;
00099 
00112     static CDynamicObjectArray* leaf_sets_multiplication(
00113             const CDynamicObjectArray& sets,
00114             const CParameterCombination* new_root);
00115 
00125     template <typename T>
00126     bool set_parameter(const char* name,
00127             T value, CSGObject* parent, index_t index = -1)
00128     {
00129         bool match = false;
00130 
00131         if (m_param)
00132         {
00133             for (index_t i = 0; i < m_param->get_num_parameters(); ++i)
00134             {
00135                     void* param = m_param->get_parameter(i)->m_parameter;
00136 
00137                     if (m_param->get_parameter(i)->m_datatype.m_ptype
00138                             ==PT_SGOBJECT)
00139                     {
00140                         if (parent == (*((CSGObject**)param)))
00141                             match = true;
00142                     }
00143 
00144             }
00145 
00146         }
00147 
00148         bool result = false;
00149 
00150         for (index_t i = 0; i < m_child_nodes->get_num_elements(); ++i)
00151         {
00152             CParameterCombination* child = (CParameterCombination*)
00153                     m_child_nodes->get_element(i);
00154 
00155             if (!match)
00156                  result |= child->set_parameter(name, value, parent, index);
00157 
00158             else
00159                  result |= child->set_parameter_helper(name, value, index);
00160 
00161             SG_UNREF(child);
00162 
00163         }
00164 
00165         return result;
00166     }
00167 
00175     TParameter* get_parameter(const char* name, CSGObject* parent);
00176 
00181     bool has_children() const
00182     {
00183         return m_child_nodes->get_num_elements()>0;
00184     }
00185 
00193     static DynArray<Parameter*>* parameter_set_multiplication(
00194             const DynArray<Parameter*>& set_1,
00195             const DynArray<Parameter*>& set_2);
00196 
00198     virtual const char* get_name() const
00199     {
00200         return "ParameterCombination";
00201     }
00202 
00203 protected:
00214     static CDynamicObjectArray* non_value_tree_multiplication(
00215                 const CDynamicObjectArray* sets,
00216                 const CParameterCombination* new_root);
00217 
00226     static CDynamicObjectArray* extract_trees_with_name(
00227             const CDynamicObjectArray* sets, const char* desired_name);
00228 
00234     TParameter* get_parameter_helper(const char* name);
00235 
00244     bool set_parameter_helper(const char* name, bool value, index_t index);
00245 
00254     bool set_parameter_helper(const char* name, int32_t value, index_t index);
00255 
00264     bool set_parameter_helper(const char* name, float64_t value, index_t index);
00265 
00266 private:
00267     void init();
00268 
00269 protected:
00270 
00272     Parameter* m_param;
00273 
00275     CDynamicObjectArray* m_child_nodes;
00276 };
00277 }
00278 
00279 #endif /* __PARAMETERCOMBINATION_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation