principal_components_layer.h
1 // OpenNN: Open Neural Networks Library
2 // www.opennn.net
3 //
4 // P R I N C I P A L C O M P O N E N T S L A Y E R C L A S S H E A D E R
5 //
6 // Pablo Martin
7 // Artificial Intelligence Techniques SL
8 // artelnics@artelnics.com
9 
10 
11 
12 #ifndef PrincipalComponentsLayer_H
13 #define PrincipalComponentsLayer_H
14 
15 // System includes
16 
17 #include <cmath>
18 #include <cstdlib>
19 #include <fstream>
20 #include <iostream>
21 #include <string>
22 #include <sstream>
23 
24 // OpenNN includes
25 
26 #include "vector.h"
27 #include "matrix.h"
28 #include "metrics.h"
29 #include "layer.h"
30 
31 
32 
33 #include "tinyxml2.h"
34 
35 namespace OpenNN
36 {
37 
39 
42 
44 {
45 
46 public:
47 
48  // DEFAULT CONSTRUCTOR
49 
50  explicit PrincipalComponentsLayer();
51 
52  // INPUTS AND PRINCIPAL COMPONENTS NUMBER CONSTRUCTOR
53 
54  explicit PrincipalComponentsLayer(const size_t&, const size_t&);
55 
56  // COPY CONSTRUCTOR
57 
59 
60 
61 
62  virtual ~PrincipalComponentsLayer();
63 
64  // Enumerations
65 
67 
68  enum PrincipalComponentsMethod{NoPrincipalComponents, PrincipalComponents};
69 
70  // Principal components state methods
71 
73 
74  string write_principal_components_method() const;
76 
77  // Get methods
78 
80  Vector<double> get_means() const;
81 
83 
84  size_t get_inputs_number() const;
85  size_t get_principal_components_number() const;
86  size_t get_neurons_number() const;
87 
88 
89  // Inputs principal components function
90 
91  // Display messages
92 
93  const bool& get_display() const;
94 
95  // Set methods
96 
97  void set();
98  void set(const size_t&, const size_t&);
99  void set(const PrincipalComponentsLayer&);
100 
101  void set_inputs_number(const size_t&);
102  void set_principal_components_number(const size_t&);
103 
104  void set_principal_component(const size_t&, const Vector<double>&);
106 
107  void set_means(const Vector<double>&);
108  void set_means(const size_t&, const double&);
109 
111 
112  virtual void set_default();
113 
115  void set_principal_components_method(const string&);
116 
117  // Display messages
118 
119  void set_display(const bool&);
120 
121  // Check methods
122 
123  // Inputs principal components function
124 
126 
127  // Expression methods
128 
129  string write_expression(const Vector<string>&, const Vector<string>&) const;
130 
133 
134  // Serialization methods
135 
136  tinyxml2::XMLDocument* to_XML() const;
137  virtual void from_XML(const tinyxml2::XMLDocument&);
138 
139  void write_XML(tinyxml2::XMLPrinter&) const;
140 
141 
142 protected:
143 
144  // MEMBERS
145 
147 
149 
151 
153 
155 
157 
160 
162 
164 
166 
168 
170 
172 
173  bool display;
174 };
175 
176 }
177 
178 #endif
179 
180 // OpenNN: Open Neural Networks Library.
181 // Copyright(C) 2005-2019 Artificial Intelligence Techniques, SL.
182 //
183 // This library is free software; you can redistribute it and/or
184 // modify it under the terms of the GNU Lesser General Public
185 // License as published by the Free Software Foundation; either
186 // version 2.1 of the License, or any later version.
187 //
188 // This library is distributed in the hope that it will be useful,
189 // but WITHOUT ANY WARRANTY; without even the implied warranty of
190 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
191 // Lesser General Public License for more details.
192 
193 // You should have received a copy of the GNU Lesser General Public
194 // License along with this library; if not, write to the Free Software
195 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
OpenNN::PrincipalComponentsLayer::~PrincipalComponentsLayer
virtual ~PrincipalComponentsLayer()
Destructor.
Definition: principal_components_layer.cpp:45
OpenNN::PrincipalComponentsLayer::set_inputs_number
void set_inputs_number(const size_t &)
Definition: principal_components_layer.cpp:405
OpenNN::PrincipalComponentsLayer
This class represents the layer of principal component analysis.
Definition: principal_components_layer.h:43
OpenNN::PrincipalComponentsLayer::write_no_principal_components_expression
string write_no_principal_components_expression(const Vector< string > &, const Vector< string > &) const
Returns a string with the expression of the principal components process when none method is used.
Definition: principal_components_layer.cpp:273
OpenNN::PrincipalComponentsLayer::set_means
void set_means(const Vector< double > &)
Definition: principal_components_layer.cpp:439
OpenNN::PrincipalComponentsLayer::principal_components
Matrix< double > principal_components
Definition: principal_components_layer.h:161
OpenNN::PrincipalComponentsLayer::set_principal_components_method
void set_principal_components_method(const PrincipalComponentsMethod &)
Definition: principal_components_layer.cpp:486
OpenNN::PrincipalComponentsLayer::set
void set()
Sets the principal components layer to be empty.
Definition: principal_components_layer.cpp:333
OpenNN::PrincipalComponentsLayer::get_display
const bool & get_display() const
Definition: principal_components_layer.cpp:323
OpenNN::PrincipalComponentsLayer::write_expression
string write_expression(const Vector< string > &, const Vector< string > &) const
Returns a string with the expression of the principal components process.
Definition: principal_components_layer.cpp:241
OpenNN::PrincipalComponentsLayer::principal_components_number
size_t principal_components_number
Principal components number.
Definition: principal_components_layer.h:152
OpenNN::PrincipalComponentsLayer::write_principal_components_method
string write_principal_components_method() const
Returns a string with the name of the method used for principal components layer.
Definition: principal_components_layer.cpp:60
tinyxml2::XMLDocument
Definition: tinyxml2.h:1649
OpenNN::PrincipalComponentsLayer::explained_variance
Vector< double > explained_variance
Explained variances for every of the principal components.
Definition: principal_components_layer.h:165
OpenNN::PrincipalComponentsLayer::display
bool display
Display warning messages to screen.
Definition: principal_components_layer.h:173
OpenNN::Matrix< double >
OpenNN::PrincipalComponentsLayer::means
Vector< double > means
Means of the input variables.
Definition: principal_components_layer.h:156
OpenNN::PrincipalComponentsLayer::get_principal_components_method
const PrincipalComponentsMethod & get_principal_components_method() const
Returns the method used for principal components layer.
Definition: principal_components_layer.cpp:52
OpenNN::PrincipalComponentsLayer::get_inputs_number
size_t get_inputs_number() const
Returns the number of inputs to the layer.
Definition: principal_components_layer.cpp:143
OpenNN::Tensor< double >
OpenNN::Layer
This abstract class represents the concept of layer of neurons in OpenNN.
Definition: layer.h:38
OpenNN::PrincipalComponentsLayer::principal_components_method
PrincipalComponentsMethod principal_components_method
Principal components layer method.
Definition: principal_components_layer.h:169
OpenNN::PrincipalComponentsLayer::write_XML
void write_XML(tinyxml2::XMLPrinter &) const
Definition: principal_components_layer.cpp:608
OpenNN::PrincipalComponentsLayer::write_principal_components_method_text
string write_principal_components_method_text() const
Definition: principal_components_layer.cpp:86
OpenNN::PrincipalComponentsLayer::set_display
void set_display(const bool &)
Definition: principal_components_layer.cpp:525
OpenNN::PrincipalComponentsLayer::to_XML
tinyxml2::XMLDocument * to_XML() const
Definition: principal_components_layer.cpp:536
OpenNN::PrincipalComponentsLayer::PrincipalComponentsLayer
PrincipalComponentsLayer()
Definition: principal_components_layer.cpp:17
OpenNN::PrincipalComponentsLayer::set_principal_components_number
void set_principal_components_number(const size_t &)
Definition: principal_components_layer.cpp:416
tinyxml2::XMLPrinter
Definition: tinyxml2.h:2150
OpenNN::PrincipalComponentsLayer::set_principal_component
void set_principal_component(const size_t &, const Vector< double > &)
Definition: principal_components_layer.cpp:428
OpenNN::PrincipalComponentsLayer::get_explained_variance
Vector< double > get_explained_variance() const
Returns a vector containing the explained variance of every of the principal components.
Definition: principal_components_layer.cpp:133
OpenNN::PrincipalComponentsLayer::set_principal_components
void set_principal_components(const Matrix< double > &)
Definition: principal_components_layer.cpp:390
OpenNN::PrincipalComponentsLayer::calculate_outputs
Tensor< double > calculate_outputs(const Tensor< double > &)
Definition: principal_components_layer.cpp:166
OpenNN::PrincipalComponentsLayer::from_XML
virtual void from_XML(const tinyxml2::XMLDocument &)
Definition: principal_components_layer.cpp:706
OpenNN::PrincipalComponentsLayer::set_default
virtual void set_default()
Definition: principal_components_layer.cpp:475
OpenNN::PrincipalComponentsLayer::get_principal_components_number
size_t get_principal_components_number() const
Returns the number of principal components.
Definition: principal_components_layer.cpp:151
OpenNN::PrincipalComponentsLayer::get_means
Vector< double > get_means() const
Returns a vector containing the means of every input variable in the data set.
Definition: principal_components_layer.cpp:123
OpenNN::Vector< double >
OpenNN::PrincipalComponentsLayer::get_principal_components
Matrix< double > get_principal_components() const
Returns a matrix containing the principal components.
Definition: principal_components_layer.cpp:113
OpenNN::PrincipalComponentsLayer::set_explained_variance
void set_explained_variance(const Vector< double > &)
Definition: principal_components_layer.cpp:462
OpenNN::PrincipalComponentsLayer::write_principal_components_expression
string write_principal_components_expression(const Vector< string > &, const Vector< string > &) const
Definition: principal_components_layer.cpp:288
OpenNN::PrincipalComponentsLayer::PrincipalComponentsMethod
PrincipalComponentsMethod
Enumeration of available methods for apply the principal components layer.
Definition: principal_components_layer.h:68
OpenNN::PrincipalComponentsLayer::inputs_number
size_t inputs_number
Inputs number.
Definition: principal_components_layer.h:148