SuperNN  1.0.0
neuron.hpp
1 /*
2  This file is part of SuperNN.
3 
4  SuperNN is free software: you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  SuperNN is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with SuperNN. If not, see <http://www.gnu.org/licenses/>.
16 
17  Copyright (C) 2010 - 2015 Lucas Hermann Negri
18 */
19 
20 #ifndef SUPERNN_NEURON_HPP
21 #define SUPERNN_NEURON_HPP
22 
23 #include <vector>
24 #include "activation_type.hpp"
25 #include "utils.hpp"
26 
27 namespace SuperNN
28 {
32 struct SUPERNN_EXPORT Connection
33 {
34  Connection();
35  virtual ~Connection();
36 
46  Connection(unsigned _l, unsigned _n, double _w = (Utils::rand_double(0.5) - 0.25));
47 
49  double weight;
50 
52  double derror;
53 
55  double aux1;
56 
58  double aux2;
59 
61  unsigned to_layer;
62 
64  unsigned to_neuron;
65 };
66 
70 struct SUPERNN_EXPORT Neuron
71 {
80  Neuron(bool _b = false);
81 
82  virtual ~Neuron();
83 
90  inline const Connection &operator[](unsigned c) const
91  {
92  return conns[c];
93  }
94 
101  inline Connection &operator[](unsigned c)
102  {
103  return conns[c];
104  }
105 
111  inline unsigned size() const
112  {
113  return conns.size();
114  }
115 
122  void connect(unsigned to_layer, unsigned to_neuron);
123 
130  void set_activation(ActFuncType type, double s = 1);
131 
133  std::vector<Connection> conns;
134 
136  double net;
137 
139  double out;
140 
142  double err;
143 
145  double delta;
146 
149 
151  double steep;
152 
154  bool delta_ok;
155 
157  bool bias;
158 };
159 }
160 
161 #endif
Neuron, that can contain connections to neurons in the next layers.
Definition: neuron.hpp:70
std::vector< Connection > conns
Synaptic connections.
Definition: neuron.hpp:133
double aux2
Auxiliary storage 2, used by some training algorithms.
Definition: neuron.hpp:58
Synaptic connection between two neurons.
Definition: neuron.hpp:32
bool delta_ok
Marks if the delta has been calculated for the current iteration.
Definition: neuron.hpp:154
double aux1
Auxiliary storage 1, used by some training algorithms.
Definition: neuron.hpp:55
double steep
Activation function steepness.
Definition: neuron.hpp:151
double weight
Weight.
Definition: neuron.hpp:49
double out
Last output of the neuron ( g(net) )
Definition: neuron.hpp:139
SUPERNN_EXPORT double rand_double(double max)
Returns a pseudo-random double.
Definition: utils.cpp:36
Connection & operator[](unsigned c)
Returns a reference to a connection.
Definition: neuron.hpp:101
double delta
Last local error gradient.
Definition: neuron.hpp:145
const Connection & operator[](unsigned c) const
Returns a const reference to a connection.
Definition: neuron.hpp:90
unsigned size() const
Returns the number of synaptic connections.
Definition: neuron.hpp:111
ActFuncType act_func
Used activation function.
Definition: neuron.hpp:148
double err
Last error (desired - actual).
Definition: neuron.hpp:142
unsigned to_neuron
Position of the target neuron in it's layer.
Definition: neuron.hpp:64
ActFuncType
Activation functions built-in in the library.
unsigned to_layer
Layer where the target neuron is located.
Definition: neuron.hpp:61
double net
Last sum of the neuron inputs.
Definition: neuron.hpp:136
bool bias
Marks if it's a bias neuron.
Definition: neuron.hpp:157
double derror
Accumulated partial error derivative in respect to the connection weight.
Definition: neuron.hpp:52