LCFIVertex  0.7.2
BackPropagationAlgorithm.h
1 #ifndef BACKPROPAGATIONALGORITHM_H
2 #define BACKPROPAGATIONALGORITHM_H
3 
4 #include "NeuralNetConfig.h"
5 
6 #include "NeuralNet.h"
7 
8 #include <vector>
9 
10 //namespace nnet added 15/08/06 by Mark Grimes (mark.grimes@bristol.ac.uk) for the LCFI vertex package
11 namespace nnet
12 {
13 
14 class
15 #ifndef __CINT__
16 NEURALNETDLL
17 #endif
19 {
20 public:
21  BackPropagationAlgorithm(NeuralNet &theNetwork,const double learningRate=0.5,const double momentumConstant=0.5);
23  void setLearningRate(const double newLearningRate)
24  { _learningRate = newLearningRate;}
25  void setMomentumConstant(const double newMomentumConstant)
26  { _momentumConstant = newMomentumConstant;}
27  double train(const std::vector<double> &inputValues,const std::vector<double> &desiredOutput);
28 
29 protected:
30  std::vector<double> layerOutput(const int layer) const;
31  void calculateLayerOutputs();
32  void calculateDerivativeOutputs();
33  void calculateErrorSignals();
34  void calculateDeltaWeights();
35  double error();
36 
37 private:
38  typedef std::vector<std::vector<double> > NetMatrix;
39 
40 private:
41  NeuralNet &_theNetwork;
42  double _learningRate;
43  const std::vector<double> *_inputs,*_target;
44  NetMatrix _neuronErrorSignals;
45  NetMatrix _neuronOutputs;
46  NetMatrix _neuronDerivativeOutputs;
47  std::vector<double> _momentumWeights;
48  double _momentumConstant;
49 };
50 
51 }//namespace nnet
52 #endif