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 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
00164 virtual bool save_serializable(CSerializableFile* file,
00165 const char* prefix="", int32_t param_version=VERSION_PARAMETER)
00166 {
00167 SG_ERROR("Serialization is not allowed for %s!\n", get_name());
00168 return false;
00169 }
00170
00172 virtual bool load_serializable(CSerializableFile* file,
00173 const char* prefix="", int32_t param_version=VERSION_PARAMETER)
00174 {
00175 SG_ERROR("Serialization is not allowed for %s!\n", get_name());
00176 return false;
00177 }
00178
00179 private:
00180 void init();
00181
00183 void delete_values();
00184
00186 void build_values(EMSParamType param_type, void* min, void* max,
00187 ERangeType type, void* step, void* type_base);
00188
00189 protected:
00194 bool has_children() const
00195 {
00196 return m_child_nodes->get_num_elements()>0;
00197 }
00198
00199 private:
00200 CSGObject* m_sgobject;
00201 const char* m_node_name;
00202 void* m_values;
00203 index_t m_values_length;
00204 index_t* m_vector_length;
00205 CDynamicObjectArray* m_child_nodes;
00206 EMSParamType m_value_type;
00207 void* m_vector;
00208 };
00209
00223 template <class T> SGVector<T> create_range_array(T min, T max,
00224 ERangeType type, T step, T type_base)
00225 {
00226 if (max<min)
00227 SG_SERROR("unable build values: max=%f < min=%f\n", max, min);
00228
00229
00230 index_t num_values=CMath::round((max-min)/step)+1;
00231 SGVector<T> result(num_values, false);
00232
00233
00234 for (index_t i=0; i<num_values; ++i)
00235 {
00236 T current=min+i*step;
00237
00238 switch (type)
00239 {
00240 case R_LINEAR:
00241 result.vector[i]=current;
00242 break;
00243 case R_EXP:
00244 result.vector[i]=CMath::pow((float64_t)type_base, current);
00245 break;
00246 case R_LOG:
00247 if (current<=0)
00248 SG_SERROR("log(x) with x=%f\n", current);
00249
00250
00251 result.vector[i]=CMath::log2(current)/CMath::log2(type_base);
00252 break;
00253 default:
00254 SG_SERROR("unknown range type!\n");
00255 break;
00256 }
00257 }
00258
00259 return result;
00260 }
00261
00262 }
00263 #endif