OpenNN  2.2
Open Neural Networks Library
perceptron.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 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 __PERCEPTRON_H__
15 #define __PERCEPTRON_H__
16 
17 // System includes
18 
19 #include <iostream>
20 #include <sstream>
21 #include <cstdlib>
22 #include <ctime>
23 
24 // OpenNN includes
25 
26 #include "vector.h"
27 #include "matrix.h"
28 
29 namespace OpenNN
30 {
31 
35 
37 {
38 public:
39 
40  // DEFAULT CONSTRUCTOR
41 
42  explicit Perceptron(void);
43 
44  // INPUTS NUMBER CONSTRUCTOR
45 
46  explicit Perceptron(const size_t&);
47 
48  // INPUTS NUMBER AND INITIALIZATION CONSTRUCTOR
49 
50  explicit Perceptron(const size_t&, const double&);
51 
52  // COPY CONSTRUCTOR
53 
54  Perceptron(const Perceptron&);
55 
56  // DESTRUCTOR
57 
58  virtual ~Perceptron(void);
59 
60  // ASSIGNMENT OPERATOR
61 
63 
64  // EQUAL TO OPERATOR
65 
66  bool operator == (const Perceptron&) const;
67 
68  // ENUMERATIONS
69 
71 
72  enum ActivationFunction{Threshold, SymmetricThreshold, Logistic, HyperbolicTangent, Linear};
73 
74  // METHODS
75 
76  // Get methods
77 
78  size_t get_inputs_number(void) const;
79 
81  std::string write_activation_function(void) const;
82 
83  const double& get_bias(void) const;
84  const Vector<double>& arrange_synaptic_weights(void) const;
85  const double& get_synaptic_weight(const size_t&) const;
86 
87  size_t count_parameters_number(void) const;
89 
90  const bool& get_display(void) const;
91 
92  // Set methods
93 
94  void set(void);
95  void set(const size_t&);
96  void set(const size_t&, const double&);
97  void set(const Perceptron&);
98 
99  void set_inputs_number(const size_t&);
100 
102  void set_activation_function(const std::string&);
103 
104  void set_bias(const double&);
106  void set_synaptic_weight(const size_t&, const double&);
107 
108  void set_parameters(const Vector<double>&);
109 
110  void set_display(const bool&);
111 
112  // Growing and pruning
113 
114  void grow_input(void);
115 
116  void prune_input(const size_t&);
117 
118  // Initialization methods
119 
120  void initialize_bias(const double&);
121  void initialize_bias_uniform(const double&, const double&);
122  void initialize_bias_normal(const double&, const double&);
123 
124  void initialize_synaptic_weights(const double&);
125  void initialize_synaptic_weights_uniform(const double&, const double&);
126  void initialize_synaptic_weights_normal(const double&, const double&);
127 
128  void initialize_parameters(const double&);
129 
130  // Combination methods
131 
132  double calculate_combination(const Vector<double>&) const;
135 
136  double calculate_combination(const Vector<double>&, const Vector<double>&) const;
139 
140  // Activation methods
141 
142  double calculate_activation(const double&) const ;
143  double calculate_activation_derivative(const double&) const ;
144  double calculate_activation_second_derivative(const double&) const ;
145 
146  // Output methods
147 
148  double calculate_output(const Vector<double>&) const;
151 
152  double calculate_output(const Vector<double>&, const Vector<double>&) const;
155 
156  // Expression methods
157 
158  std::string write_expression(const Vector<std::string>&, const std::string&) const;
159 
160 private:
161 
162  // MEMBERS
163 
165 
166  double bias;
167 
169 
171 
173 
175 
177 
178  bool display;
179 
180 };
181 
182 }
183 
184 #endif
185 
186 
187 // OpenNN: Open Neural Networks Library.
188 // Copyright (c) 2005-2015 Roberto Lopez.
189 //
190 // This library is free software; you can redistribute it and/or
191 // modify it under the terms of the GNU Lesser General Public
192 // License as published by the Free Software Foundation; either
193 // version 2.1 of the License, or any later version.
194 //
195 // This library is distributed in the hope that it will be useful,
196 // but WITHOUT ANY WARRANTY; without even the implied warranty of
197 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
198 // Lesser General Public License for more details.
199 
200 // You should have received a copy of the GNU Lesser General Public
201 // License along with this library; if not, write to the Free Software
202 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
203 
Vector< double > synaptic_weights
Synaptic weights vector.
Definition: perceptron.h:170
void set_display(const bool &)
Definition: perceptron.cpp:467
void prune_input(const size_t &)
double bias
Bias value.
Definition: perceptron.h:166
void initialize_bias_uniform(const double &, const double &)
Definition: perceptron.cpp:578
void initialize_bias_normal(const double &, const double &)
Definition: perceptron.cpp:630
double calculate_activation(const double &) const
Definition: perceptron.cpp:791
void initialize_synaptic_weights(const double &)
Definition: perceptron.cpp:606
const double & get_synaptic_weight(const size_t &) const
Definition: perceptron.cpp:223
Matrix< double > calculate_Hessian(const Vector< double > &) const
size_t count_parameters_number(void) const
Returns the number of parameters (bias and synaptic weights) in the perceptron.
Definition: perceptron.cpp:493
ActivationFunction
Enumeration of available activation functions for the perceptron neuron model.
Definition: perceptron.h:72
void set_synaptic_weights(const Vector< double > &)
Definition: perceptron.cpp:400
const ActivationFunction & get_activation_function(void) const
Returns the activation function of the neuron.
Definition: perceptron.cpp:129
bool display
Display messages to screen.
Definition: perceptron.h:178
void set_activation_function(const ActivationFunction &)
Definition: perceptron.cpp:337
Perceptron & operator=(const Perceptron &)
Definition: perceptron.cpp:81
std::string write_activation_function(void) const
Returns a string with the name of the activation function of the neuron.
Definition: perceptron.cpp:139
Vector< double > arrange_parameters(void) const
Returns the parameters (bias and synaptic weights) of the perceptron.
Definition: perceptron.cpp:505
void set_bias(const double &)
Definition: perceptron.cpp:389
void set_inputs_number(const size_t &)
Definition: perceptron.cpp:480
void initialize_synaptic_weights_uniform(const double &, const double &)
Definition: perceptron.cpp:618
double calculate_combination(const Vector< double > &) const
Definition: perceptron.cpp:683
Vector< double > calculate_combination_gradient(const Vector< double > &) const
Returns the partial derivatives of the combination with respect to the inputs.
ActivationFunction activation_function
Activation function variable.
Definition: perceptron.h:174
void set(void)
Sets the number of inputs to zero and the rest of members to their default values.
Definition: perceptron.cpp:265
bool operator==(const Perceptron &) const
Definition: perceptron.cpp:107
size_t get_inputs_number(void) const
Returns the number of inputs to the neuron.
Definition: perceptron.cpp:192
double calculate_output(const Vector< double > &) const
void initialize_synaptic_weights_normal(const double &, const double &)
Definition: perceptron.cpp:659
Matrix< double > calculate_combination_Hessian(const Vector< double > &) const
This method retuns the second derivatives of the combination with respect to the inputs.
void grow_input(void)
virtual ~Perceptron(void)
Definition: perceptron.cpp:70
std::string write_expression(const Vector< std::string > &, const std::string &) const
const bool & get_display(void) const
Definition: perceptron.cpp:255
void initialize_bias(const double &)
Definition: perceptron.cpp:566
void initialize_parameters(const double &)
Definition: perceptron.cpp:670
double calculate_activation_derivative(const double &) const
Definition: perceptron.cpp:860
const Vector< double > & arrange_synaptic_weights(void) const
Returns the synaptic weight values of the neuron.
Definition: perceptron.cpp:212
Vector< double > calculate_gradient(const Vector< double > &) const
const double & get_bias(void) const
Returns the bias value of the neuron.
Definition: perceptron.cpp:202
double calculate_activation_second_derivative(const double &) const
Definition: perceptron.cpp:945
void set_synaptic_weight(const size_t &, const double &)
Definition: perceptron.cpp:433
void set_parameters(const Vector< double > &)
Definition: perceptron.cpp:529