Files
NeuralNetworkLib/tests/nn-01.cpp

47 lines
1.3 KiB
C++

#include "../src/NeuralNetwork/FeedForward"
#include "../src/NeuralNetwork/Learning/BackPropagation"
#include <iostream>
#include <vector>
//typedef Shin::NeuronNetwork::Problem X;
class X: public Shin::Problem
{
public:
X(const X& a) :Problem(a) {}
X(const std::vector<bool> &a):Problem() { for (bool s:a) data.push_back((float)s);}
protected:
};
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<bool>({0})));
s.push_back(Shin::Solution(std::vector<float>({0})));
p.push_back(X(std::vector<bool>({1})));
Shin::NeuralNetwork::FeedForward q({1,5000,5000,15000,2});
Shin::NeuralNetwork::Learning::BackPropagation b(q);
if(argc > 1)
{
std::cerr << "THREADING\n";
q.setThreads(2);
}
#include <chrono>
auto t1 = std::chrono::high_resolution_clock::now();
for(int i=0;i<100;i++)
{
//b.teach(p[i%2],s[i%2]);
q.solve(p[i%2])[0];
//std::cerr << i%2 <<". FOR: [" << p[i%2].representation()[0] << "] res: " << q.solve(p[i%2])[0] << " should be " << s[i%2][0]<<"\n";
}
auto t2 = std::chrono::high_resolution_clock::now();
std::cout << "Time: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << std::endl;
}