OpenNN  2.2
Open Neural Networks Library
perceptron_layer.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* P E R C E P T R O N L A Y E R 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 __PERCEPTRONLAYER_H__
15 #define __PERCEPTRONLAYER_H__
16 
17 // System includes
18 
19 #include <cmath>
20 #include <cstdlib>
21 #include <fstream>
22 #include <iostream>
23 #include <string>
24 #include <sstream>
25 
26 // OpenNN includes
27 
28 #include "perceptron.h"
29 
30 #include "vector.h"
31 #include "matrix.h"
32 
33 namespace OpenNN
34 {
35 
38 
40 {
41 
42 public:
43 
44  // DEFAULT CONSTRUCTOR
45 
46  explicit PerceptronLayer(void);
47 
48  // ARCHITECTURE CONSTRUCTOR
49 
50  explicit PerceptronLayer(const size_t&, const size_t&);
51 
52  // COPY CONSTRUCTOR
53 
55 
56  // DESTRUCTOR
57 
58  virtual ~PerceptronLayer(void);
59 
60  // ASSIGNMENT OPERATOR
61 
63 
64  // EQUAL TO OPERATOR
65 
66  bool operator == (const PerceptronLayer&) const;
67 
68  // GET METHODS
69 
70  bool is_empty(void) const;
71 
72  const Vector<Perceptron>& get_perceptrons(void) const;
73  const Perceptron& get_perceptron(const size_t&) const;
74 
75  size_t get_inputs_number(void) const;
76  size_t get_perceptrons_number(void) const;
77 
78  // PerceptronLayer parameters
79 
80  Vector<double> arrange_biases(void) const;
82 
83  size_t count_parameters_number(void) const;
85 
86  size_t count_perceptron_parameters_number(void) const;
88 
90 
91  // Activation functions
92 
94 
95  std::string write_activation_function(void) const;
96 
97  // Display messages
98 
99  const bool& get_display(void) const;
100 
101  // SET METHODS
102 
103  void set(void);
104  void set(const Vector<Perceptron>&);
105  void set(const size_t&, const size_t&);
106  void set(const PerceptronLayer&);
107 
108  void set_default(void);
109 
110  // Architecture
111 
112  void set_inputs_number(const size_t&);
113  void set_perceptrons_number(const size_t&);
114 
115  void set_perceptrons(const Vector<Perceptron>&);
116  void set_perceptron(const size_t&, const Perceptron&);
117 
118  // PerceptronLayer parameters
119 
120  void set_biases(const Vector<double>&);
122 
123  void set_parameters(const Vector<double>&);
124 
125  // Activation functions
126 
128  void set_activation_function(const std::string&);
129 
130  // Display messages
131 
132  void set_display(const bool&);
133 
134  // Growing and pruning
135 
136  void grow_inputs(const size_t&);
137  void grow_perceptrons(const size_t&);
138 
139  void prune_input(const size_t&);
140  void prune_perceptron(const size_t&);
141 
142  // PerceptronLayer initialization methods
143 
144  void initialize_random(void);
145 
146  // Parameters initialization methods
147 
148  void initialize_biases(const double&);
149  void initialize_synaptic_weights(const double&);
150 
151  void initialize_parameters(const double&);
152 
153  void randomize_parameters_uniform(void);
154  void randomize_parameters_uniform(const double&, const double&);
157 
158  void randomize_parameters_normal(void);
159  void randomize_parameters_normal(const double&, const double&);
162 
163  // Parameters norm
164 
165  double calculate_parameters_norm(void) const;
166 
167  // Perceptron layer combinations
168 
172 
176 
177  // Perceptron layer activations
178 
182 
185 
186  // Perceptron layer outputs
187 
191 
195 
196  // Expression methods
197 
198  std::string write_expression(const Vector<std::string>&, const Vector<std::string>&) const;
199 
200  // Hinton diagram methods
201 
202  // Serialization methods
203 
204 
205 protected:
206 
207  // MEMBERS
208 
211 
213 
215 
216  bool display;
217 };
218 
219 }
220 
221 #endif
222 
223 
224 // OpenNN: Open Neural Networks Library.
225 // Copyright (c) 2005-2015 Roberto Lopez.
226 //
227 // This library is free software; you can redistribute it and/or
228 // modify it under the terms of the GNU Lesser General Public
229 // License as published by the Free Software Foundation; either
230 // version 2.1 of the License, or any later version.
231 //
232 // This library is distributed in the hope that it will be useful,
233 // but WITHOUT ANY WARRANTY; without even the implied warranty of
234 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
235 // Lesser General Public License for more details.
236 
237 // You should have received a copy of the GNU Lesser General Public
238 // License along with this library; if not, write to the Free Software
239 
240 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
241 
void set_synaptic_weights(const Matrix< double > &)
const bool & get_display(void) const
void set_inputs_number(const size_t &)
Vector< double > arrange_parameters(void) const
Vector< double > calculate_activations_derivatives(const Vector< double > &) const
void prune_perceptron(const size_t &)
PerceptronLayer & operator=(const PerceptronLayer &)
void set_biases(const Vector< double > &)
std::string write_activation_function(void) const
const Vector< Perceptron > & get_perceptrons(void) const
Returns a constant reference to the vector of perceptrons defining the layer.
size_t count_parameters_number(void) const
Returns the number of parameters (biases and synaptic weights) of the layer.
Matrix< double > calculate_combinations_Jacobian(const Vector< double > &) const
Vector< double > calculate_combinations(const Vector< double > &) const
size_t get_inputs_number(void) const
Returns the number of inputs to the layer.
void set_perceptron(const size_t &, const Perceptron &)
ActivationFunction
Enumeration of available activation functions for the perceptron neuron model.
Definition: perceptron.h:72
Vector< Matrix< double > > calculate_Hessian_form(const Vector< double > &) const
bool display
Display messages to screen.
const Perceptron::ActivationFunction & get_activation_function(void) const
Vector< Vector< double > > arrange_perceptrons_parameters(void) const
void set_display(const bool &)
Vector< double > calculate_outputs(const Vector< double > &) const
void initialize_synaptic_weights(const double &)
Vector< double > calculate_activations_second_derivatives(const Vector< double > &) const
void grow_inputs(const size_t &)
const Perceptron & get_perceptron(const size_t &) const
Vector< size_t > count_cumulative_parameters_number(void) const
void set_parameters(const Vector< double > &)
Vector< Matrix< double > > calculate_combinations_Hessian_form(const Vector< double > &) const
Matrix< double > arrange_activations_Jacobian(const Vector< double > &) const
Vector< Matrix< double > > arrange_activations_Hessian_form(const Vector< double > &) const
void initialize_biases(const double &)
std::string write_expression(const Vector< std::string > &, const Vector< std::string > &) const
double calculate_parameters_norm(void) const
Calculates the norm of a layer parameters vector.
size_t get_perceptrons_number(void) const
Returns the size of the perceptrons vector.
void set_perceptrons_number(const size_t &)
void prune_input(const size_t &)
bool operator==(const PerceptronLayer &) const
void grow_perceptrons(const size_t &)
bool is_empty(void) const
Returns true if the size of the layer is zero, and false otherwise.
size_t count_perceptron_parameters_number(void) const
Vector< Perceptron > perceptrons
Matrix< double > calculate_Jacobian(const Vector< double > &) const
void set_perceptrons(const Vector< Perceptron > &)
Vector< double > calculate_activations(const Vector< double > &) const
Matrix< double > arrange_synaptic_weights(void) const
Vector< double > arrange_biases(void) const
void set_activation_function(const Perceptron::ActivationFunction &)
void initialize_parameters(const double &)