SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ModelSelectionParameters.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 __MODELSELECTIONPARAMETERS_H_
00012 #define __MODELSELECTIONPARAMETERS_H_
00013 
00014 #include <shogun/base/SGObject.h>
00015 #include <shogun/lib/DynamicObjectArray.h>
00016 
00017 namespace shogun
00018 {
00019 
00020 class CParameterCombination;
00021 
00023 enum ERangeType
00024 {
00025     R_LINEAR, R_EXP, R_LOG
00026 };
00027 
00029 enum EMSParamType
00030 {
00032     MSPT_NONE=0,
00033 
00034     /* float64_t */
00035     MSPT_FLOAT64,
00036 
00037     /* int32_t */
00038     MSPT_INT32,
00039 
00040     MSPT_FLOAT64_VECTOR,
00041 
00042     MSPT_INT32_VECTOR,
00043 
00044     MSPT_FLOAT64_SGVECTOR,
00045 
00046     MSPT_INT32_SGVECTOR,
00047 };
00048 
00068 class CModelSelectionParameters: public CSGObject
00069 {
00070 public:
00072     CModelSelectionParameters();
00073 
00078     CModelSelectionParameters(const char* node_name);
00079 
00085     CModelSelectionParameters(const char* node_name, CSGObject* sgobject);
00086 
00088     ~CModelSelectionParameters();
00089 
00094     void append_child(CModelSelectionParameters* child);
00095 
00103     template <class T>
00104     void set_values(const SGVector<T>& values, EMSParamType value_type);
00105 
00111     void print_tree(int prefix_num=0);
00112 
00121     CDynamicObjectArray* get_combinations(index_t prefix_num=1);
00122 
00133     CParameterCombination* get_single_combination(bool rand = true);
00134 
00136     void build_values(float64_t min, float64_t max, ERangeType type,
00137             float64_t step=1.0, float64_t type_base=2.0);
00138 
00139     void build_values_vector(float64_t min, float64_t max, ERangeType type,
00140             void* vector, index_t* size, float64_t step=1.0,
00141             float64_t type_base=2.0);
00142 
00143     void build_values_sgvector(float64_t min, float64_t max, ERangeType type,
00144             void* vector, float64_t step=1.0, float64_t type_base=2.0);
00145 
00147     void build_values(int32_t min, int32_t max, ERangeType type, int32_t step=1,
00148             int32_t type_base=2);
00149 
00150     void build_values_vector(int32_t min, int32_t max, ERangeType type,
00151             void* vector, index_t* size, int32_t step=1,
00152             int32_t type_base=2);
00153 
00154     void build_values_sgvector(int32_t min, int32_t max, ERangeType type, void* vector,
00155             int32_t step=1, int32_t type_base=2);
00156 
00158     virtual const char* get_name() const
00159     {
00160         return "ModelSelectionParameters";
00161     }
00162 
00163 private:
00164     void init();
00165 
00167     void delete_values();
00168 
00170     void build_values(EMSParamType param_type, void* min, void* max,
00171             ERangeType type, void* step, void* type_base);
00172 
00173 protected:
00178     bool has_children() const
00179     {
00180         return m_child_nodes->get_num_elements()>0;
00181     }
00182 
00183 private:
00184     CSGObject* m_sgobject;
00185     const char* m_node_name;
00186     void* m_values;
00187     index_t m_values_length;
00188     index_t* m_vector_length;
00189     CDynamicObjectArray* m_child_nodes;
00190     EMSParamType m_value_type;
00191     void*   m_vector;
00192 };
00193 
00207 template <class T> SGVector<T> create_range_array(T min, T max,
00208         ERangeType type, T step, T type_base)
00209 {
00210     if (max<min)
00211         SG_SERROR("unable build values: max=%f < min=%f\n", max, min)
00212 
00213     /* create value vector, no ref-counting */
00214     index_t num_values=CMath::round((max-min)/step)+1;
00215     SGVector<T> result(num_values, false);
00216 
00217     /* fill array */
00218     for (index_t i=0; i<num_values; ++i)
00219     {
00220         T current=min+i*step;
00221 
00222         switch (type)
00223         {
00224         case R_LINEAR:
00225             result.vector[i]=current;
00226             break;
00227         case R_EXP:
00228             result.vector[i]=CMath::pow((float64_t)type_base, current);
00229             break;
00230         case R_LOG:
00231             if (current<=0)
00232                 SG_SERROR("log(x) with x=%f\n", current)
00233 
00234             /* custom base b: log_b(i*step)=log_2(i*step)/log_2(b) */
00235             result.vector[i]=CMath::log2(current)/CMath::log2(type_base);
00236             break;
00237         default:
00238             SG_SERROR("unknown range type!\n")
00239             break;
00240         }
00241     }
00242 
00243     return result;
00244 }
00245 
00246 }
00247 #endif /* __MODELSELECTIONPARAMETERS_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation