OpenNN  2.2
Open Neural Networks Library
variables.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* V A R I A B L E S C L A S S H E A D E R */
7 /* */
8 /* Roberto Lopez */
9 /* Artelnics - Making intelligent use of data */
11 /* */
12 /****************************************************************************************************************/
13 
14 #ifndef __VARIABLES_H__
15 #define __VARIABLES_H__
16 
17 // System includes
18 
19 #include <iostream>
20 #include <fstream>
21 #include <string>
22 #include <sstream>
23 #include <cmath>
24 #include <algorithm>
25 #include <cstdlib>
26 #include <stdexcept>
27 #include <ctime>
28 #include <exception>
29 
30 // OpenNN includes
31 
32 #include "vector.h"
33 #include "matrix.h"
34 
35 #include<limits>
36 #include<climits>
37 
38 
39 // TinyXml includes
40 
41 #include "../tinyxml2/tinyxml2.h"
42 
43 namespace OpenNN
44 {
45 
49 
50 class Variables
51 {
52 
53 public:
54 
55  // DEFAULT CONSTRUCTOR
56 
57  explicit Variables(void);
58 
59  // VARIABLES NUMBER CONSTRUCTOR
60 
61  explicit Variables(const size_t&);
62 
63  // INPUT AND TARGET VARIABLES NUMBER
64 
65  explicit Variables(const size_t&, const size_t&);
66 
67  // XML CONSTRUCTOR
68 
69  explicit Variables(const tinyxml2::XMLDocument&);
70 
71  // COPY CONSTRUCTOR
72 
73  Variables(const Variables&);
74 
75  // DESTRUCTOR
76 
77  virtual ~Variables(void);
78 
79  // ASSIGNMENT OPERATOR
80 
82 
83  // EQUAL TO OPERATOR
84 
85  bool operator == (const Variables&) const;
86 
87  // ENUMERATIONS
88 
90 
91  enum Use{Input, Target, Unused};
92 
93  // STRUCTURES
94 
98 
99  struct Item
100  {
102 
103  std::string name;
104 
106 
107  std::string units;
108 
110 
111  std::string description;
112 
114 
116  };
117 
118  // METHODS
119 
120  const Vector<Item>& get_items(void) const;
121 
122  const Item& get_item(const size_t&) const;
123 
125 
126  inline size_t get_variables_number(void) const
127  {
128  return(items.size());
129  }
130 
131  bool empty(void) const;
132 
133  size_t count_used_variables_number(void) const;
134  size_t count_unused_variables_number(void) const;
135  size_t count_inputs_number(void) const;
136  size_t count_targets_number(void) const;
137 
138  Vector<size_t> count_uses(void) const;
139 
140  // Variables methods
141 
142  Vector<Use> arrange_uses(void) const;
143  Vector<std::string> write_uses(void) const;
144 
145  const Use& get_use(const size_t&) const;
146  std::string write_use(const size_t&) const;
147 
148  bool is_used(const size_t&) const;
149 
152 
153  // Information methods
154 
156  const std::string& get_name(const size_t&) const;
157 
158  bool has_names(void) const;
159 
161  const std::string& get_unit(const size_t&) const;
162 
164  const std::string& get_description(const size_t&) const;
165 
166  const bool& get_display(void) const;
167 
168  // Set methods
169 
170  void set(void);
171  void set(const size_t&);
172  void set(const size_t&, const size_t&);
173  void set(const tinyxml2::XMLDocument&);
174 
175  void set_default(void);
176 
177  // Data methods
178 
179  void set_variables_number(const size_t&);
180 
181  // Variables methods
182 
183  void set_items(const Vector<Item>&);
184 
185  void set_uses(const Vector<Use>&);
186  void set_uses(const Vector<std::string>&);
187 
188  void set_use(const size_t&, const Use&);
189  void set_use(const size_t&, const std::string&);
190 
191  void set_input(void);
192  void set_target(void);
193 
194  void set_default_uses(void);
195 
196  // Information methods
197 
198  void set_names(const Vector<std::string>&);
199  void set_name(const size_t&, const std::string&);
200 
201  void set_units(const Vector<std::string>&);
202  void set_units(const size_t&, const std::string&);
203 
205  void set_description(const size_t&, const std::string&);
206 
208 
209  void set_display(const bool&);
210 
212 
215 
218 
221 
224 
225  void convert_time_series(const size_t&);
226  void convert_autoassociation(void);
227 
228  // Serialization methods
229 
230  std::string to_string(void) const;
231 
232  tinyxml2::XMLDocument* to_XML(void) const;
233  void from_XML(const tinyxml2::XMLDocument&);
234 
235 private:
236 
237  static std::string unsigned_to_string(const size_t&);
238  static std::string prepend(const std::string&, const std::string&);
239 
240 
241  // MEMBERS
242 
245 
247 
249 
250  bool display;
251 };
252 
253 }
254 
255 #endif
256 
257 // OpenNN: Open Neural Networks Library.
258 // Copyright (c) 2005-2015 Roberto Lopez.
259 //
260 // This library is free software; you can redistribute it and/or
261 // modify it under the terms of the GNU Lesser General Public
262 // License as published by the Free Software Foundation; either
263 // version 2.1 of the License, or any later version.
264 //
265 // This library is distributed in the hope that it will be useful,
266 // but WITHOUT ANY WARRANTY; without even the implied warranty of
267 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
268 // Lesser General Public License for more details.
269 
270 // You should have received a copy of the GNU Lesser General Public
271 // License along with this library; if not, write to the Free Software
272 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
virtual ~Variables(void)
Destructor.
Definition: variables.cpp:99
const std::string & get_description(const size_t &) const
Definition: variables.cpp:784
Use
This enumeration represents the possible uses of a variable (input, target or unused).
Definition: variables.h:91
std::string units
Units of a variable.
Definition: variables.h:107
void set_name(const size_t &, const std::string &)
Definition: variables.cpp:1258
Vector< std::string > arrange_inputs_name(void) const
Returns the names of the input variables in the data set.
Definition: variables.cpp:615
const std::string & get_name(const size_t &) const
Definition: variables.cpp:565
Vector< Item > items
Definition: variables.h:246
void set_target(void)
Sets all the variables in the data set as target variables.
Definition: variables.cpp:1175
Vector< std::string > arrange_units(void) const
Returns the units of all the variables in the data set.
Definition: variables.cpp:665
void convert_time_series(const size_t &)
Definition: variables.cpp:1547
Vector< std::string > arrange_inputs_units(void) const
Returns the units of the input variables in the data set.
Definition: variables.cpp:714
bool empty(void) const
Returns true if the number of variables is zero, and false otherwise.
Definition: variables.cpp:196
void set_descriptions(const Vector< std::string > &)
Definition: variables.cpp:1361
static std::string unsigned_to_string(const size_t &)
Returns the string representation of number of type size_t.
Definition: variables.cpp:1898
Matrix< std::string > arrange_targets_information(void) const
Definition: variables.cpp:892
Vector< size_t > arrange_targets_indices(void) const
Returns the indices of the target variables.
Definition: variables.cpp:519
static std::string prepend(const std::string &, const std::string &)
Prepends the string pre to the beginning of the string str and returns the whole string.
Definition: variables.cpp:1912
const bool & get_display(void) const
Definition: variables.cpp:920
Matrix< std::string > arrange_information(void) const
Definition: variables.cpp:471
void set_variables_number(const size_t &)
Definition: variables.cpp:1616
void set_display(const bool &)
Definition: variables.cpp:1535
void set_default_uses(void)
Definition: variables.cpp:1194
void set_items(const Vector< Item > &)
Definition: variables.cpp:1011
void set_input(void)
Sets all the variables in the data set as input variables.
Definition: variables.cpp:1160
Vector< std::string > arrange_targets_units(void) const
Returns the units of the target variables in the data set.
Definition: variables.cpp:739
void set_uses(const Vector< Use > &)
Definition: variables.cpp:1023
tinyxml2::XMLDocument * to_XML(void) const
Definition: variables.cpp:1664
void set(void)
Sets a variables object with zero variables.
Definition: variables.cpp:930
size_t count_used_variables_number(void) const
Returns the number of variables which are either input or target.
Definition: variables.cpp:213
bool has_names(void) const
Returns true if all the variables have been named, and false otherwise.
Definition: variables.cpp:594
Vector< std::string > arrange_targets_description(void) const
Returns the description of the target variables in the data set.
Definition: variables.cpp:838
void from_XML(const tinyxml2::XMLDocument &)
Definition: variables.cpp:1754
bool display
Display messages to screen.
Definition: variables.h:250
void set_description(const size_t &, const std::string &)
Definition: variables.cpp:1398
size_t count_inputs_number(void) const
Returns the number of input variables of the data set.
Definition: variables.cpp:249
const std::string & get_unit(const size_t &) const
Definition: variables.cpp:685
Matrix< std::string > arrange_inputs_information(void) const
Definition: variables.cpp:864
void convert_autoassociation(void)
Definition: variables.cpp:1589
const Use & get_use(const size_t &) const
Definition: variables.cpp:388
Vector< std::string > arrange_names(void) const
Returns the names of all the variables in the data set.
Definition: variables.cpp:545
void set_use(const size_t &, const Use &)
Definition: variables.cpp:1078
Use use
Use of a variable (none, input or target).
Definition: variables.h:115
Vector< size_t > count_uses(void) const
Definition: variables.cpp:295
size_t count_targets_number(void) const
Returns the number of target variables of the data set.
Definition: variables.cpp:271
void set_units(const Vector< std::string > &)
Definition: variables.cpp:1291
Vector< std::string > arrange_targets_name(void) const
Returns the names of the target variables in the data set.
Definition: variables.cpp:640
Vector< std::string > write_uses(void) const
Definition: variables.cpp:347
std::string to_string(void) const
Returns a string representation of the current variables object.
Definition: variables.cpp:1627
void set_names(const Vector< std::string > &)
Definition: variables.cpp:1221
const Vector< Item > & get_items(void) const
Returns the vector Item structures in the variables object.
Definition: variables.cpp:156
bool is_used(const size_t &) const
Definition: variables.cpp:431
Vector< Use > arrange_uses(void) const
Definition: variables.cpp:326
std::string description
Description of a variable.
Definition: variables.h:111
size_t get_variables_number(void) const
Returns the total number of variables in the data set.
Definition: variables.h:126
size_t count_unused_variables_number(void) const
Returns the number of variables which will neither be used as input nor as target.
Definition: variables.cpp:227
Variables & operator=(const Variables &)
Definition: variables.cpp:110
bool operator==(const Variables &) const
Definition: variables.cpp:136
void set_default(void)
Definition: variables.cpp:1000
Vector< std::string > arrange_descriptions(void) const
Returns the description of all the variables in the data set.
Definition: variables.cpp:764
std::string write_use(const size_t &) const
Definition: variables.cpp:399
std::string name
Name of a variable.
Definition: variables.h:103
const Item & get_item(const size_t &) const
Definition: variables.cpp:167
Vector< size_t > arrange_inputs_indices(void) const
Returns the indices of the input variables.
Definition: variables.cpp:493
Vector< std::string > arrange_inputs_description(void) const
Returns the description of the input variables in the data set.
Definition: variables.cpp:813