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) 2010 Soeren Sonnenburg 00008 * Copyright (C) 2010 Berlin Institute of Technology 00009 */ 00010 #ifndef __PARAMETER_H__ 00011 #define __PARAMETER_H__ 00012 00013 #include <shogun/lib/common.h> 00014 #include <shogun/io/SGIO.h> 00015 #include <shogun/lib/DataType.h> 00016 #include <shogun/io/SerializableFile.h> 00017 #include <shogun/base/DynArray.h> 00018 00019 namespace shogun 00020 { 00022 struct TParameter 00023 { 00030 explicit TParameter(const TSGDataType* datatype, void* parameter, 00031 const char* name, const char* description); 00032 00034 ~TParameter(); 00035 00039 void print(const char* prefix); 00040 00045 bool save(CSerializableFile* file, const char* prefix=""); 00046 00051 bool load(CSerializableFile* file, const char* prefix=""); 00052 00054 TSGDataType m_datatype; 00056 void* m_parameter; 00058 char* m_name; 00060 char* m_description; 00061 00062 private: 00063 char* new_prefix(const char* s1, const char* s2); 00064 void delete_cont(); 00065 void new_cont(index_t new_len_y, index_t new_len_x); 00066 bool new_sgserial(CSGObject** param, EPrimitiveType generic, 00067 const char* sgserializable_name, 00068 const char* prefix); 00069 bool save_ptype(CSerializableFile* file, const void* param, 00070 const char* prefix); 00071 bool load_ptype(CSerializableFile* file, void* param, 00072 const char* prefix); 00073 bool save_stype(CSerializableFile* file, const void* param, 00074 const char* prefix); 00075 bool load_stype(CSerializableFile* file, void* param, 00076 const char* prefix); 00077 }; 00078 00084 class Parameter 00085 { 00086 public: 00088 explicit Parameter(); 00090 virtual ~Parameter(); 00091 00095 virtual void print(const char* prefix=""); 00096 00101 virtual bool save(CSerializableFile* file, const char* prefix=""); 00102 00107 virtual bool load(CSerializableFile* file, const char* prefix=""); 00108 00112 inline virtual int32_t get_num_parameters() 00113 { 00114 return m_params.get_num_elements(); 00115 } 00116 00125 void set_from_parameters(Parameter* params); 00126 00132 void add_parameters(Parameter* params); 00133 00138 bool contains_parameter(const char* name); 00139 00145 inline TParameter* get_parameter(int32_t idx) 00146 { 00147 return m_params.get_element(idx); 00148 } 00149 00150 /* ************************************************************ */ 00151 /* Scalar wrappers */ 00152 00158 void add(bool* param, const char* name, 00159 const char* description=""); 00165 void add(char* param, const char* name, 00166 const char* description=""); 00172 void add(int8_t* param, const char* name, 00173 const char* description=""); 00179 void add(uint8_t* param, const char* name, 00180 const char* description=""); 00186 void add(int16_t* param, const char* name, 00187 const char* description=""); 00193 void add(uint16_t* param, const char* name, 00194 const char* description=""); 00200 void add(int32_t* param, const char* name, 00201 const char* description=""); 00207 void add(uint32_t* param, const char* name, 00208 const char* description=""); 00214 void add(int64_t* param, const char* name, 00215 const char* description=""); 00221 void add(uint64_t* param, const char* name, 00222 const char* description=""); 00228 void add(float32_t* param, const char* name, 00229 const char* description=""); 00235 void add(float64_t* param, const char* name, 00236 const char* description=""); 00242 void add(floatmax_t* param, const char* name, 00243 const char* description=""); 00249 void add(CSGObject** param, 00250 const char* name, const char* description=""); 00256 void add(SGString<bool>* param, const char* name, 00257 const char* description=""); 00263 void add(SGString<char>* param, const char* name, 00264 const char* description=""); 00270 void add(SGString<int8_t>* param, const char* name, 00271 const char* description=""); 00277 void add(SGString<uint8_t>* param, const char* name, 00278 const char* description=""); 00284 void add(SGString<int16_t>* param, const char* name, 00285 const char* description=""); 00291 void add(SGString<uint16_t>* param, const char* name, 00292 const char* description=""); 00298 void add(SGString<int32_t>* param, const char* name, 00299 const char* description=""); 00305 void add(SGString<uint32_t>* param, const char* name, 00306 const char* description=""); 00312 void add(SGString<int64_t>* param, const char* name, 00313 const char* description=""); 00319 void add(SGString<uint64_t>* param, const char* name, 00320 const char* description=""); 00326 void add(SGString<float32_t>* param, const char* name, 00327 const char* description=""); 00333 void add(SGString<float64_t>* param, const char* name, 00334 const char* description=""); 00340 void add(SGString<floatmax_t>* param, const char* name, 00341 const char* description=""); 00347 void add(SGSparseVector<bool>* param, const char* name, 00348 const char* description=""); 00354 void add(SGSparseVector<char>* param, const char* name, 00355 const char* description=""); 00361 void add(SGSparseVector<int8_t>* param, const char* name, 00362 const char* description=""); 00368 void add(SGSparseVector<uint8_t>* param, const char* name, 00369 const char* description=""); 00375 void add(SGSparseVector<int16_t>* param, const char* name, 00376 const char* description=""); 00382 void add(SGSparseVector<uint16_t>* param, const char* name, 00383 const char* description=""); 00389 void add(SGSparseVector<int32_t>* param, const char* name, 00390 const char* description=""); 00396 void add(SGSparseVector<uint32_t>* param, const char* name, 00397 const char* description=""); 00403 void add(SGSparseVector<int64_t>* param, const char* name, 00404 const char* description=""); 00410 void add(SGSparseVector<uint64_t>* param, const char* name, 00411 const char* description=""); 00417 void add(SGSparseVector<float32_t>* param, const char* name, 00418 const char* description=""); 00424 void add(SGSparseVector<float64_t>* param, const char* name, 00425 const char* description=""); 00431 void add(SGSparseVector<floatmax_t>* param, const char* name, 00432 const char* description=""); 00433 00434 /* ************************************************************ */ 00435 /* Vector wrappers */ 00436 00443 void add_vector(bool** param, index_t* length, 00444 const char* name, const char* description=""); 00451 void add_vector(char** param, index_t* length, 00452 const char* name, const char* description=""); 00459 void add_vector(int8_t** param, index_t* length, 00460 const char* name, const char* description=""); 00467 void add_vector(uint8_t** param, index_t* length, 00468 const char* name, const char* description=""); 00475 void add_vector(int16_t** param, index_t* length, 00476 const char* name, const char* description=""); 00483 void add_vector(uint16_t** param, index_t* length, 00484 const char* name, const char* description=""); 00491 void add_vector(int32_t** param, index_t* length, 00492 const char* name, const char* description=""); 00499 void add_vector(uint32_t** param, index_t* length, 00500 const char* name, const char* description=""); 00507 void add_vector(int64_t** param, index_t* length, 00508 const char* name, const char* description=""); 00515 void add_vector(uint64_t** param, index_t* length, 00516 const char* name, const char* description=""); 00523 void add_vector(float32_t** param, index_t* length, 00524 const char* name, const char* description=""); 00531 void add_vector(float64_t** param, index_t* length, 00532 const char* name, const char* description=""); 00539 void add_vector(floatmax_t** param, index_t* length, 00540 const char* name, const char* description=""); 00547 void add_vector(CSGObject*** param, index_t* length, 00548 const char* name, const char* description=""); 00555 void add_vector(SGString<bool>** param, index_t* length, 00556 const char* name, const char* description=""); 00563 void add_vector(SGString<char>** param, index_t* length, 00564 const char* name, const char* description=""); 00571 void add_vector(SGString<int8_t>** param, index_t* length, 00572 const char* name, const char* description=""); 00579 void add_vector(SGString<uint8_t>** param, index_t* length, 00580 const char* name, const char* description=""); 00587 void add_vector(SGString<int16_t>** param, index_t* length, 00588 const char* name, const char* description=""); 00595 void add_vector(SGString<uint16_t>** param, index_t* length, 00596 const char* name, const char* description=""); 00603 void add_vector(SGString<int32_t>** param, index_t* length, 00604 const char* name, const char* description=""); 00611 void add_vector(SGString<uint32_t>** param, index_t* length, 00612 const char* name, const char* description=""); 00619 void add_vector(SGString<int64_t>** param, index_t* length, 00620 const char* name, const char* description=""); 00627 void add_vector(SGString<uint64_t>** param, index_t* length, 00628 const char* name, const char* description=""); 00635 void add_vector(SGString<float32_t>** param, index_t* length, 00636 const char* name, const char* description=""); 00643 void add_vector(SGString<float64_t>** param, index_t* length, 00644 const char* name, const char* description=""); 00651 void add_vector(SGString<floatmax_t>** param, index_t* length, 00652 const char* name, const char* description=""); 00659 void add_vector(SGSparseVector<bool>** param, index_t* length, 00660 const char* name, const char* description=""); 00667 void add_vector(SGSparseVector<char>** param, index_t* length, 00668 const char* name, const char* description=""); 00675 void add_vector(SGSparseVector<int8_t>** param, index_t* length, 00676 const char* name, const char* description=""); 00683 void add_vector(SGSparseVector<uint8_t>** param, index_t* length, 00684 const char* name, const char* description=""); 00691 void add_vector(SGSparseVector<int16_t>** param, index_t* length, 00692 const char* name, const char* description=""); 00699 void add_vector(SGSparseVector<uint16_t>** param, index_t* length, 00700 const char* name, const char* description=""); 00707 void add_vector(SGSparseVector<int32_t>** param, index_t* length, 00708 const char* name, const char* description=""); 00715 void add_vector(SGSparseVector<uint32_t>** param, index_t* length, 00716 const char* name, const char* description=""); 00723 void add_vector(SGSparseVector<int64_t>** param, index_t* length, 00724 const char* name, const char* description=""); 00731 void add_vector(SGSparseVector<uint64_t>** param, index_t* length, 00732 const char* name, const char* description=""); 00739 void add_vector(SGSparseVector<float32_t>** param, index_t* length, 00740 const char* name, const char* description=""); 00747 void add_vector(SGSparseVector<float64_t>** param, index_t* length, 00748 const char* name, const char* description=""); 00755 void add_vector(SGSparseVector<floatmax_t>** param, index_t* length, 00756 const char* name, const char* description=""); 00757 00758 00764 void add(SGVector<bool>* param, const char* name, 00765 const char* description=""); 00771 void add(SGVector<char>* param, const char* name, 00772 const char* description=""); 00778 void add(SGVector<int8_t>* param, const char* name, 00779 const char* description=""); 00785 void add(SGVector<uint8_t>* param, const char* name, 00786 const char* description=""); 00792 void add(SGVector<int16_t>* param, const char* name, 00793 const char* description=""); 00799 void add(SGVector<uint16_t>* param, const char* name, 00800 const char* description=""); 00806 void add(SGVector<int32_t>* param, const char* name, 00807 const char* description=""); 00813 void add(SGVector<uint32_t>* param, const char* name, 00814 const char* description=""); 00820 void add(SGVector<int64_t>* param, const char* name, 00821 const char* description=""); 00827 void add(SGVector<uint64_t>* param, const char* name, 00828 const char* description=""); 00834 void add(SGVector<float32_t>* param, const char* name, 00835 const char* description=""); 00841 void add(SGVector<float64_t>* param, const char* name, 00842 const char* description=""); 00848 void add(SGVector<floatmax_t>* param, const char* name, 00849 const char* description=""); 00855 void add(SGVector<CSGObject*>* param, const char* name, 00856 const char* description=""); 00862 void add(SGVector<SGString<bool> >* param, const char* name, 00863 const char* description=""); 00869 void add(SGVector<SGString<char> >* param, const char* name, 00870 const char* description=""); 00876 void add(SGVector<SGString<int8_t> >* param, const char* name, 00877 const char* description=""); 00883 void add(SGVector<SGString<uint8_t> >* param, const char* name, 00884 const char* description=""); 00890 void add(SGVector<SGString<int16_t> >* param, const char* name, 00891 const char* description=""); 00897 void add(SGVector<SGString<uint16_t> >* param, const char* name, 00898 const char* description=""); 00904 void add(SGVector<SGString<int32_t> >* param, const char* name, 00905 const char* description=""); 00911 void add(SGVector<SGString<uint32_t> >* param, const char* name, 00912 const char* description=""); 00918 void add(SGVector<SGString<int64_t> >* param, const char* name, 00919 const char* description=""); 00925 void add(SGVector<SGString<uint64_t> >* param, const char* name, 00926 const char* description=""); 00932 void add(SGVector<SGString<float32_t> >* param, const char* name, 00933 const char* description=""); 00939 void add(SGVector<SGString<float64_t> >* param, const char* name, 00940 const char* description=""); 00946 void add(SGVector<SGString<floatmax_t> >* param, const char* name, 00947 const char* description=""); 00953 void add(SGVector<SGSparseVector<bool> >* param, const char* name, 00954 const char* description=""); 00960 void add(SGVector<SGSparseVector<char> >* param, const char* name, 00961 const char* description=""); 00967 void add(SGVector<SGSparseVector<int8_t> >* param, const char* name, 00968 const char* description=""); 00974 void add(SGVector<SGSparseVector<uint8_t> >* param,const char* name, 00975 const char* description=""); 00981 void add(SGVector<SGSparseVector<int16_t> >* param, const char* name, 00982 const char* description=""); 00988 void add(SGVector<SGSparseVector<uint16_t> >* param, 00989 const char* name, const char* description=""); 00995 void add(SGVector<SGSparseVector<int32_t> >* param, const char* name, 00996 const char* description=""); 01002 void add(SGVector<SGSparseVector<uint32_t> >* param,const char* name, 01003 const char* description=""); 01009 void add(SGVector<SGSparseVector<int64_t> >* param, const char* name, 01010 const char* description=""); 01016 void add(SGVector<SGSparseVector<uint64_t> >* param, 01017 const char* name, const char* description=""); 01023 void add(SGVector<SGSparseVector<float32_t> >* param, 01024 const char* name, const char* description=""); 01030 void add(SGVector<SGSparseVector<float64_t> >* param, 01031 const char* name, const char* description=""); 01037 void add(SGVector<SGSparseVector<floatmax_t> >* param, 01038 const char* name, const char* description=""); 01039 01040 /* ************************************************************ */ 01041 /* Matrix wrappers */ 01042 01050 void add_matrix(bool** param, 01051 index_t* length_y, index_t* length_x, 01052 const char* name, const char* description=""); 01060 void add_matrix(char** param, 01061 index_t* length_y, index_t* length_x, 01062 const char* name, const char* description=""); 01070 void add_matrix(int8_t** param, 01071 index_t* length_y, index_t* length_x, 01072 const char* name, const char* description=""); 01080 void add_matrix(uint8_t** param, 01081 index_t* length_y, index_t* length_x, 01082 const char* name, const char* description=""); 01090 void add_matrix(int16_t** param, 01091 index_t* length_y, index_t* length_x, 01092 const char* name, const char* description=""); 01100 void add_matrix(uint16_t** param, 01101 index_t* length_y, index_t* length_x, 01102 const char* name, const char* description=""); 01110 void add_matrix(int32_t** param, 01111 index_t* length_y, index_t* length_x, 01112 const char* name, const char* description=""); 01120 void add_matrix(uint32_t** param, 01121 index_t* length_y, index_t* length_x, 01122 const char* name, const char* description=""); 01130 void add_matrix(int64_t** param, 01131 index_t* length_y, index_t* length_x, 01132 const char* name, const char* description=""); 01140 void add_matrix(uint64_t** param, 01141 index_t* length_y, index_t* length_x, 01142 const char* name, const char* description=""); 01150 void add_matrix(float32_t** param, 01151 index_t* length_y, index_t* length_x, 01152 const char* name, const char* description=""); 01160 void add_matrix(float64_t** param, 01161 index_t* length_y, index_t* length_x, 01162 const char* name, const char* description=""); 01170 void add_matrix(floatmax_t** param, 01171 index_t* length_y, index_t* length_x, 01172 const char* name, const char* description=""); 01180 void add_matrix(CSGObject*** param, 01181 index_t* length_y, index_t* length_x, 01182 const char* name, const char* description=""); 01190 void add_matrix(SGString<bool>** param, 01191 index_t* length_y, index_t* length_x, 01192 const char* name, const char* description=""); 01200 void add_matrix(SGString<char>** param, 01201 index_t* length_y, index_t* length_x, 01202 const char* name, const char* description=""); 01210 void add_matrix(SGString<int8_t>** param, 01211 index_t* length_y, index_t* length_x, 01212 const char* name, const char* description=""); 01220 void add_matrix(SGString<uint8_t>** param, 01221 index_t* length_y, index_t* length_x, 01222 const char* name, const char* description=""); 01230 void add_matrix(SGString<int16_t>** param, 01231 index_t* length_y, index_t* length_x, 01232 const char* name, const char* description=""); 01240 void add_matrix(SGString<uint16_t>** param, 01241 index_t* length_y, index_t* length_x, 01242 const char* name, const char* description=""); 01250 void add_matrix(SGString<int32_t>** param, 01251 index_t* length_y, index_t* length_x, 01252 const char* name, const char* description=""); 01260 void add_matrix(SGString<uint32_t>** param, 01261 index_t* length_y, index_t* length_x, 01262 const char* name, const char* description=""); 01270 void add_matrix(SGString<int64_t>** param, 01271 index_t* length_y, index_t* length_x, 01272 const char* name, const char* description=""); 01280 void add_matrix(SGString<uint64_t>** param, 01281 index_t* length_y, index_t* length_x, 01282 const char* name, const char* description=""); 01290 void add_matrix(SGString<float32_t>** param, 01291 index_t* length_y, index_t* length_x, 01292 const char* name, const char* description=""); 01300 void add_matrix(SGString<float64_t>** param, 01301 index_t* length_y, index_t* length_x, 01302 const char* name, const char* description=""); 01310 void add_matrix(SGString<floatmax_t>** param, 01311 index_t* length_y, index_t* length_x, 01312 const char* name, const char* description=""); 01320 void add_matrix(SGSparseVector<bool>** param, 01321 index_t* length_y, index_t* length_x, 01322 const char* name, const char* description=""); 01330 void add_matrix(SGSparseVector<char>** param, 01331 index_t* length_y, index_t* length_x, 01332 const char* name, const char* description=""); 01340 void add_matrix(SGSparseVector<int8_t>** param, 01341 index_t* length_y, index_t* length_x, 01342 const char* name, const char* description=""); 01350 void add_matrix(SGSparseVector<uint8_t>** param, 01351 index_t* length_y, index_t* length_x, 01352 const char* name, const char* description=""); 01360 void add_matrix(SGSparseVector<int16_t>** param, 01361 index_t* length_y, index_t* length_x, 01362 const char* name, const char* description=""); 01370 void add_matrix(SGSparseVector<uint16_t>** param, 01371 index_t* length_y, index_t* length_x, 01372 const char* name, const char* description=""); 01380 void add_matrix(SGSparseVector<int32_t>** param, 01381 index_t* length_y, index_t* length_x, 01382 const char* name, const char* description=""); 01390 void add_matrix(SGSparseVector<uint32_t>** param, 01391 index_t* length_y, index_t* length_x, 01392 const char* name, const char* description=""); 01400 void add_matrix(SGSparseVector<int64_t>** param, 01401 index_t* length_y, index_t* length_x, 01402 const char* name, const char* description=""); 01410 void add_matrix(SGSparseVector<uint64_t>** param, 01411 index_t* length_y, index_t* length_x, 01412 const char* name, const char* description=""); 01420 void add_matrix(SGSparseVector<float32_t>** param, 01421 index_t* length_y, index_t* length_x, 01422 const char* name, const char* description=""); 01430 void add_matrix(SGSparseVector<float64_t>** param, 01431 index_t* length_y, index_t* length_x, 01432 const char* name, const char* description=""); 01440 void add_matrix(SGSparseVector<floatmax_t>** param, 01441 index_t* length_y, index_t* length_x, 01442 const char* name, const char* description=""); 01448 void add(SGMatrix<bool>* param, const char* name, 01449 const char* description=""); 01455 void add(SGMatrix<char>* param, const char* name, 01456 const char* description=""); 01462 void add(SGMatrix<int8_t>* param, const char* name, 01463 const char* description=""); 01469 void add(SGMatrix<uint8_t>* param, const char* name, 01470 const char* description=""); 01476 void add(SGMatrix<int16_t>* param, const char* name, 01477 const char* description=""); 01483 void add(SGMatrix<uint16_t>* param, const char* name, 01484 const char* description=""); 01490 void add(SGMatrix<int32_t>* param, const char* name, 01491 const char* description=""); 01497 void add(SGMatrix<uint32_t>* param, const char* name, 01498 const char* description=""); 01504 void add(SGMatrix<int64_t>* param, const char* name, 01505 const char* description=""); 01511 void add(SGMatrix<uint64_t>* param, const char* name, 01512 const char* description=""); 01518 void add(SGMatrix<float32_t>* param, const char* name, 01519 const char* description=""); 01525 void add(SGMatrix<float64_t>* param, const char* name, 01526 const char* description=""); 01532 void add(SGMatrix<floatmax_t>* param, const char* name, 01533 const char* description=""); 01539 void add(SGMatrix<CSGObject*>* param, const char* name, 01540 const char* description=""); 01546 void add(SGMatrix<SGString<bool> >* param, const char* name, 01547 const char* description=""); 01553 void add(SGMatrix<SGString<char> >* param, const char* name, 01554 const char* description=""); 01560 void add(SGMatrix<SGString<int8_t> >* param, const char* name, 01561 const char* description=""); 01567 void add(SGMatrix<SGString<uint8_t> >* param, const char* name, 01568 const char* description=""); 01574 void add(SGMatrix<SGString<int16_t> >* param, const char* name, 01575 const char* description=""); 01581 void add(SGMatrix<SGString<uint16_t> >* param, const char* name, 01582 const char* description=""); 01588 void add(SGMatrix<SGString<int32_t> >* param, const char* name, 01589 const char* description=""); 01595 void add(SGMatrix<SGString<uint32_t> >* param, const char* name, 01596 const char* description=""); 01602 void add(SGMatrix<SGString<int64_t> >* param, const char* name, 01603 const char* description=""); 01609 void add(SGMatrix<SGString<uint64_t> >* param, const char* name, 01610 const char* description=""); 01616 void add(SGMatrix<SGString<float32_t> >* param, const char* name, 01617 const char* description=""); 01623 void add(SGMatrix<SGString<float64_t> >* param, const char* name, 01624 const char* description=""); 01630 void add(SGMatrix<SGString<floatmax_t> >* param, const char* name, 01631 const char* description=""); 01637 void add(SGMatrix<SGSparseVector<bool> >* param, const char* name, 01638 const char* description=""); 01644 void add(SGMatrix<SGSparseVector<char> >* param, const char* name, 01645 const char* description=""); 01651 void add(SGMatrix<SGSparseVector<int8_t> >* param, const char* name, 01652 const char* description=""); 01658 void add(SGMatrix<SGSparseVector<uint8_t> >* param,const char* name, 01659 const char* description=""); 01665 void add(SGMatrix<SGSparseVector<int16_t> >* param, const char* name, 01666 const char* description=""); 01672 void add(SGMatrix<SGSparseVector<uint16_t> >* param, 01673 const char* name, const char* description=""); 01679 void add(SGMatrix<SGSparseVector<int32_t> >* param, const char* name, 01680 const char* description=""); 01686 void add(SGMatrix<SGSparseVector<uint32_t> >* param,const char* name, 01687 const char* description=""); 01693 void add(SGMatrix<SGSparseVector<int64_t> >* param, const char* name, 01694 const char* description=""); 01700 void add(SGMatrix<SGSparseVector<uint64_t> >* param, 01701 const char* name, const char* description=""); 01707 void add(SGMatrix<SGSparseVector<float32_t> >* param, 01708 const char* name, const char* description=""); 01714 void add(SGMatrix<SGSparseVector<float64_t> >* param, 01715 const char* name, const char* description=""); 01721 void add(SGMatrix<SGSparseVector<floatmax_t> >* param, 01722 const char* name, const char* description=""); 01723 01724 protected: 01725 01727 DynArray<TParameter*> m_params; 01728 01735 virtual void add_type(const TSGDataType* type, void* param, 01736 const char* name, 01737 const char* description); 01738 }; 01739 } 01740 #endif //__PARAMETER_H__