aimsalgo  5.0.5
Neuroimaging image processing
multilayerperceptron.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_NEURALNET_MULTILAYERPERCEPTRON_H
36 #define AIMS_NEURALNET_MULTILAYERPERCEPTRON_H
37 
39 #include <string>
40 
41 template <class T> class AimsData;
42 template <class T,int D> class AimsVector;
43 
44 
48 { protected:
51  int _nInputs;
54  float _output;
56  float _activation;
58  float _error;
64 
65  public:
71  AimsMLPNeuron(int ninputs);
73  virtual ~AimsMLPNeuron();
75 
78  int nInputs() const;
81  float output() const;
83  float activation() const;
85  float error() const;
87  float deltaW(int i) const;
89  float weight(int i) const;
91  void setWeight(const AimsData<float> &weight);
92 
94  void forward(const AimsData<float> &input);
96  void evaluateError(float target);
98  void backPropagation(const AimsData<float> &nexterror,
99  const AimsData<float> &nextweight);
101  void adjust(const AimsData<float> &input,
102  float learningrate,
103  float momentum);
105 };
106 
107 
111 { protected:
114  int _nNeurons;
119 
120  public:
127  AimsMLPLayer(int nneurons,int ninputs);
129  virtual ~AimsMLPLayer();
131 
134  int nNeurons() const;
137  AimsData<float> activations() const;
139  AimsData<float> outputs() const;
141  AimsData<float> errors() const;
143  AimsData<float> nextWeights(int n) const;
145  void setWeight(const AimsData<float> &weight, int neuron);
146 
148  void forward(const AimsData<float> &input);
150  float evaluateError(const AimsData<float> &target);
152  void backPropagation(const AimsMLPLayer &nextlayer);
154  void adjust(const AimsData<float> &input,
155  float learningrate, float momentum);
157 };
158 
159 
163 { protected:
166  int _nLayers;
169  int _nInputs;
175  float _momentum;
177  float _maxError;
181  int _maxTime;
187 
188  public:
201  AimsMultilayerPerceptron(const AimsData<int32_t> &topology, int ninputs,
202  float learningrate, float momentum,
203  float maxerror, int stabilitytime, int maxtime);
217  const AimsData<float> &weights,
218  int ninputs, float learningrate=0,
219  float momentum=0, float maxerror=0,
220  int stabilitytime=0, int maxtime=0);
222  virtual ~AimsMultilayerPerceptron();
224 
227  AimsData<int32_t> topology() const;
230  int nLayers() const;
232  int nInputs() const;
234  int nOutputs() const;
236  float learningRate() const;
238  float momentum() const;
240  float maxError() const;
242  int stabilityTime() const;
244  int maxTime() const;
246  void setLearningRate(float learningrate);
248  void setMomentum(float momentum);
250  void setMaxError(float maxerror);
252  void setStabilityTime(int stabilitytime);
254  void setMaxTime(int maxtime);
255 
257  void learn(const AimsData<float> &base,
258  const AimsData<float> &target,
259  int counter);
261  void forward(const AimsData<float> &input);
263  void backPropagation();
265  void adjust(const AimsData<float> &input);
267  AimsData<float> test(const AimsData<float> &base);
268 
270  AimsData<float> weights() const;
271 
273  void save(const std::string &filetopology,
274  const std::string &fileweight);
276 };
277 
278 
279 #endif
float _activation
Activation value (before entering sigmoid function)
The class for a complete MultiLayer Perceptron.
int _stabilityTime
Minimum number of epochs for the network to be considered stable.
AimsData< int32_t > * _topology
Topology of the network, i.e. number of neurons for each layer.
int _maxTime
Maximum of number of epochs for the learning step.
AimsData< float > * _deltaW
Weight variation data.
float _learningRate
Learning rate.
float _error
Error between desired and actual value.
AimsData< float > * _weight
Weight data.
The class that describes MLP neuron.
float _maxError
Maximum error to consider the network learned.
float _momentum
Momentum coefficient.
AimsMLPLayer ** _layer
Pointer to layer pointers.
float _output
Floating output.
int _nInputs
Number of inputs for each neuron.
The class to manage MLP layers of neurons.
#define AIMSALGO_API
AimsMLPNeuron ** _neuron
Pointer to neuron pointers.
int _nOutputs
Number of outputs of the network.