SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parameter.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2010 Soeren Sonnenburg
8  * Copyright (C) 2010 Berlin Institute of Technology
9  */
10 #ifndef __PARAMETER_H__
11 #define __PARAMETER_H__
12 
13 #include <shogun/lib/common.h>
14 #include <shogun/io/SGIO.h>
15 #include <shogun/lib/DataType.h>
16 #include <shogun/lib/SGVector.h>
17 #include <shogun/lib/SGMatrix.h>
19 #include <shogun/base/DynArray.h>
20 
21 namespace shogun
22 {
24 struct TParameter
25 {
32  explicit TParameter(const TSGDataType* datatype, void* parameter,
33  const char* name, const char* description);
34 
36  ~TParameter();
37 
41  void print(const char* prefix);
42 
47  bool save(CSerializableFile* file, const char* prefix="");
48 
53  bool load(CSerializableFile* file, const char* prefix="");
54 
69  void allocate_data_from_scratch(index_t len_y, index_t len_x,
70  bool new_cont_call=true);
71 
78  void copy_data(const TParameter* source);
79 
81  bool operator==(const TParameter& other) const;
82 
84  bool operator<(const TParameter& other) const;
85 
87  bool operator>(const TParameter& other) const;
88 
92  void* m_parameter;
94  char* m_name;
97 
106 
110 
120  uint32_t& hash, uint32_t& carry, uint32_t& total_length);
121 
122 private:
123  char* new_prefix(const char* s1, const char* s2);
124  void delete_cont();
125  void new_cont(index_t new_len_y, index_t new_len_x);
126  bool new_sgserial(CSGObject** param, EPrimitiveType generic,
127  const char* sgserializable_name,
128  const char* prefix);
129  bool save_ptype(CSerializableFile* file, const void* param,
130  const char* prefix);
131  bool load_ptype(CSerializableFile* file, void* param,
132  const char* prefix);
133  bool save_stype(CSerializableFile* file, const void* param,
134  const char* prefix);
135  bool load_stype(CSerializableFile* file, void* param,
136  const char* prefix);
137 
138 };
139 
146 {
147 public:
149  explicit Parameter();
151  virtual ~Parameter();
152 
156  virtual void print(const char* prefix="");
157 
162  virtual bool save(CSerializableFile* file, const char* prefix="");
163 
164  /* load from serializable file
165  * @param file source file
166  * @param prefix prefix
167  virtual bool load(CSerializableFile* file, const char* prefix="");
168  */
169 
173  inline virtual int32_t get_num_parameters()
174  {
175  return m_params.get_num_elements();
176  }
177 
186  void set_from_parameters(Parameter* params);
187 
193  void add_parameters(Parameter* params);
194 
199  bool contains_parameter(const char* name);
200 
206  inline TParameter* get_parameter(int32_t idx)
207  {
208  return m_params.get_element(idx);
209  }
210 
211  /* ************************************************************ */
212  /* Scalar wrappers */
213 
219  void add(bool* param, const char* name,
220  const char* description="");
226  void add(char* param, const char* name,
227  const char* description="");
233  void add(int8_t* param, const char* name,
234  const char* description="");
240  void add(uint8_t* param, const char* name,
241  const char* description="");
247  void add(int16_t* param, const char* name,
248  const char* description="");
254  void add(uint16_t* param, const char* name,
255  const char* description="");
261  void add(int32_t* param, const char* name,
262  const char* description="");
268  void add(uint32_t* param, const char* name,
269  const char* description="");
275  void add(int64_t* param, const char* name,
276  const char* description="");
282  void add(uint64_t* param, const char* name,
283  const char* description="");
289  void add(float32_t* param, const char* name,
290  const char* description="");
296  void add(float64_t* param, const char* name,
297  const char* description="");
303  void add(floatmax_t* param, const char* name,
304  const char* description="");
310  void add(CSGObject** param,
311  const char* name, const char* description="");
317  void add(SGString<bool>* param, const char* name,
318  const char* description="");
324  void add(SGString<char>* param, const char* name,
325  const char* description="");
331  void add(SGString<int8_t>* param, const char* name,
332  const char* description="");
338  void add(SGString<uint8_t>* param, const char* name,
339  const char* description="");
345  void add(SGString<int16_t>* param, const char* name,
346  const char* description="");
352  void add(SGString<uint16_t>* param, const char* name,
353  const char* description="");
359  void add(SGString<int32_t>* param, const char* name,
360  const char* description="");
366  void add(SGString<uint32_t>* param, const char* name,
367  const char* description="");
373  void add(SGString<int64_t>* param, const char* name,
374  const char* description="");
380  void add(SGString<uint64_t>* param, const char* name,
381  const char* description="");
387  void add(SGString<float32_t>* param, const char* name,
388  const char* description="");
394  void add(SGString<float64_t>* param, const char* name,
395  const char* description="");
401  void add(SGString<floatmax_t>* param, const char* name,
402  const char* description="");
408  void add(SGSparseVector<bool>* param, const char* name,
409  const char* description="");
415  void add(SGSparseVector<char>* param, const char* name,
416  const char* description="");
422  void add(SGSparseVector<int8_t>* param, const char* name,
423  const char* description="");
429  void add(SGSparseVector<uint8_t>* param, const char* name,
430  const char* description="");
436  void add(SGSparseVector<int16_t>* param, const char* name,
437  const char* description="");
443  void add(SGSparseVector<uint16_t>* param, const char* name,
444  const char* description="");
450  void add(SGSparseVector<int32_t>* param, const char* name,
451  const char* description="");
457  void add(SGSparseVector<uint32_t>* param, const char* name,
458  const char* description="");
464  void add(SGSparseVector<int64_t>* param, const char* name,
465  const char* description="");
471  void add(SGSparseVector<uint64_t>* param, const char* name,
472  const char* description="");
478  void add(SGSparseVector<float32_t>* param, const char* name,
479  const char* description="");
485  void add(SGSparseVector<float64_t>* param, const char* name,
486  const char* description="");
492  void add(SGSparseVector<floatmax_t>* param, const char* name,
493  const char* description="");
494 
495  /* ************************************************************ */
496  /* Vector wrappers */
497 
504  void add_vector(bool** param, index_t* length,
505  const char* name, const char* description="");
512  void add_vector(char** param, index_t* length,
513  const char* name, const char* description="");
520  void add_vector(int8_t** param, index_t* length,
521  const char* name, const char* description="");
528  void add_vector(uint8_t** param, index_t* length,
529  const char* name, const char* description="");
536  void add_vector(int16_t** param, index_t* length,
537  const char* name, const char* description="");
544  void add_vector(uint16_t** param, index_t* length,
545  const char* name, const char* description="");
552  void add_vector(int32_t** param, index_t* length,
553  const char* name, const char* description="");
560  void add_vector(uint32_t** param, index_t* length,
561  const char* name, const char* description="");
568  void add_vector(int64_t** param, index_t* length,
569  const char* name, const char* description="");
576  void add_vector(uint64_t** param, index_t* length,
577  const char* name, const char* description="");
584  void add_vector(float32_t** param, index_t* length,
585  const char* name, const char* description="");
592  void add_vector(float64_t** param, index_t* length,
593  const char* name, const char* description="");
600  void add_vector(floatmax_t** param, index_t* length,
601  const char* name, const char* description="");
608  void add_vector(CSGObject*** param, index_t* length,
609  const char* name, const char* description="");
616  void add_vector(SGString<bool>** param, index_t* length,
617  const char* name, const char* description="");
624  void add_vector(SGString<char>** param, index_t* length,
625  const char* name, const char* description="");
632  void add_vector(SGString<int8_t>** param, index_t* length,
633  const char* name, const char* description="");
640  void add_vector(SGString<uint8_t>** param, index_t* length,
641  const char* name, const char* description="");
648  void add_vector(SGString<int16_t>** param, index_t* length,
649  const char* name, const char* description="");
656  void add_vector(SGString<uint16_t>** param, index_t* length,
657  const char* name, const char* description="");
664  void add_vector(SGString<int32_t>** param, index_t* length,
665  const char* name, const char* description="");
672  void add_vector(SGString<uint32_t>** param, index_t* length,
673  const char* name, const char* description="");
680  void add_vector(SGString<int64_t>** param, index_t* length,
681  const char* name, const char* description="");
688  void add_vector(SGString<uint64_t>** param, index_t* length,
689  const char* name, const char* description="");
696  void add_vector(SGString<float32_t>** param, index_t* length,
697  const char* name, const char* description="");
704  void add_vector(SGString<float64_t>** param, index_t* length,
705  const char* name, const char* description="");
712  void add_vector(SGString<floatmax_t>** param, index_t* length,
713  const char* name, const char* description="");
720  void add_vector(SGSparseVector<bool>** param, index_t* length,
721  const char* name, const char* description="");
728  void add_vector(SGSparseVector<char>** param, index_t* length,
729  const char* name, const char* description="");
736  void add_vector(SGSparseVector<int8_t>** param, index_t* length,
737  const char* name, const char* description="");
744  void add_vector(SGSparseVector<uint8_t>** param, index_t* length,
745  const char* name, const char* description="");
752  void add_vector(SGSparseVector<int16_t>** param, index_t* length,
753  const char* name, const char* description="");
760  void add_vector(SGSparseVector<uint16_t>** param, index_t* length,
761  const char* name, const char* description="");
768  void add_vector(SGSparseVector<int32_t>** param, index_t* length,
769  const char* name, const char* description="");
776  void add_vector(SGSparseVector<uint32_t>** param, index_t* length,
777  const char* name, const char* description="");
784  void add_vector(SGSparseVector<int64_t>** param, index_t* length,
785  const char* name, const char* description="");
792  void add_vector(SGSparseVector<uint64_t>** param, index_t* length,
793  const char* name, const char* description="");
800  void add_vector(SGSparseVector<float32_t>** param, index_t* length,
801  const char* name, const char* description="");
808  void add_vector(SGSparseVector<float64_t>** param, index_t* length,
809  const char* name, const char* description="");
816  void add_vector(SGSparseVector<floatmax_t>** param, index_t* length,
817  const char* name, const char* description="");
818 
819 
825  void add(SGVector<bool>* param, const char* name,
826  const char* description="");
832  void add(SGVector<char>* param, const char* name,
833  const char* description="");
839  void add(SGVector<int8_t>* param, const char* name,
840  const char* description="");
846  void add(SGVector<uint8_t>* param, const char* name,
847  const char* description="");
853  void add(SGVector<int16_t>* param, const char* name,
854  const char* description="");
860  void add(SGVector<uint16_t>* param, const char* name,
861  const char* description="");
867  void add(SGVector<int32_t>* param, const char* name,
868  const char* description="");
874  void add(SGVector<uint32_t>* param, const char* name,
875  const char* description="");
881  void add(SGVector<int64_t>* param, const char* name,
882  const char* description="");
888  void add(SGVector<uint64_t>* param, const char* name,
889  const char* description="");
895  void add(SGVector<float32_t>* param, const char* name,
896  const char* description="");
902  void add(SGVector<float64_t>* param, const char* name,
903  const char* description="");
909  void add(SGVector<floatmax_t>* param, const char* name,
910  const char* description="");
916  void add(SGVector<CSGObject*>* param, const char* name,
917  const char* description="");
923  void add(SGVector<SGString<bool> >* param, const char* name,
924  const char* description="");
930  void add(SGVector<SGString<char> >* param, const char* name,
931  const char* description="");
937  void add(SGVector<SGString<int8_t> >* param, const char* name,
938  const char* description="");
944  void add(SGVector<SGString<uint8_t> >* param, const char* name,
945  const char* description="");
951  void add(SGVector<SGString<int16_t> >* param, const char* name,
952  const char* description="");
958  void add(SGVector<SGString<uint16_t> >* param, const char* name,
959  const char* description="");
965  void add(SGVector<SGString<int32_t> >* param, const char* name,
966  const char* description="");
972  void add(SGVector<SGString<uint32_t> >* param, const char* name,
973  const char* description="");
979  void add(SGVector<SGString<int64_t> >* param, const char* name,
980  const char* description="");
986  void add(SGVector<SGString<uint64_t> >* param, const char* name,
987  const char* description="");
993  void add(SGVector<SGString<float32_t> >* param, const char* name,
994  const char* description="");
1000  void add(SGVector<SGString<float64_t> >* param, const char* name,
1001  const char* description="");
1007  void add(SGVector<SGString<floatmax_t> >* param, const char* name,
1008  const char* description="");
1014  void add(SGVector<SGSparseVector<bool> >* param, const char* name,
1015  const char* description="");
1021  void add(SGVector<SGSparseVector<char> >* param, const char* name,
1022  const char* description="");
1028  void add(SGVector<SGSparseVector<int8_t> >* param, const char* name,
1029  const char* description="");
1035  void add(SGVector<SGSparseVector<uint8_t> >* param,const char* name,
1036  const char* description="");
1042  void add(SGVector<SGSparseVector<int16_t> >* param, const char* name,
1043  const char* description="");
1049  void add(SGVector<SGSparseVector<uint16_t> >* param,
1050  const char* name, const char* description="");
1056  void add(SGVector<SGSparseVector<int32_t> >* param, const char* name,
1057  const char* description="");
1063  void add(SGVector<SGSparseVector<uint32_t> >* param,const char* name,
1064  const char* description="");
1070  void add(SGVector<SGSparseVector<int64_t> >* param, const char* name,
1071  const char* description="");
1077  void add(SGVector<SGSparseVector<uint64_t> >* param,
1078  const char* name, const char* description="");
1084  void add(SGVector<SGSparseVector<float32_t> >* param,
1085  const char* name, const char* description="");
1091  void add(SGVector<SGSparseVector<float64_t> >* param,
1092  const char* name, const char* description="");
1098  void add(SGVector<SGSparseVector<floatmax_t> >* param,
1099  const char* name, const char* description="");
1100 
1101  /* ************************************************************ */
1102  /* Matrix wrappers */
1103 
1111  void add_matrix(bool** param,
1112  index_t* length_y, index_t* length_x,
1113  const char* name, const char* description="");
1121  void add_matrix(char** param,
1122  index_t* length_y, index_t* length_x,
1123  const char* name, const char* description="");
1131  void add_matrix(int8_t** param,
1132  index_t* length_y, index_t* length_x,
1133  const char* name, const char* description="");
1141  void add_matrix(uint8_t** param,
1142  index_t* length_y, index_t* length_x,
1143  const char* name, const char* description="");
1151  void add_matrix(int16_t** param,
1152  index_t* length_y, index_t* length_x,
1153  const char* name, const char* description="");
1161  void add_matrix(uint16_t** param,
1162  index_t* length_y, index_t* length_x,
1163  const char* name, const char* description="");
1171  void add_matrix(int32_t** param,
1172  index_t* length_y, index_t* length_x,
1173  const char* name, const char* description="");
1181  void add_matrix(uint32_t** param,
1182  index_t* length_y, index_t* length_x,
1183  const char* name, const char* description="");
1191  void add_matrix(int64_t** param,
1192  index_t* length_y, index_t* length_x,
1193  const char* name, const char* description="");
1201  void add_matrix(uint64_t** param,
1202  index_t* length_y, index_t* length_x,
1203  const char* name, const char* description="");
1211  void add_matrix(float32_t** param,
1212  index_t* length_y, index_t* length_x,
1213  const char* name, const char* description="");
1221  void add_matrix(float64_t** param,
1222  index_t* length_y, index_t* length_x,
1223  const char* name, const char* description="");
1231  void add_matrix(floatmax_t** param,
1232  index_t* length_y, index_t* length_x,
1233  const char* name, const char* description="");
1241  void add_matrix(CSGObject*** param,
1242  index_t* length_y, index_t* length_x,
1243  const char* name, const char* description="");
1251  void add_matrix(SGString<bool>** param,
1252  index_t* length_y, index_t* length_x,
1253  const char* name, const char* description="");
1261  void add_matrix(SGString<char>** param,
1262  index_t* length_y, index_t* length_x,
1263  const char* name, const char* description="");
1271  void add_matrix(SGString<int8_t>** param,
1272  index_t* length_y, index_t* length_x,
1273  const char* name, const char* description="");
1281  void add_matrix(SGString<uint8_t>** param,
1282  index_t* length_y, index_t* length_x,
1283  const char* name, const char* description="");
1291  void add_matrix(SGString<int16_t>** param,
1292  index_t* length_y, index_t* length_x,
1293  const char* name, const char* description="");
1301  void add_matrix(SGString<uint16_t>** param,
1302  index_t* length_y, index_t* length_x,
1303  const char* name, const char* description="");
1311  void add_matrix(SGString<int32_t>** param,
1312  index_t* length_y, index_t* length_x,
1313  const char* name, const char* description="");
1321  void add_matrix(SGString<uint32_t>** param,
1322  index_t* length_y, index_t* length_x,
1323  const char* name, const char* description="");
1331  void add_matrix(SGString<int64_t>** param,
1332  index_t* length_y, index_t* length_x,
1333  const char* name, const char* description="");
1341  void add_matrix(SGString<uint64_t>** param,
1342  index_t* length_y, index_t* length_x,
1343  const char* name, const char* description="");
1351  void add_matrix(SGString<float32_t>** param,
1352  index_t* length_y, index_t* length_x,
1353  const char* name, const char* description="");
1361  void add_matrix(SGString<float64_t>** param,
1362  index_t* length_y, index_t* length_x,
1363  const char* name, const char* description="");
1371  void add_matrix(SGString<floatmax_t>** param,
1372  index_t* length_y, index_t* length_x,
1373  const char* name, const char* description="");
1381  void add_matrix(SGSparseVector<bool>** param,
1382  index_t* length_y, index_t* length_x,
1383  const char* name, const char* description="");
1391  void add_matrix(SGSparseVector<char>** param,
1392  index_t* length_y, index_t* length_x,
1393  const char* name, const char* description="");
1401  void add_matrix(SGSparseVector<int8_t>** param,
1402  index_t* length_y, index_t* length_x,
1403  const char* name, const char* description="");
1411  void add_matrix(SGSparseVector<uint8_t>** param,
1412  index_t* length_y, index_t* length_x,
1413  const char* name, const char* description="");
1421  void add_matrix(SGSparseVector<int16_t>** param,
1422  index_t* length_y, index_t* length_x,
1423  const char* name, const char* description="");
1431  void add_matrix(SGSparseVector<uint16_t>** param,
1432  index_t* length_y, index_t* length_x,
1433  const char* name, const char* description="");
1441  void add_matrix(SGSparseVector<int32_t>** param,
1442  index_t* length_y, index_t* length_x,
1443  const char* name, const char* description="");
1451  void add_matrix(SGSparseVector<uint32_t>** param,
1452  index_t* length_y, index_t* length_x,
1453  const char* name, const char* description="");
1461  void add_matrix(SGSparseVector<int64_t>** param,
1462  index_t* length_y, index_t* length_x,
1463  const char* name, const char* description="");
1471  void add_matrix(SGSparseVector<uint64_t>** param,
1472  index_t* length_y, index_t* length_x,
1473  const char* name, const char* description="");
1482  index_t* length_y, index_t* length_x,
1483  const char* name, const char* description="");
1492  index_t* length_y, index_t* length_x,
1493  const char* name, const char* description="");
1502  index_t* length_y, index_t* length_x,
1503  const char* name, const char* description="");
1509  void add(SGMatrix<bool>* param, const char* name,
1510  const char* description="");
1516  void add(SGMatrix<char>* param, const char* name,
1517  const char* description="");
1523  void add(SGMatrix<int8_t>* param, const char* name,
1524  const char* description="");
1530  void add(SGMatrix<uint8_t>* param, const char* name,
1531  const char* description="");
1537  void add(SGMatrix<int16_t>* param, const char* name,
1538  const char* description="");
1544  void add(SGMatrix<uint16_t>* param, const char* name,
1545  const char* description="");
1551  void add(SGMatrix<int32_t>* param, const char* name,
1552  const char* description="");
1558  void add(SGMatrix<uint32_t>* param, const char* name,
1559  const char* description="");
1565  void add(SGMatrix<int64_t>* param, const char* name,
1566  const char* description="");
1572  void add(SGMatrix<uint64_t>* param, const char* name,
1573  const char* description="");
1579  void add(SGMatrix<float32_t>* param, const char* name,
1580  const char* description="");
1586  void add(SGMatrix<float64_t>* param, const char* name,
1587  const char* description="");
1593  void add(SGMatrix<floatmax_t>* param, const char* name,
1594  const char* description="");
1600  void add(SGMatrix<CSGObject*>* param, const char* name,
1601  const char* description="");
1607  void add(SGMatrix<SGString<bool> >* param, const char* name,
1608  const char* description="");
1614  void add(SGMatrix<SGString<char> >* param, const char* name,
1615  const char* description="");
1621  void add(SGMatrix<SGString<int8_t> >* param, const char* name,
1622  const char* description="");
1628  void add(SGMatrix<SGString<uint8_t> >* param, const char* name,
1629  const char* description="");
1635  void add(SGMatrix<SGString<int16_t> >* param, const char* name,
1636  const char* description="");
1642  void add(SGMatrix<SGString<uint16_t> >* param, const char* name,
1643  const char* description="");
1649  void add(SGMatrix<SGString<int32_t> >* param, const char* name,
1650  const char* description="");
1656  void add(SGMatrix<SGString<uint32_t> >* param, const char* name,
1657  const char* description="");
1663  void add(SGMatrix<SGString<int64_t> >* param, const char* name,
1664  const char* description="");
1670  void add(SGMatrix<SGString<uint64_t> >* param, const char* name,
1671  const char* description="");
1677  void add(SGMatrix<SGString<float32_t> >* param, const char* name,
1678  const char* description="");
1684  void add(SGMatrix<SGString<float64_t> >* param, const char* name,
1685  const char* description="");
1691  void add(SGMatrix<SGString<floatmax_t> >* param, const char* name,
1692  const char* description="");
1698  void add(SGMatrix<SGSparseVector<bool> >* param, const char* name,
1699  const char* description="");
1705  void add(SGMatrix<SGSparseVector<char> >* param, const char* name,
1706  const char* description="");
1712  void add(SGMatrix<SGSparseVector<int8_t> >* param, const char* name,
1713  const char* description="");
1719  void add(SGMatrix<SGSparseVector<uint8_t> >* param,const char* name,
1720  const char* description="");
1726  void add(SGMatrix<SGSparseVector<int16_t> >* param, const char* name,
1727  const char* description="");
1733  void add(SGMatrix<SGSparseVector<uint16_t> >* param,
1734  const char* name, const char* description="");
1740  void add(SGMatrix<SGSparseVector<int32_t> >* param, const char* name,
1741  const char* description="");
1747  void add(SGMatrix<SGSparseVector<uint32_t> >* param,const char* name,
1748  const char* description="");
1754  void add(SGMatrix<SGSparseVector<int64_t> >* param, const char* name,
1755  const char* description="");
1761  void add(SGMatrix<SGSparseVector<uint64_t> >* param,
1762  const char* name, const char* description="");
1768  void add(SGMatrix<SGSparseVector<float32_t> >* param,
1769  const char* name, const char* description="");
1775  void add(SGMatrix<SGSparseVector<float64_t> >* param,
1776  const char* name, const char* description="");
1782  void add(SGMatrix<SGSparseVector<floatmax_t> >* param,
1783  const char* name, const char* description="");
1784 
1785 protected:
1786 
1789 
1796  virtual void add_type(const TSGDataType* type, void* param,
1797  const char* name,
1798  const char* description);
1799 };
1800 }
1801 #endif //__PARAMETER_H__

SHOGUN Machine Learning Toolbox - Documentation