#include "../src/NeuronNetwork/FeedForwardQuick" #include "../src/NeuronNetwork/Learning/BackPropagation" #include #include class X: public Shin::NeuronNetwork::Problem { public: X(const X& a) :q(a.q) {} X(const std::vector &a):q(a) {} std::vector representation() const { return q; } protected: std::vector q; }; int main() { for (int test=0;test<2;test++) { Shin::NeuronNetwork::FeedForwardNetworkQuick q({2,4,1}); Shin::NeuronNetwork::Learning::BackPropagation b(q); srand(time(NULL)); std::vector s; std::vector p; s.push_back(new Shin::NeuronNetwork::Solution(std::vector({0}))); p.push_back(new X(std::vector({0,0}))); s.push_back( new Shin::NeuronNetwork::Solution(std::vector({1}))); p.push_back( new X(std::vector({1,0}))); s.push_back(new Shin::NeuronNetwork::Solution(std::vector({0}))); p.push_back(new X(std::vector({1,1}))); s.push_back( new Shin::NeuronNetwork::Solution(std::vector({1}))); p.push_back( new X(std::vector({0,1}))); if(test) { std::cerr << "Testing with entropy\n"; b.allowEntropy(); }else { std::cerr << "Testing without entropy\n"; } b.setLearningCoeficient(0.1);//8); for(int j=0;;j++) { double err=b.teachSet(p,s); if(err <0.3) { // b.setLearningCoeficient(5); } if(err <0.1) { // b.setLearningCoeficient(0.2); } if(err <0.001) { std::cerr << j << "(" << err <<"):\n"; for(int i=0;i<4;i++) { std::cerr << "\t" << i%4 <<". FOR: [" << p[i%4]->representation()[0] << "," <representation()[1] << "] res: " << q.solve(*p[i%4])[0] << " should be " << s[i%4]->operator[](0)<<"\n"; } } if(err <0.001) break; } } }