1 #ifndef BACKPROPAGATIONCGALGORITHM_H
2 #define BACKPROPAGATIONCGALGORITHM_H
4 #include "NeuralNetConfig.h"
7 #include "NeuralNetDataSet.h"
12 #include "InputNormaliser.h"
17 class InputNormaliser;
32 typedef enum { FletcherReves, PolakRibiere, ConjugateDescent } BetaFunctionSelect;
38 const NeuralNet::InputNormalisationSelect normaliseTrainingData=NeuralNet::PassthroughNormalised);
39 double train(
const int numberOfEpochs,
const NeuralNetDataSet &dataSet,
const std::vector<InputNormaliser *> &inputNormalisers);
40 void setBetaFunction(BetaFunctionSelect theFunction);
41 void setLinearSearchInitialStepLength(
const double stepLength) {_linearSearchStepLength = stepLength;}
42 void setLinearSearchMu(
const double mu) {_linearSearchMu = mu;}
43 void setLinearSearchSigma(
const double sigma) {_linearSearchSigma = sigma;}
44 void setLinearSearchGamma(
const double gamma) {_linearSearchGamma = gamma;}
45 void setLinearSearchMaxIterations(
const int maxIterations) {_linearSearchMaxIterations = maxIterations;}
46 void setLinearSearchAbsGradientCutoff(
const double cutoff) {_linearSearchAbsGradientCutoff = cutoff;}
47 void setEpochsBeforeGradientReset(
const int numberOfEpochs) {_epochsBeforeGradientReset = numberOfEpochs;}
48 void setProgressPrintoutFrequency(
const int frequency) {_progressPrintoutFrequency = frequency;}
49 std::vector<double> getTrainingErrorValuesPerEpoch()
const {
return _savedEpochErrorValues;}
52 double trainWithDataSet(
const int numberOfEpochs);
53 std::vector<double> layerOutput(
const int layer)
const;
54 void calculateLayerOutputs();
55 void calculateDerivativeOutputs();
56 void calculateErrorSignals();
58 void calculateRunningDeDw();
60 double newEpoch(
bool &success,
double &gradient);
61 double processDataSet();
62 double beta(
const std::vector<double> &gk,
const std::vector<double> &gkplus1,
const std::vector<double> &dk);
63 double betaFR(
const std::vector<double> &gk,
const std::vector<double> &gkplus1);
64 double betaPR(
const std::vector<double> &gk,
const std::vector<double> &gkplus1);
65 double betaCD(
const std::vector<double> &gk,
const std::vector<double> &gkplus1,
const std::vector<double> &dk);
66 double alpha(
const std::vector<double> &x,
const std::vector<double> &p,
const std::vector<double> &g,
const double F0,
bool &converged);
69 typedef std::vector<std::vector<double> > NetMatrix;
73 BetaFunctionSelect _theBetaFunction;
74 const std::vector<double> *_inputs,*_target;
75 NetMatrix _neuronErrorSignals;
76 NetMatrix _neuronOutputs;
77 NetMatrix _neuronDerivativeOutputs;
80 double _previousEpochError;
81 double _runningEpochErrorTotal;
82 int _numberOfTrainingEvents;
83 std::vector<double> _runningDeDwSum;
84 std::vector<double> _previousEpochDeDw;
85 double _linearSearchStepLength;
86 std::vector<double> _currentSearchDirection;
87 double _linearSearchMu;
88 double _linearSearchSigma;
89 double _linearSearchGamma;
90 double _linearSearchTolerance;
91 int _linearSearchMaxIterations;
92 int _epochsBeforeGradientReset;
94 int _progressPrintoutFrequency;
95 std::vector<double> _savedEpochErrorValues;
96 double _linearSearchAbsGradientCutoff;
97 double _previousEpochStepLength;
98 std::vector<double> _previousEpochDeltaWeights;