perceptron implementation changed + perceptronLearningAlgorithm and tests

This commit is contained in:
2016-03-08 23:10:38 +01:00
parent 4ef010b965
commit a48298b342
7 changed files with 97 additions and 7 deletions

View File

@@ -0,0 +1,41 @@
#include <NeuralNetwork/Learning/PerceptronLearning.h>
#include <cassert>
#include <iostream>
int main() {
{ // XOR problem
NeuralNetwork::FeedForward::Perceptron n(2,1);
n.randomizeWeights();
NeuralNetwork::Learning::PerceptronLearning learn(n);
for(int i=0;i<10;i++) {
learn.teach({1,0},{1});
learn.teach({1,1},{1});
learn.teach({0,0},{0});
learn.teach({0,1},{1});
}
{
std::vector<float> ret =n.computeOutput({1,1});
assert(ret[0] > 0.9);
}
{
std::vector<float> ret =n.computeOutput({0,1});
assert(ret[0] > 0.9);
}
{
std::vector<float> ret =n.computeOutput({1,0});
assert(ret[0] > 0.9);
}
{
std::vector<float> ret =n.computeOutput({0,0});
assert(ret[0] < 0.1);
}
}
}