OpenNN  2.2
Open Neural Networks Library
missing_values.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* M I S S I N G V A L U 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 __MISSINGVALUES_H__
15 #define __MISSINGVALUES_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 // TinyXml includes
36 
37 #include "../tinyxml2/tinyxml2.h"
38 
39 
40 namespace OpenNN
41 {
42 
46 
48 {
49 
50 public:
51 
52  // DEFAULT CONSTRUCTOR
53 
54  explicit MissingValues(void);
55 
56  // MISSING VALUES NUMBER CONSTRUCTOR
57 
58  explicit MissingValues(const size_t&, const size_t&);
59 
60  // XML CONSTRUCTOR
61 
62  explicit MissingValues(const tinyxml2::XMLDocument&);
63 
64  // COPY CONSTRUCTOR
65 
67 
68 
69  // DESTRUCTOR
70 
71  virtual ~MissingValues(void);
72 
73  // ASSIGNMENT OPERATOR
74 
76 
77  // EQUAL TO OPERATOR
78 
79  bool operator == (const MissingValues&) const;
80 
81 
82  // ENUMERATIONS
83 
85 
86  enum ScrubbingMethod{Unuse, Mean, NoScrubbing};
87 
88  // STRUCTURES
89 
94 
95  struct Item
96  {
98 
99  Item(void)
100  {
101  }
102 
104 
105  Item(const size_t& new_instance_index, const size_t& new_variable_index)
106  {
107  //std::cout << instances_number;
108 
109 
110  instance_index = new_instance_index;
111  variable_index = new_variable_index;
112  }
113 
115 
116  virtual ~Item(void)
117  {
118  }
119 
122 
123  bool operator == (const Item& other_item) const
124  {
125  if(other_item.instance_index == instance_index && other_item.variable_index == variable_index)
126  {
127  return(true);
128  }
129  else
130  {
131  return(false);
132  }
133  }
134 
136 
138 
140 
142  };
143 
144 
145  // METHODS
146 
147  size_t get_instances_number(void) const;
148 
149  size_t get_variables_number(void) const;
150 
151 
153 
154  inline size_t get_missing_values_number(void) const
155  {
156  return(items.size());
157  }
158 
160 
161  const Vector<Item>& get_items(void) const;
162  const Item& get_item(const size_t&) const;
163 
165 
166  std::string write_scrubbing_method(void) const;
167  std::string write_scrubbing_method_text(void) const;
168 
169  const bool& get_display(void) const;
170 
171  // Set methods
172 
173  void set(void);
174  void set(const size_t&, const size_t&);
175  void set(const tinyxml2::XMLDocument&);
176 
177  void set_instances_number(const size_t&);
178  void set_variables_number(const size_t&);
179 
180  void set_default(void);
181 
182  void set_missing_values_number(const size_t&);
183 
185  void set_scrubbing_method(const std::string&);
186 
187  // Missing values methods
188 
189  void set_display(const bool&);
190 
191  void set_items(const Vector<Item>&);
192  void set_item(const size_t&, const size_t&, const size_t&);
193 
194  void append(const size_t&, const size_t&);
195 
196  bool has_missing_values(void) const;
197  bool has_missing_values(const size_t&) const;
198  bool has_missing_values(const size_t&, const Vector<size_t>&) const;
199 
200  bool is_missing_value(const size_t&, const size_t&) const;
201 
203 
204  size_t count_missing_instances(void) const;
205 
207 
209 
210  void convert_time_series(const size_t&);
211  void convert_autoassociation(void);
212 
213  // Serialization methods
214 
215  std::string to_string(void) const;
216 
217  void print(void) const;
218 
219  tinyxml2::XMLDocument* to_XML(void) const;
220  void from_XML(const tinyxml2::XMLDocument&);
221 
222 private:
223 
224  // MEMBERS
225 
227 
229 
231 
233 
235 
237 
239 
241 
243 
244  bool display;
245 };
246 
247 }
248 
249 #endif
250 
251 // OpenNN: Open Neural Networks Library.
252 // Copyright (c) 2005-2015 Roberto Lopez.
253 //
254 // This library is free software; you can redistribute it and/or
255 // modify it under the terms of the GNU Lesser General Public
256 // License as published by the Free Software Foundation; either
257 // version 2.1 of the License, or any later version.
258 //
259 // This library is distributed in the hope that it will be useful,
260 // but WITHOUT ANY WARRANTY; without even the implied warranty of
261 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
262 // Lesser General Public License for more details.
263 
264 // You should have received a copy of the GNU Lesser General Public
265 // License along with this library; if not, write to the Free Software
266 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
std::string write_scrubbing_method_text(void) const
Returns a string with the name of the method used for scrubbing, as paragaph text.
void convert_time_series(const size_t &)
ScrubbingMethod get_scrubbing_method(void) const
Returns the method to be used for dealing with the missing values.
bool display
Display messages to screen.
MissingValues & operator=(const MissingValues &)
virtual ~Item(void)
Destructor.
ScrubbingMethod
Enumeration of available activation functions for the perceptron neuron model.
Item(const size_t &new_instance_index, const size_t &new_variable_index)
Indices constructor.
void set_instances_number(const size_t &)
Sets the number of data set instances in this object.
void set_item(const size_t &, const size_t &, const size_t &)
Sets the indices.
Vector< size_t > arrange_missing_instances(void) const
Returns a vector with the indices of those instances with missing values.
bool operator==(const MissingValues &) const
const Vector< Item > & get_items(void) const
Returns a constant reference to the vector of missing value items.
void convert_autoassociation(void)
bool has_missing_values(void) const
size_t variables_number
Number of variables.
tinyxml2::XMLDocument * to_XML(void) const
Item(void)
Default constructor.
Vector< size_t > get_missing_values_numbers(void) const
size_t variable_index
Column index for missing value.
Vector< Item > items
Missing values.
void print(void) const
Prints to the screen information about the missing values object.
Vector< size_t > arrange_missing_variables(void) const
Returns a vector with the indices of those variables with missing values.
void set_display(const bool &)
void append(const size_t &, const size_t &)
void set_items(const Vector< Item > &)
Sets a new vector of missing value items.
const Item & get_item(const size_t &) const
const bool & get_display(void) const
size_t instance_index
Row index for missing value.
void set_missing_values_number(const size_t &)
void set(void)
Sets a missing values object with zero instances, variables and missing values.
bool is_missing_value(const size_t &, const size_t &) const
ScrubbingMethod scrubbing_method
Method for handling missing values.
std::string to_string(void) const
Returns a string representation of the current MissingValues object.
size_t get_instances_number(void) const
Returns the number of instances in the data set.
void set_variables_number(const size_t &)
Sets the number of data set variables in this object.
void from_XML(const tinyxml2::XMLDocument &)
virtual ~MissingValues(void)
Destructor.
size_t count_missing_instances(void) const
Returns the number of instances with missing values.
size_t get_variables_number(void) const
Returns the number of variables in the data set.
std::string write_scrubbing_method(void) const
Returns a string with the name of the method used for scrubbing.
size_t instances_number
Number of instances.
void set_scrubbing_method(const ScrubbingMethod &)
size_t get_missing_values_number(void) const
Returns the number of missing values in the data set.
bool operator==(const Item &other_item) const
Vector< Vector< size_t > > arrange_missing_indices(void) const