new test, and multithreading in FFQ, MT in BP not working
This commit is contained in:
@@ -3,10 +3,11 @@ include ../Makefile.const
|
||||
LIB_DIR = ../lib
|
||||
GEN_TESTS=g-01 g-02
|
||||
NN_TESTS= \
|
||||
nn-01 nn-02 nn-03 nn-bp-sppeed \
|
||||
nn-bp-xor \
|
||||
nn-obp-xor \
|
||||
nn-rl-xor nn-rl-and \
|
||||
nn-reinforcement nn-01 nn-02 nn-03 nn-04
|
||||
nn-reinforcement nn-04
|
||||
ALL_TESTS=$(NN_TESTS) $(GEN_TESTS)
|
||||
|
||||
LIBS=$(LIB_DIR)/Genetics.a $(LIB_DIR)/NeuronNetwork.a
|
||||
|
||||
@@ -18,7 +18,7 @@ class X: public Shin::NeuronNetwork::Problem
|
||||
std::vector<bool> q;
|
||||
};
|
||||
|
||||
int main()
|
||||
int main(int argc)
|
||||
{
|
||||
srand(time(NULL));
|
||||
std::vector<Shin::NeuronNetwork::Solution> s;
|
||||
@@ -31,22 +31,29 @@ int main()
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(X(std::vector<bool>({1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({1,5000,5000,1});
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({1,5000,5000,5000,500,500,500,500});
|
||||
Shin::NeuronNetwork::Learning::BackPropagation b(q);
|
||||
|
||||
int i=0;
|
||||
std::cerr << i%4 <<". FOR: [" << p[i%2].representation()[0] << "] res: " << q.solve(p[i%2])[0] << " should be " << s[i%2][0]<<"\n";
|
||||
if(argc > 1)
|
||||
{
|
||||
std::cerr << "THREADING\n";
|
||||
q.setThreads(4);
|
||||
}
|
||||
for(int i=0;i<5;i++)
|
||||
{
|
||||
//b.teach(p[i%2],s[i%2]);
|
||||
std::cerr << i%2 <<". FOR: [" << p[i%2].representation()[0] << "] res: " << q.solve(p[i%2])[0] << " should be " << s[i%2][0]<<"\n";
|
||||
}
|
||||
|
||||
for(int i=0;i<5;i++)
|
||||
{
|
||||
//b.teach(p[i%2],s[i%2]);
|
||||
// std::cerr << i%2 <<". FOR: [" << p[i%2].representation()[0] << "] res: " << q.solve(p[i%2])[0] << " should be " << s[i%2][0]<<"\n";
|
||||
std::cerr << i%2 <<". FOR: [" << p[i%2].representation()[0] << "] res: " << q.solve(p[i%2])[0] << " should be " << s[i%2][0]<<"\n";
|
||||
}
|
||||
for(int i=0;i<2;i++)
|
||||
{
|
||||
// b.teach(p[i%2],s[i%2]);
|
||||
std::cerr << i%4 <<". FOR: [" << p[i%4].representation()[0] << "," <<p[i%4].representation()[0] << "] res: " << q.solve(p[i%4])[0] << " should be " <<
|
||||
s[i%4][0]<<"\n";
|
||||
// std::cerr << i%4 <<". FOR: [" << p[i%4].representation()[0] << "," <<p[i%4].representation()[0] << "] res: " << q.solve(p[i%4])[0] << " should be " <<
|
||||
// s[i%4][0]<<"\n";
|
||||
}
|
||||
/*
|
||||
for(int i=0;i<40;i++)
|
||||
|
||||
47
tests/nn-bp-sppeed.cpp
Normal file
47
tests/nn-bp-sppeed.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "../src/NeuronNetwork/FeedForward"
|
||||
#include "../src/NeuronNetwork/FeedForwardQuick"
|
||||
#include "../src/NeuronNetwork/Learning/BackPropagation"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
class X: public Shin::NeuronNetwork::Problem
|
||||
{
|
||||
public:
|
||||
X(const X& a) :q(a.q) {}
|
||||
X(const std::vector<bool> &a):q(a) {}
|
||||
std::vector<bool> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<bool> q;
|
||||
};
|
||||
|
||||
int main(int argc, char*argv)
|
||||
{
|
||||
srand(time(NULL));
|
||||
std::vector<Shin::NeuronNetwork::Solution> s;
|
||||
std::vector<X> p;
|
||||
|
||||
//
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({1})));
|
||||
p.push_back(X(std::vector<bool>({0})));
|
||||
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(X(std::vector<bool>({1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({1,5000,5000,5000,1});
|
||||
Shin::NeuronNetwork::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].representation()[0] << "] res: " << q.solve(p[i%2])[0] << " should be " << s[i%2][0]<<"\n";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "../src/NeuronNetwork/FeedForwardQuick"
|
||||
#include "../src/NeuronNetwork/Learning/Reinforcement"
|
||||
#include "../src/NeuronNetwork/Learning/OpticalBackPropagation"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
@@ -20,10 +21,19 @@ class X: public Shin::NeuronNetwork::Problem
|
||||
int main()
|
||||
{
|
||||
|
||||
for (int test=0;test<2;test++)
|
||||
for (int test=0;test<3;test++)
|
||||
{
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({2,6,1});
|
||||
Shin::NeuronNetwork::Learning::Reinforcement b(q);
|
||||
double targetQuality =1.2;
|
||||
if(test==2)
|
||||
{
|
||||
targetQuality =1.62;
|
||||
std::cerr << "Testing with OBP ...\n";
|
||||
|
||||
b.setPropagator(new Shin::NeuronNetwork::Learning::OpticalBackPropagation(q));
|
||||
b.getPropagator().setLearningCoeficient(3);
|
||||
}
|
||||
b.setQualityFunction(
|
||||
[](const Shin::NeuronNetwork::Problem &pr,const Shin::NeuronNetwork::Solution &s)->double
|
||||
{
|
||||
@@ -42,10 +52,10 @@ int main()
|
||||
|
||||
if(expect==0)
|
||||
{
|
||||
expect=0.35-s[0];
|
||||
expect=0.33-s[0];
|
||||
}else
|
||||
{
|
||||
expect=s[0]-0.65;
|
||||
expect=s[0]-0.67;
|
||||
}
|
||||
|
||||
// std::cerr << " returnning " << expect*5.0 << "\n";
|
||||
@@ -62,7 +72,7 @@ int main()
|
||||
p.push_back( new X(std::vector<bool>({0,1})));
|
||||
p.push_back(new X(std::vector<bool>({1,1})));
|
||||
|
||||
if(test)
|
||||
if(test==1)
|
||||
{
|
||||
std::cerr << "Testing with entropy ...\n";
|
||||
b.getPropagator().allowEntropy();
|
||||
@@ -70,7 +80,6 @@ int main()
|
||||
{
|
||||
std::cerr << "Testing without entropy ...\n";
|
||||
}
|
||||
double targetQuality =1.5;
|
||||
|
||||
for(int i=0;i < 500000000;i++)
|
||||
{
|
||||
@@ -78,7 +87,7 @@ int main()
|
||||
|
||||
if(i%100000==0)
|
||||
srand(time(NULL));
|
||||
if(i%20000==0 || err > targetQuality)
|
||||
if(i%40000==0 || err > targetQuality)
|
||||
{
|
||||
std::cerr << i << " ("<< err <<").\n";
|
||||
for(int j=0;j<4;j++)
|
||||
|
||||
Reference in New Issue
Block a user