modified BP interface
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
#include <NeuralNetwork/FeedForward/Network.h>
|
||||
#include "CorrectionFunction/Linear.h"
|
||||
|
||||
namespace NeuralNetwork {
|
||||
namespace Learning {
|
||||
@@ -13,21 +15,23 @@ namespace Learning {
|
||||
class BackPropagation {
|
||||
|
||||
public:
|
||||
inline BackPropagation(FeedForward::Network &feedForwardNetwork): network(feedForwardNetwork), learningCoefficient(0.4), deltas() {
|
||||
inline BackPropagation(FeedForward::Network &feedForwardNetwork, CorrectionFunction::CorrectionFunction *correction = new CorrectionFunction::Linear()):
|
||||
network(feedForwardNetwork), correctionFunction(correction),learningCoefficient(0.4), deltas() {
|
||||
resize();
|
||||
}
|
||||
|
||||
virtual ~BackPropagation() {
|
||||
delete correctionFunction;
|
||||
}
|
||||
|
||||
BackPropagation(const BackPropagation&)=delete;
|
||||
BackPropagation& operator=(const NeuralNetwork::Learning::BackPropagation&) = delete;
|
||||
|
||||
void teach(const std::vector<float> &input, const std::vector<float> &output);
|
||||
|
||||
inline virtual void setLearningCoefficient (const float& coefficient) { learningCoefficient=coefficient; }
|
||||
|
||||
protected:
|
||||
inline virtual float correction(const float & expected, const float &computed) const {
|
||||
return expected-computed;
|
||||
};
|
||||
|
||||
inline void resize() {
|
||||
if(deltas.size()!=network.size())
|
||||
@@ -41,6 +45,8 @@ namespace Learning {
|
||||
|
||||
FeedForward::Network &network;
|
||||
|
||||
CorrectionFunction::CorrectionFunction *correctionFunction;
|
||||
|
||||
float learningCoefficient;
|
||||
|
||||
std::vector<std::vector<float>> deltas;
|
||||
|
||||
Reference in New Issue
Block a user