Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
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
00035 MSPT_FLOAT64,
00036
00037
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 void set_values(SGVector<void> values);
00095
00101 void print_tree(int prefix_num=0);
00102
00110 CDynamicObjectArray<CParameterCombination>* get_combinations();
00111
00113 void build_values(float64_t min, float64_t max, ERangeType type,
00114 float64_t step=1.0, float64_t type_base=2.0);
00115
00117 void build_values(int32_t min, int32_t max, ERangeType type, int32_t step=1,
00118 int32_t type_base=2);
00119
00121 inline virtual const char* get_name() const
00122 {
00123 return "ModelSelectionParameters";
00124 }
00125
00126 private:
00127 void init();
00128
00130 void delete_values();
00131
00133 void build_values(EMSParamType param_type, void* min, void* max,
00134 ERangeType type, void* step, void* type_base);
00135
00136 protected:
00141 bool has_children() const
00142 {
00143 return m_child_nodes->get_num_elements()>0;
00144 }
00145
00146 private:
00147 CSGObject* m_sgobject;
00148 const char* m_node_name;
00149 SGVector<void> m_values;
00150 CDynamicObjectArray<CModelSelectionParameters>* m_child_nodes;
00151 EMSParamType m_value_type;
00152 };
00153
00167 template <class T> SGVector<T> create_range_array(T min, T max,
00168 ERangeType type, T step, T type_base)
00169 {
00170 if (max<min)
00171 SG_SERROR("unable build values: max=%f < min=%f\n", max, min);
00172
00173
00174 index_t num_values=CMath::round(max-min)/step+1;
00175 SGVector<T> result(num_values);
00176
00177
00178 for (index_t i=0; i<num_values; ++i)
00179 {
00180 T current=min+i*step;
00181
00182 switch (type)
00183 {
00184 case R_LINEAR:
00185 result.vector[i]=current;
00186 break;
00187 case R_EXP:
00188 result.vector[i]=CMath::pow((float64_t)type_base, current);
00189 break;
00190 case R_LOG:
00191 if (current<=0)
00192 SG_SERROR("log(x) with x=%f\n", current);
00193
00194
00195 result.vector[i]=CMath::log2(current)/CMath::log2(type_base);
00196 break;
00197 default:
00198 SG_SERROR("unknown range type!\n");
00199 break;
00200 }
00201 }
00202
00203 return result;
00204 }
00205
00206 }
00207 #endif