perceptron implementation changed + perceptronLearningAlgorithm and tests
This commit is contained in:
41
tests/perceptron_learning.cpp
Normal file
41
tests/perceptron_learning.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user