loooot of fixes nad SSE enhacement
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
include ../Makefile.const
|
||||
|
||||
OPTIMALIZATION=
|
||||
LIB_DIR = ../lib
|
||||
GEN_TESTS=g-01 g-02
|
||||
NN_TESTS= \
|
||||
@@ -23,7 +24,7 @@ test: all
|
||||
@for i in $(ALL_TESTS); do echo -n ./$$i; echo -n " - "; ./$$i; echo ""; done
|
||||
|
||||
g-%: g-%.cpp $(LIB_DIR)/Genetics.a
|
||||
$(CXX) $(CXXFLAGS) -o $@ $< $ $(LIB_DIR)/Genetics.a $(LIB_DIR)/NeuronNetwork.a -lm
|
||||
$(CXX) $(CXXFLAGS) $(OPTIMALIZATION) -o $@ $< $ $(LIB_DIR)/Genetics.a $(LIB_DIR)/NeuronNetwork.a -lm
|
||||
|
||||
nn-%: nn-%.cpp $(LIB_DIR)/NeuronNetwork.a
|
||||
$(CXX) $(CXXFLAGS) -o $@ $< $ $(LIB_DIR)/NeuronNetwork.a -lm
|
||||
|
||||
@@ -9,59 +9,45 @@ 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
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
X(const std::vector<bool> &a):q() {for(bool s:a) q.push_back((float)s);}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<bool> q;
|
||||
std::vector<float> q;
|
||||
};
|
||||
|
||||
int main(int argc)
|
||||
int main(int argc,char**)
|
||||
{
|
||||
srand(time(NULL));
|
||||
std::vector<Shin::NeuronNetwork::Solution> s;
|
||||
std::vector<X> p;
|
||||
|
||||
//
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({1})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<float>({1})));
|
||||
p.push_back(X(std::vector<bool>({0})));
|
||||
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<float>({0})));
|
||||
p.push_back(X(std::vector<bool>({1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({1,5000,5000,5000});
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({1,5000,5000,15000,2});
|
||||
Shin::NeuronNetwork::Learning::BackPropagation b(q);
|
||||
if(argc > 1)
|
||||
{
|
||||
std::cerr << "THREADING\n";
|
||||
q.setThreads(4);
|
||||
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";
|
||||
}
|
||||
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";
|
||||
}
|
||||
/*
|
||||
for(int i=0;i<40;i++)
|
||||
{
|
||||
b.teach(p[i%4],s[i%4]);
|
||||
}
|
||||
b.debugOn();
|
||||
std::cerr << "LEARNED\n";
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
b.teach(p[i%4],s[i%4]);
|
||||
std::cerr << i%4 <<". FOR: [" << p[i%4].representation()[0] << "," <<p[i%4].representation()[1] << "] res: " << q.solve(p[i%4])[0] << " should be " <<
|
||||
s[i%4][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;
|
||||
|
||||
}
|
||||
@@ -7,9 +7,9 @@
|
||||
class X: public Shin::NeuronNetwork::Problem
|
||||
{
|
||||
protected:
|
||||
std::vector<bool> representation() const
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return std::vector<bool>({1,1});
|
||||
return std::vector<float>({1,1});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ 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
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<bool> q;
|
||||
std::vector<float> q;
|
||||
};
|
||||
|
||||
int main()
|
||||
@@ -24,14 +24,14 @@ int main()
|
||||
std::vector<X> p;
|
||||
|
||||
//
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(X(std::vector<bool>({1,0})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(X(std::vector<bool>({0,1})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(X(std::vector<bool>({0,0})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({1})));
|
||||
p.push_back(X(std::vector<bool>({1,1})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<float>({0})));
|
||||
p.push_back(X(std::vector<float>({1,0})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<float>({0})));
|
||||
p.push_back(X(std::vector<float>({0,1})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<float>({0})));
|
||||
p.push_back(X(std::vector<float>({0,0})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<float>({1})));
|
||||
p.push_back(X(std::vector<float>({1,1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({2,4,1});
|
||||
Shin::NeuronNetwork::Learning::BackPropagation b(q);
|
||||
@@ -45,7 +45,7 @@ int main()
|
||||
}
|
||||
b.debugOff();
|
||||
|
||||
for(int i=0;i<40;i++)
|
||||
for(int i=0;i<4000;i++)
|
||||
{
|
||||
b.teach(p[i%4],s[i%4]);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
class X: public Shin::NeuronNetwork::Problem
|
||||
{
|
||||
public: X(bool x,bool y):x(x),y(y) {}
|
||||
protected: std::vector<bool> representation() const { return std::vector<bool>({x,y}); }
|
||||
protected: std::vector<float> representation() const { return std::vector<float>({x,y}); }
|
||||
private:
|
||||
bool x;
|
||||
bool y;
|
||||
|
||||
@@ -9,27 +9,27 @@ 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
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<bool> q;
|
||||
std::vector<float> q;
|
||||
};
|
||||
|
||||
int main(int argc, char*argv)
|
||||
int main(int argc, char**)
|
||||
{
|
||||
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<float>({1})));
|
||||
p.push_back(X(std::vector<float>({0})));
|
||||
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(X(std::vector<bool>({1})));
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<float>({0})));
|
||||
p.push_back(X(std::vector<float>({1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({1,5000,5000,5000,1});
|
||||
Shin::NeuronNetwork::Learning::BackPropagation b(q);
|
||||
|
||||
@@ -8,13 +8,13 @@ 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
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<bool> q;
|
||||
std::vector<float> q;
|
||||
};
|
||||
|
||||
int main()
|
||||
@@ -29,17 +29,17 @@ int main()
|
||||
std::vector<Shin::NeuronNetwork::Solution*> s;
|
||||
std::vector<Shin::NeuronNetwork::Problem*> p;
|
||||
|
||||
s.push_back(new Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(new X(std::vector<bool>({0,0})));
|
||||
s.push_back(new Shin::NeuronNetwork::Solution(std::vector<float>({0})));
|
||||
p.push_back(new X(std::vector<float>({0,0})));
|
||||
|
||||
s.push_back( new Shin::NeuronNetwork::Solution(std::vector<double>({1})));
|
||||
p.push_back( new X(std::vector<bool>({1,0})));
|
||||
s.push_back( new Shin::NeuronNetwork::Solution(std::vector<float>({1})));
|
||||
p.push_back( new X(std::vector<float>({1,0})));
|
||||
|
||||
s.push_back(new Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(new X(std::vector<bool>({1,1})));
|
||||
s.push_back(new Shin::NeuronNetwork::Solution(std::vector<float>({0})));
|
||||
p.push_back(new X(std::vector<float>({1,1})));
|
||||
|
||||
s.push_back( new Shin::NeuronNetwork::Solution(std::vector<double>({1})));
|
||||
p.push_back( new X(std::vector<bool>({0,1})));
|
||||
s.push_back( new Shin::NeuronNetwork::Solution(std::vector<float>({1})));
|
||||
p.push_back( new X(std::vector<float>({0,1})));
|
||||
|
||||
if(test)
|
||||
{
|
||||
|
||||
@@ -8,13 +8,13 @@ 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
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<bool> q;
|
||||
std::vector<float> q;
|
||||
};
|
||||
|
||||
int main()
|
||||
@@ -29,17 +29,17 @@ int main()
|
||||
std::vector<Shin::NeuronNetwork::Solution*> s;
|
||||
std::vector<Shin::NeuronNetwork::Problem*> p;
|
||||
|
||||
s.push_back(new Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(new X(std::vector<bool>({0,0})));
|
||||
s.push_back(new Shin::NeuronNetwork::Solution(std::vector<float>({0})));
|
||||
p.push_back(new X(std::vector<float>({0,0})));
|
||||
|
||||
s.push_back( new Shin::NeuronNetwork::Solution(std::vector<double>({1})));
|
||||
p.push_back( new X(std::vector<bool>({1,0})));
|
||||
s.push_back( new Shin::NeuronNetwork::Solution(std::vector<float>({1})));
|
||||
p.push_back( new X(std::vector<float>({1,0})));
|
||||
|
||||
s.push_back(new Shin::NeuronNetwork::Solution(std::vector<double>({0})));
|
||||
p.push_back(new X(std::vector<bool>({1,1})));
|
||||
s.push_back(new Shin::NeuronNetwork::Solution(std::vector<float>({0})));
|
||||
p.push_back(new X(std::vector<float>({1,1})));
|
||||
|
||||
s.push_back( new Shin::NeuronNetwork::Solution(std::vector<double>({1})));
|
||||
p.push_back( new X(std::vector<bool>({0,1})));
|
||||
s.push_back( new Shin::NeuronNetwork::Solution(std::vector<float>({1})));
|
||||
p.push_back( new X(std::vector<float>({0,1})));
|
||||
|
||||
b.debugOn();
|
||||
if(test)
|
||||
|
||||
@@ -9,13 +9,13 @@ 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
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<bool> q;
|
||||
std::vector<float> q;
|
||||
};
|
||||
|
||||
int main()
|
||||
@@ -24,15 +24,16 @@ int main()
|
||||
|
||||
std::vector<X> p;
|
||||
|
||||
p.push_back(X(std::vector<bool>({0,0})));
|
||||
p.push_back(X(std::vector<float>({0,0})));
|
||||
|
||||
p.push_back(X(std::vector<bool>({1,1})));
|
||||
p.push_back(X(std::vector<float>({1,1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({2,6,2});
|
||||
Shin::NeuronNetwork::Learning::Reinforcement b(q);
|
||||
b.getPropagator().setLearningCoeficient(1);
|
||||
int i=0;
|
||||
b.setQualityFunction(
|
||||
[&i](const Shin::NeuronNetwork::Solution &s)->double
|
||||
[&i](const Shin::NeuronNetwork::Problem &,const Shin::NeuronNetwork::Solution &s)->float
|
||||
{
|
||||
if(i%2==0)
|
||||
{
|
||||
|
||||
@@ -9,13 +9,13 @@ 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
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<bool> q;
|
||||
std::vector<float> q;
|
||||
};
|
||||
|
||||
int main()
|
||||
@@ -24,16 +24,16 @@ int main()
|
||||
|
||||
std::vector<Shin::NeuronNetwork::Problem*> p;
|
||||
|
||||
p.push_back(new X(std::vector<bool>({0,0})));
|
||||
p.push_back(new X(std::vector<float>({0,0})));
|
||||
|
||||
p.push_back(new X(std::vector<bool>({1,1})));
|
||||
p.push_back(new X(std::vector<float>({1,1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({1,1});
|
||||
Shin::NeuronNetwork::Learning::Reinforcement b(q);
|
||||
int i=0;
|
||||
double targetQuality=1.4;
|
||||
b.setQualityFunction(
|
||||
[](const Shin::NeuronNetwork::Problem &pr,const Shin::NeuronNetwork::Solution &s)->double
|
||||
[](const Shin::NeuronNetwork::Problem &pr,const Shin::NeuronNetwork::Solution &s)->float
|
||||
{
|
||||
if(pr.representation()[0]==0)
|
||||
{
|
||||
|
||||
@@ -9,23 +9,26 @@ 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
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<bool> q;
|
||||
std::vector<float> q;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
srand(time(NULL));
|
||||
for (int test=0;test<3;test++)
|
||||
{
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({2,6,1});
|
||||
Shin::NeuronNetwork::Learning::Reinforcement b(q);
|
||||
double targetQuality =1.2;
|
||||
b.setPropagator(new Shin::NeuronNetwork::Learning::OpticalBackPropagation(q));
|
||||
b.getPropagator().setLearningCoeficient(0.9);
|
||||
b.getPropagator().allowEntropy();
|
||||
double targetQuality =1.7;
|
||||
if(test==2)
|
||||
{
|
||||
targetQuality =1.62;
|
||||
@@ -35,10 +38,10 @@ int main()
|
||||
b.getPropagator().setLearningCoeficient(3);
|
||||
}
|
||||
b.setQualityFunction(
|
||||
[](const Shin::NeuronNetwork::Problem &pr,const Shin::NeuronNetwork::Solution &s)->double
|
||||
[](const Shin::NeuronNetwork::Problem &pr,const Shin::NeuronNetwork::Solution &s)->float
|
||||
{
|
||||
std::vector <bool> p=pr;
|
||||
double expect=0.0;
|
||||
std::vector <float> p=pr;
|
||||
float expect=0.0;
|
||||
if(p[0] && p[1])
|
||||
expect=0;
|
||||
else if(p[0] && !p[1])
|
||||
@@ -60,17 +63,15 @@ int main()
|
||||
|
||||
// std::cerr << " returnning " << expect*5.0 << "\n";
|
||||
|
||||
return expect*5.0;
|
||||
return expect*9.0;
|
||||
});
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
std::vector<Shin::NeuronNetwork::Problem*> p;
|
||||
|
||||
p.push_back(new X(std::vector<bool>({0,0})));
|
||||
p.push_back( new X(std::vector<bool>({1,0})));
|
||||
p.push_back( new X(std::vector<bool>({0,1})));
|
||||
p.push_back(new X(std::vector<bool>({1,1})));
|
||||
p.push_back(new X(std::vector<float>({0,0})));
|
||||
p.push_back( new X(std::vector<float>({1,0})));
|
||||
p.push_back( new X(std::vector<float>({0,1})));
|
||||
p.push_back(new X(std::vector<float>({1,1})));
|
||||
|
||||
if(test==1)
|
||||
{
|
||||
@@ -82,12 +83,13 @@ int main()
|
||||
}
|
||||
|
||||
for(int i=0;i < 500000000;i++)
|
||||
// for(int i=0;i < 5;i++)
|
||||
{
|
||||
double err=b.learnSet(p);
|
||||
|
||||
if(i%100000==0)
|
||||
srand(time(NULL));
|
||||
if(i%40000==0 || err > targetQuality)
|
||||
if(i%200000==0 || err > targetQuality)
|
||||
{
|
||||
std::cerr << i << " ("<< err <<").\n";
|
||||
for(int j=0;j<4;j++)
|
||||
|
||||
Reference in New Issue
Block a user