00001
00002
00003
00004
00005
00006
00007
00008
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/lib/SGVector.h>
00017 #include <shogun/lib/SGMatrix.h>
00018 #include <shogun/io/SerializableFile.h>
00019 #include <shogun/base/DynArray.h>
00020
00021 namespace shogun
00022 {
00024 struct TParameter
00025 {
00032 explicit TParameter(const TSGDataType* datatype, void* parameter,
00033 const char* name, const char* description);
00034
00036 ~TParameter();
00037
00041 void print(const char* prefix);
00042
00047 bool save(CSerializableFile* file, const char* prefix="");
00048
00053 bool load(CSerializableFile* file, const char* prefix="");
00054
00069 void allocate_data_from_scratch(index_t len_y, index_t len_x,
00070 bool new_cont_call=true);
00071
00078 void copy_data(const TParameter* source);
00079
00081 bool operator==(const TParameter& other) const;
00082
00084 bool operator<(const TParameter& other) const;
00085
00087 bool operator>(const TParameter& other) const;
00088
00090 TSGDataType m_datatype;
00092 void* m_parameter;
00094 char* m_name;
00096 char* m_description;
00097
00105 bool m_delete_data;
00106
00109 bool m_was_allocated_from_scratch;
00110
00119 void get_incremental_hash(
00120 uint32_t& hash, uint32_t& carry, uint32_t& total_length);
00121
00122 private:
00123 char* new_prefix(const char* s1, const char* s2);
00124 void delete_cont();
00125 void new_cont(index_t new_len_y, index_t new_len_x);
00126 bool new_sgserial(CSGObject** param, EPrimitiveType generic,
00127 const char* sgserializable_name,
00128 const char* prefix);
00129 bool save_ptype(CSerializableFile* file, const void* param,
00130 const char* prefix);
00131 bool load_ptype(CSerializableFile* file, void* param,
00132 const char* prefix);
00133 bool save_stype(CSerializableFile* file, const void* param,
00134 const char* prefix);
00135 bool load_stype(CSerializableFile* file, void* param,
00136 const char* prefix);
00137
00138 };
00139
00145 class Parameter
00146 {
00147 public:
00149 explicit Parameter();
00151 virtual ~Parameter();
00152
00156 virtual void print(const char* prefix="");
00157
00162 virtual bool save(CSerializableFile* file, const char* prefix="");
00163
00164
00165
00166
00167
00168
00169
00173 virtual int32_t get_num_parameters()
00174 {
00175 return m_params.get_num_elements();
00176 }
00177
00186 void set_from_parameters(Parameter* params);
00187
00193 void add_parameters(Parameter* params);
00194
00199 bool contains_parameter(const char* name);
00200
00206 inline TParameter* get_parameter(int32_t idx)
00207 {
00208 return m_params.get_element(idx);
00209 }
00210
00216 inline TParameter* get_parameter(const char* name)
00217 {
00218 TParameter* result=NULL;
00219
00220 for (index_t i=0; i<m_params.get_num_elements(); ++i)
00221 {
00222 result=m_params.get_element(i);
00223 if (!strcmp(name, result->m_name))
00224 break;
00225 else
00226 result=NULL;
00227 }
00228
00229 return result;
00230 }
00231
00232
00233
00234
00240 void add(bool* param, const char* name,
00241 const char* description="");
00247 void add(char* param, const char* name,
00248 const char* description="");
00254 void add(int8_t* param, const char* name,
00255 const char* description="");
00261 void add(uint8_t* param, const char* name,
00262 const char* description="");
00268 void add(int16_t* param, const char* name,
00269 const char* description="");
00275 void add(uint16_t* param, const char* name,
00276 const char* description="");
00282 void add(int32_t* param, const char* name,
00283 const char* description="");
00289 void add(uint32_t* param, const char* name,
00290 const char* description="");
00296 void add(int64_t* param, const char* name,
00297 const char* description="");
00303 void add(uint64_t* param, const char* name,
00304 const char* description="");
00310 void add(float32_t* param, const char* name,
00311 const char* description="");
00317 void add(float64_t* param, const char* name,
00318 const char* description="");
00324 void add(floatmax_t* param, const char* name,
00325 const char* description="");
00331 void add(CSGObject** param,
00332 const char* name, const char* description="");
00338 void add(SGString<bool>* param, const char* name,
00339 const char* description="");
00345 void add(SGString<char>* param, const char* name,
00346 const char* description="");
00352 void add(SGString<int8_t>* param, const char* name,
00353 const char* description="");
00359 void add(SGString<uint8_t>* param, const char* name,
00360 const char* description="");
00366 void add(SGString<int16_t>* param, const char* name,
00367 const char* description="");
00373 void add(SGString<uint16_t>* param, const char* name,
00374 const char* description="");
00380 void add(SGString<int32_t>* param, const char* name,
00381 const char* description="");
00387 void add(SGString<uint32_t>* param, const char* name,
00388 const char* description="");
00394 void add(SGString<int64_t>* param, const char* name,
00395 const char* description="");
00401 void add(SGString<uint64_t>* param, const char* name,
00402 const char* description="");
00408 void add(SGString<float32_t>* param, const char* name,
00409 const char* description="");
00415 void add(SGString<float64_t>* param, const char* name,
00416 const char* description="");
00422 void add(SGString<floatmax_t>* param, const char* name,
00423 const char* description="");
00429 void add(SGSparseVector<bool>* param, const char* name,
00430 const char* description="");
00436 void add(SGSparseVector<char>* param, const char* name,
00437 const char* description="");
00443 void add(SGSparseVector<int8_t>* param, const char* name,
00444 const char* description="");
00450 void add(SGSparseVector<uint8_t>* param, const char* name,
00451 const char* description="");
00457 void add(SGSparseVector<int16_t>* param, const char* name,
00458 const char* description="");
00464 void add(SGSparseVector<uint16_t>* param, const char* name,
00465 const char* description="");
00471 void add(SGSparseVector<int32_t>* param, const char* name,
00472 const char* description="");
00478 void add(SGSparseVector<uint32_t>* param, const char* name,
00479 const char* description="");
00485 void add(SGSparseVector<int64_t>* param, const char* name,
00486 const char* description="");
00492 void add(SGSparseVector<uint64_t>* param, const char* name,
00493 const char* description="");
00499 void add(SGSparseVector<float32_t>* param, const char* name,
00500 const char* description="");
00506 void add(SGSparseVector<float64_t>* param, const char* name,
00507 const char* description="");
00513 void add(SGSparseVector<floatmax_t>* param, const char* name,
00514 const char* description="");
00515
00516
00517
00518
00525 void add_vector(bool** param, index_t* length,
00526 const char* name, const char* description="");
00533 void add_vector(char** param, index_t* length,
00534 const char* name, const char* description="");
00541 void add_vector(int8_t** param, index_t* length,
00542 const char* name, const char* description="");
00549 void add_vector(uint8_t** param, index_t* length,
00550 const char* name, const char* description="");
00557 void add_vector(int16_t** param, index_t* length,
00558 const char* name, const char* description="");
00565 void add_vector(uint16_t** param, index_t* length,
00566 const char* name, const char* description="");
00573 void add_vector(int32_t** param, index_t* length,
00574 const char* name, const char* description="");
00581 void add_vector(uint32_t** param, index_t* length,
00582 const char* name, const char* description="");
00589 void add_vector(int64_t** param, index_t* length,
00590 const char* name, const char* description="");
00597 void add_vector(uint64_t** param, index_t* length,
00598 const char* name, const char* description="");
00605 void add_vector(float32_t** param, index_t* length,
00606 const char* name, const char* description="");
00613 void add_vector(float64_t** param, index_t* length,
00614 const char* name, const char* description="");
00621 void add_vector(floatmax_t** param, index_t* length,
00622 const char* name, const char* description="");
00629 void add_vector(CSGObject*** param, index_t* length,
00630 const char* name, const char* description="");
00637 void add_vector(SGString<bool>** param, index_t* length,
00638 const char* name, const char* description="");
00645 void add_vector(SGString<char>** param, index_t* length,
00646 const char* name, const char* description="");
00653 void add_vector(SGString<int8_t>** param, index_t* length,
00654 const char* name, const char* description="");
00661 void add_vector(SGString<uint8_t>** param, index_t* length,
00662 const char* name, const char* description="");
00669 void add_vector(SGString<int16_t>** param, index_t* length,
00670 const char* name, const char* description="");
00677 void add_vector(SGString<uint16_t>** param, index_t* length,
00678 const char* name, const char* description="");
00685 void add_vector(SGString<int32_t>** param, index_t* length,
00686 const char* name, const char* description="");
00693 void add_vector(SGString<uint32_t>** param, index_t* length,
00694 const char* name, const char* description="");
00701 void add_vector(SGString<int64_t>** param, index_t* length,
00702 const char* name, const char* description="");
00709 void add_vector(SGString<uint64_t>** param, index_t* length,
00710 const char* name, const char* description="");
00717 void add_vector(SGString<float32_t>** param, index_t* length,
00718 const char* name, const char* description="");
00725 void add_vector(SGString<float64_t>** param, index_t* length,
00726 const char* name, const char* description="");
00733 void add_vector(SGString<floatmax_t>** param, index_t* length,
00734 const char* name, const char* description="");
00741 void add_vector(SGSparseVector<bool>** param, index_t* length,
00742 const char* name, const char* description="");
00749 void add_vector(SGSparseVector<char>** param, index_t* length,
00750 const char* name, const char* description="");
00757 void add_vector(SGSparseVector<int8_t>** param, index_t* length,
00758 const char* name, const char* description="");
00765 void add_vector(SGSparseVector<uint8_t>** param, index_t* length,
00766 const char* name, const char* description="");
00773 void add_vector(SGSparseVector<int16_t>** param, index_t* length,
00774 const char* name, const char* description="");
00781 void add_vector(SGSparseVector<uint16_t>** param, index_t* length,
00782 const char* name, const char* description="");
00789 void add_vector(SGSparseVector<int32_t>** param, index_t* length,
00790 const char* name, const char* description="");
00797 void add_vector(SGSparseVector<uint32_t>** param, index_t* length,
00798 const char* name, const char* description="");
00805 void add_vector(SGSparseVector<int64_t>** param, index_t* length,
00806 const char* name, const char* description="");
00813 void add_vector(SGSparseVector<uint64_t>** param, index_t* length,
00814 const char* name, const char* description="");
00821 void add_vector(SGSparseVector<float32_t>** param, index_t* length,
00822 const char* name, const char* description="");
00829 void add_vector(SGSparseVector<float64_t>** param, index_t* length,
00830 const char* name, const char* description="");
00837 void add_vector(SGSparseVector<floatmax_t>** param, index_t* length,
00838 const char* name, const char* description="");
00839
00840
00846 void add(SGVector<bool>* param, const char* name,
00847 const char* description="");
00853 void add(SGVector<char>* param, const char* name,
00854 const char* description="");
00860 void add(SGVector<int8_t>* param, const char* name,
00861 const char* description="");
00867 void add(SGVector<uint8_t>* param, const char* name,
00868 const char* description="");
00874 void add(SGVector<int16_t>* param, const char* name,
00875 const char* description="");
00881 void add(SGVector<uint16_t>* param, const char* name,
00882 const char* description="");
00888 void add(SGVector<int32_t>* param, const char* name,
00889 const char* description="");
00895 void add(SGVector<uint32_t>* param, const char* name,
00896 const char* description="");
00902 void add(SGVector<int64_t>* param, const char* name,
00903 const char* description="");
00909 void add(SGVector<uint64_t>* param, const char* name,
00910 const char* description="");
00916 void add(SGVector<float32_t>* param, const char* name,
00917 const char* description="");
00923 void add(SGVector<float64_t>* param, const char* name,
00924 const char* description="");
00930 void add(SGVector<floatmax_t>* param, const char* name,
00931 const char* description="");
00937 void add(SGVector<CSGObject*>* param, const char* name,
00938 const char* description="");
00944 void add(SGVector<SGString<bool> >* param, const char* name,
00945 const char* description="");
00951 void add(SGVector<SGString<char> >* param, const char* name,
00952 const char* description="");
00958 void add(SGVector<SGString<int8_t> >* param, const char* name,
00959 const char* description="");
00965 void add(SGVector<SGString<uint8_t> >* param, const char* name,
00966 const char* description="");
00972 void add(SGVector<SGString<int16_t> >* param, const char* name,
00973 const char* description="");
00979 void add(SGVector<SGString<uint16_t> >* param, const char* name,
00980 const char* description="");
00986 void add(SGVector<SGString<int32_t> >* param, const char* name,
00987 const char* description="");
00993 void add(SGVector<SGString<uint32_t> >* param, const char* name,
00994 const char* description="");
01000 void add(SGVector<SGString<int64_t> >* param, const char* name,
01001 const char* description="");
01007 void add(SGVector<SGString<uint64_t> >* param, const char* name,
01008 const char* description="");
01014 void add(SGVector<SGString<float32_t> >* param, const char* name,
01015 const char* description="");
01021 void add(SGVector<SGString<float64_t> >* param, const char* name,
01022 const char* description="");
01028 void add(SGVector<SGString<floatmax_t> >* param, const char* name,
01029 const char* description="");
01035 void add(SGVector<SGSparseVector<bool> >* param, const char* name,
01036 const char* description="");
01042 void add(SGVector<SGSparseVector<char> >* param, const char* name,
01043 const char* description="");
01049 void add(SGVector<SGSparseVector<int8_t> >* param, const char* name,
01050 const char* description="");
01056 void add(SGVector<SGSparseVector<uint8_t> >* param,const char* name,
01057 const char* description="");
01063 void add(SGVector<SGSparseVector<int16_t> >* param, const char* name,
01064 const char* description="");
01070 void add(SGVector<SGSparseVector<uint16_t> >* param,
01071 const char* name, const char* description="");
01077 void add(SGVector<SGSparseVector<int32_t> >* param, const char* name,
01078 const char* description="");
01084 void add(SGVector<SGSparseVector<uint32_t> >* param,const char* name,
01085 const char* description="");
01091 void add(SGVector<SGSparseVector<int64_t> >* param, const char* name,
01092 const char* description="");
01098 void add(SGVector<SGSparseVector<uint64_t> >* param,
01099 const char* name, const char* description="");
01105 void add(SGVector<SGSparseVector<float32_t> >* param,
01106 const char* name, const char* description="");
01112 void add(SGVector<SGSparseVector<float64_t> >* param,
01113 const char* name, const char* description="");
01119 void add(SGVector<SGSparseVector<floatmax_t> >* param,
01120 const char* name, const char* description="");
01121
01122
01123
01124
01132 void add_matrix(bool** param,
01133 index_t* length_y, index_t* length_x,
01134 const char* name, const char* description="");
01142 void add_matrix(char** param,
01143 index_t* length_y, index_t* length_x,
01144 const char* name, const char* description="");
01152 void add_matrix(int8_t** param,
01153 index_t* length_y, index_t* length_x,
01154 const char* name, const char* description="");
01162 void add_matrix(uint8_t** param,
01163 index_t* length_y, index_t* length_x,
01164 const char* name, const char* description="");
01172 void add_matrix(int16_t** param,
01173 index_t* length_y, index_t* length_x,
01174 const char* name, const char* description="");
01182 void add_matrix(uint16_t** param,
01183 index_t* length_y, index_t* length_x,
01184 const char* name, const char* description="");
01192 void add_matrix(int32_t** param,
01193 index_t* length_y, index_t* length_x,
01194 const char* name, const char* description="");
01202 void add_matrix(uint32_t** param,
01203 index_t* length_y, index_t* length_x,
01204 const char* name, const char* description="");
01212 void add_matrix(int64_t** param,
01213 index_t* length_y, index_t* length_x,
01214 const char* name, const char* description="");
01222 void add_matrix(uint64_t** param,
01223 index_t* length_y, index_t* length_x,
01224 const char* name, const char* description="");
01232 void add_matrix(float32_t** param,
01233 index_t* length_y, index_t* length_x,
01234 const char* name, const char* description="");
01242 void add_matrix(float64_t** param,
01243 index_t* length_y, index_t* length_x,
01244 const char* name, const char* description="");
01252 void add_matrix(floatmax_t** param,
01253 index_t* length_y, index_t* length_x,
01254 const char* name, const char* description="");
01262 void add_matrix(CSGObject*** param,
01263 index_t* length_y, index_t* length_x,
01264 const char* name, const char* description="");
01272 void add_matrix(SGString<bool>** param,
01273 index_t* length_y, index_t* length_x,
01274 const char* name, const char* description="");
01282 void add_matrix(SGString<char>** param,
01283 index_t* length_y, index_t* length_x,
01284 const char* name, const char* description="");
01292 void add_matrix(SGString<int8_t>** param,
01293 index_t* length_y, index_t* length_x,
01294 const char* name, const char* description="");
01302 void add_matrix(SGString<uint8_t>** param,
01303 index_t* length_y, index_t* length_x,
01304 const char* name, const char* description="");
01312 void add_matrix(SGString<int16_t>** param,
01313 index_t* length_y, index_t* length_x,
01314 const char* name, const char* description="");
01322 void add_matrix(SGString<uint16_t>** param,
01323 index_t* length_y, index_t* length_x,
01324 const char* name, const char* description="");
01332 void add_matrix(SGString<int32_t>** param,
01333 index_t* length_y, index_t* length_x,
01334 const char* name, const char* description="");
01342 void add_matrix(SGString<uint32_t>** param,
01343 index_t* length_y, index_t* length_x,
01344 const char* name, const char* description="");
01352 void add_matrix(SGString<int64_t>** param,
01353 index_t* length_y, index_t* length_x,
01354 const char* name, const char* description="");
01362 void add_matrix(SGString<uint64_t>** param,
01363 index_t* length_y, index_t* length_x,
01364 const char* name, const char* description="");
01372 void add_matrix(SGString<float32_t>** param,
01373 index_t* length_y, index_t* length_x,
01374 const char* name, const char* description="");
01382 void add_matrix(SGString<float64_t>** param,
01383 index_t* length_y, index_t* length_x,
01384 const char* name, const char* description="");
01392 void add_matrix(SGString<floatmax_t>** param,
01393 index_t* length_y, index_t* length_x,
01394 const char* name, const char* description="");
01402 void add_matrix(SGSparseVector<bool>** param,
01403 index_t* length_y, index_t* length_x,
01404 const char* name, const char* description="");
01412 void add_matrix(SGSparseVector<char>** param,
01413 index_t* length_y, index_t* length_x,
01414 const char* name, const char* description="");
01422 void add_matrix(SGSparseVector<int8_t>** param,
01423 index_t* length_y, index_t* length_x,
01424 const char* name, const char* description="");
01432 void add_matrix(SGSparseVector<uint8_t>** param,
01433 index_t* length_y, index_t* length_x,
01434 const char* name, const char* description="");
01442 void add_matrix(SGSparseVector<int16_t>** param,
01443 index_t* length_y, index_t* length_x,
01444 const char* name, const char* description="");
01452 void add_matrix(SGSparseVector<uint16_t>** param,
01453 index_t* length_y, index_t* length_x,
01454 const char* name, const char* description="");
01462 void add_matrix(SGSparseVector<int32_t>** param,
01463 index_t* length_y, index_t* length_x,
01464 const char* name, const char* description="");
01472 void add_matrix(SGSparseVector<uint32_t>** param,
01473 index_t* length_y, index_t* length_x,
01474 const char* name, const char* description="");
01482 void add_matrix(SGSparseVector<int64_t>** param,
01483 index_t* length_y, index_t* length_x,
01484 const char* name, const char* description="");
01492 void add_matrix(SGSparseVector<uint64_t>** param,
01493 index_t* length_y, index_t* length_x,
01494 const char* name, const char* description="");
01502 void add_matrix(SGSparseVector<float32_t>** param,
01503 index_t* length_y, index_t* length_x,
01504 const char* name, const char* description="");
01512 void add_matrix(SGSparseVector<float64_t>** param,
01513 index_t* length_y, index_t* length_x,
01514 const char* name, const char* description="");
01522 void add_matrix(SGSparseVector<floatmax_t>** param,
01523 index_t* length_y, index_t* length_x,
01524 const char* name, const char* description="");
01530 void add(SGMatrix<bool>* param, const char* name,
01531 const char* description="");
01537 void add(SGMatrix<char>* param, const char* name,
01538 const char* description="");
01544 void add(SGMatrix<int8_t>* param, const char* name,
01545 const char* description="");
01551 void add(SGMatrix<uint8_t>* param, const char* name,
01552 const char* description="");
01558 void add(SGMatrix<int16_t>* param, const char* name,
01559 const char* description="");
01565 void add(SGMatrix<uint16_t>* param, const char* name,
01566 const char* description="");
01572 void add(SGMatrix<int32_t>* param, const char* name,
01573 const char* description="");
01579 void add(SGMatrix<uint32_t>* param, const char* name,
01580 const char* description="");
01586 void add(SGMatrix<int64_t>* param, const char* name,
01587 const char* description="");
01593 void add(SGMatrix<uint64_t>* param, const char* name,
01594 const char* description="");
01600 void add(SGMatrix<float32_t>* param, const char* name,
01601 const char* description="");
01607 void add(SGMatrix<float64_t>* param, const char* name,
01608 const char* description="");
01614 void add(SGMatrix<floatmax_t>* param, const char* name,
01615 const char* description="");
01621 void add(SGMatrix<CSGObject*>* param, const char* name,
01622 const char* description="");
01628 void add(SGMatrix<SGString<bool> >* param, const char* name,
01629 const char* description="");
01635 void add(SGMatrix<SGString<char> >* param, const char* name,
01636 const char* description="");
01642 void add(SGMatrix<SGString<int8_t> >* param, const char* name,
01643 const char* description="");
01649 void add(SGMatrix<SGString<uint8_t> >* param, const char* name,
01650 const char* description="");
01656 void add(SGMatrix<SGString<int16_t> >* param, const char* name,
01657 const char* description="");
01663 void add(SGMatrix<SGString<uint16_t> >* param, const char* name,
01664 const char* description="");
01670 void add(SGMatrix<SGString<int32_t> >* param, const char* name,
01671 const char* description="");
01677 void add(SGMatrix<SGString<uint32_t> >* param, const char* name,
01678 const char* description="");
01684 void add(SGMatrix<SGString<int64_t> >* param, const char* name,
01685 const char* description="");
01691 void add(SGMatrix<SGString<uint64_t> >* param, const char* name,
01692 const char* description="");
01698 void add(SGMatrix<SGString<float32_t> >* param, const char* name,
01699 const char* description="");
01705 void add(SGMatrix<SGString<float64_t> >* param, const char* name,
01706 const char* description="");
01712 void add(SGMatrix<SGString<floatmax_t> >* param, const char* name,
01713 const char* description="");
01719 void add(SGMatrix<SGSparseVector<bool> >* param, const char* name,
01720 const char* description="");
01726 void add(SGMatrix<SGSparseVector<char> >* param, const char* name,
01727 const char* description="");
01733 void add(SGMatrix<SGSparseVector<int8_t> >* param, const char* name,
01734 const char* description="");
01740 void add(SGMatrix<SGSparseVector<uint8_t> >* param,const char* name,
01741 const char* description="");
01747 void add(SGMatrix<SGSparseVector<int16_t> >* param, const char* name,
01748 const char* description="");
01754 void add(SGMatrix<SGSparseVector<uint16_t> >* param,
01755 const char* name, const char* description="");
01761 void add(SGMatrix<SGSparseVector<int32_t> >* param, const char* name,
01762 const char* description="");
01768 void add(SGMatrix<SGSparseVector<uint32_t> >* param,const char* name,
01769 const char* description="");
01775 void add(SGMatrix<SGSparseVector<int64_t> >* param, const char* name,
01776 const char* description="");
01782 void add(SGMatrix<SGSparseVector<uint64_t> >* param,
01783 const char* name, const char* description="");
01789 void add(SGMatrix<SGSparseVector<float32_t> >* param,
01790 const char* name, const char* description="");
01796 void add(SGMatrix<SGSparseVector<float64_t> >* param,
01797 const char* name, const char* description="");
01803 void add(SGMatrix<SGSparseVector<floatmax_t> >* param,
01804 const char* name, const char* description="");
01805
01806 protected:
01807
01809 DynArray<TParameter*> m_params;
01810
01817 virtual void add_type(const TSGDataType* type, void* param,
01818 const char* name,
01819 const char* description);
01820 };
01821 }
01822 #endif //__PARAMETER_H__