Files
NeuralNetworkLib/tests/nn-bp-sppeed.cpp

40 lines
936 B
C++

#include "../src/NeuralNetwork/FeedForward"
#include "../src/NeuralNetwork/Learning/BackPropagation"
#include <iostream>
#include <vector>
class X: public Shin::Problem
{
public:
X(const X& a) :Problem(a.data) {}
X(const std::vector<float> &a):Problem(a) {}
};
int main(int argc, char**)
{
srand(time(NULL));
std::vector<Shin::Solution> s;
std::vector<X> p;
//
s.push_back(Shin::Solution(std::vector<float>({1})));
p.push_back(X(std::vector<float>({0})));
s.push_back(Shin::Solution(std::vector<float>({0})));
p.push_back(X(std::vector<float>({1})));
Shin::NeuralNetwork::FeedForward q({1,5000,5000,5000,1});
Shin::NeuralNetwork::Learning::BackPropagation b(q);
if(argc >1)
{
std::cerr << "Allowing threadnig\n";
b.allowThreading();
}
for(int i=0;i<2;i++)
{
b.teach(p[i%2],s[i%2]);
std::cerr << i%2 <<". FOR: [" << p[i%2][0] << "] res: " << q.solve(p[i%2])[0] << " should be " << s[i%2][0]<<"\n";
}
}