SHOGUN
v1.1.0
|
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 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 00060 class CModelSelectionParameters: public CSGObject 00061 { 00062 public: 00064 CModelSelectionParameters(); 00065 00070 CModelSelectionParameters(const char* node_name); 00071 00077 CModelSelectionParameters(const char* node_name, CSGObject* sgobject); 00078 00080 ~CModelSelectionParameters(); 00081 00086 void append_child(CModelSelectionParameters* child); 00087 00094 template <class T> 00095 void set_values(SGVector<T> values); 00096 00102 void print_tree(int prefix_num=0); 00103 00111 CDynamicObjectArray<CParameterCombination>* get_combinations(); 00112 00114 void build_values(float64_t min, float64_t max, ERangeType type, 00115 float64_t step=1.0, float64_t type_base=2.0); 00116 00118 void build_values(int32_t min, int32_t max, ERangeType type, int32_t step=1, 00119 int32_t type_base=2); 00120 00122 inline virtual const char* get_name() const 00123 { 00124 return "ModelSelectionParameters"; 00125 } 00126 00127 private: 00128 void init(); 00129 00131 void delete_values(); 00132 00134 void build_values(EMSParamType param_type, void* min, void* max, 00135 ERangeType type, void* step, void* type_base); 00136 00137 protected: 00142 bool has_children() const 00143 { 00144 return m_child_nodes->get_num_elements()>0; 00145 } 00146 00147 private: 00148 CSGObject* m_sgobject; 00149 const char* m_node_name; 00150 SGVector<char> m_values; // dummy void type char 00151 CDynamicObjectArray<CModelSelectionParameters>* m_child_nodes; 00152 EMSParamType m_value_type; 00153 }; 00154 00168 template <class T> SGVector<T> create_range_array(T min, T max, 00169 ERangeType type, T step, T type_base) 00170 { 00171 if (max<min) 00172 SG_SERROR("unable build values: max=%f < min=%f\n", max, min); 00173 00174 /* create value vector */ 00175 index_t num_values=CMath::round(max-min)/step+1; 00176 SGVector<T> result(num_values); 00177 00178 /* fill array */ 00179 for (index_t i=0; i<num_values; ++i) 00180 { 00181 T current=min+i*step; 00182 00183 switch (type) 00184 { 00185 case R_LINEAR: 00186 result.vector[i]=current; 00187 break; 00188 case R_EXP: 00189 result.vector[i]=CMath::pow((float64_t)type_base, current); 00190 break; 00191 case R_LOG: 00192 if (current<=0) 00193 SG_SERROR("log(x) with x=%f\n", current); 00194 00195 /* custom base b: log_b(i*step)=log_2(i*step)/log_2(b) */ 00196 result.vector[i]=CMath::log2(current)/CMath::log2(type_base); 00197 break; 00198 default: 00199 SG_SERROR("unknown range type!\n"); 00200 break; 00201 } 00202 } 00203 00204 return result; 00205 } 00206 00207 } 00208 #endif /* __MODELSELECTIONPARAMETERS_H_ */