don't know
This commit is contained in:
@@ -3,12 +3,14 @@ include ../Makefile.const
|
||||
OPTIMALIZATION=
|
||||
LIB_DIR = ../lib
|
||||
GEN_TESTS=g-01 g-02
|
||||
NN_TESTS= \
|
||||
NN_TESTS=\
|
||||
nn-01 nn-02 nn-03 nn-bp-sppeed \
|
||||
nn-bp-xor \
|
||||
nn-obp-xor \
|
||||
nn-rl-xor nn-rl-and \
|
||||
nn-rl-xor nn-rl-and nn-rl-qfun\
|
||||
nn-reinforcement nn-04
|
||||
# nn-test nn-rl-qfun\
|
||||
|
||||
ALL_TESTS=$(NN_TESTS) $(GEN_TESTS)
|
||||
|
||||
LIBS=$(LIB_DIR)/Genetics.a $(LIB_DIR)/NeuronNetwork.a
|
||||
|
||||
@@ -5,20 +5,15 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
//typedef Shin::NeuronNetwork::Problem X;
|
||||
|
||||
class X: public Shin::NeuronNetwork::Problem
|
||||
{
|
||||
public:
|
||||
X(const X& a) :q(a.q) {}
|
||||
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;
|
||||
}
|
||||
X(const X& a) :Problem(a) {}
|
||||
X(const std::vector<bool> &a):Problem() { for (bool s:a) data.push_back((float)s);}
|
||||
protected:
|
||||
std::vector<float> q;
|
||||
};
|
||||
|
||||
int main(int argc,char**)
|
||||
{
|
||||
srand(time(NULL));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
class X: public Shin::NeuronNetwork::Problem
|
||||
{
|
||||
public:
|
||||
X(const X& a) :q(a.q) {}
|
||||
X(const X& a) :Problem(),q(a.q) {}
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
@@ -33,8 +33,9 @@ int main()
|
||||
s.push_back(Shin::NeuronNetwork::Solution(std::vector<float>({1})));
|
||||
p.push_back(X(std::vector<float>({1,1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({2,2,4,1});
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({2,4,1});
|
||||
Shin::NeuronNetwork::Learning::BackPropagation b(q);
|
||||
b.setLearningCoeficient(10);
|
||||
|
||||
b.debugOn();
|
||||
for(int i=0;i<4;i++)
|
||||
@@ -45,7 +46,7 @@ int main()
|
||||
}
|
||||
b.debugOff();
|
||||
|
||||
for(int i=0;i<4000;i++)
|
||||
for(int i=0;i<40000;i++)
|
||||
{
|
||||
b.teach(p[i%4],s[i%4]);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,8 @@
|
||||
class X: public Shin::NeuronNetwork::Problem
|
||||
{
|
||||
public:
|
||||
X(const X& a) :q(a.q) {}
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<float> q;
|
||||
X(const X& a) :Problem(a) {}
|
||||
X(const std::vector<float> &a):Problem() {data=a;}
|
||||
};
|
||||
|
||||
int main()
|
||||
@@ -66,7 +60,7 @@ int main()
|
||||
std::cerr << j << "(" << err <<"):\n";
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
std::cerr << "\t" << i%4 <<". FOR: [" << p[i%4]->representation()[0] << "," <<p[i%4]->representation()[1] << "] res: " <<
|
||||
std::cerr << "\t" << i%4 <<". FOR: [" << p[i%4]->operator[](0) << "," <<p[i%4]->operator[](1) << "] res: " <<
|
||||
q.solve(*p[i%4])[0] << " should be " << s[i%4]->operator[](0)<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,8 @@
|
||||
class X: public Shin::NeuronNetwork::Problem
|
||||
{
|
||||
public:
|
||||
X(const X& a) :q(a.q) {}
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<float> q;
|
||||
X(const X& a) :Problem(a) {}
|
||||
X(const std::vector<float> &a):Problem() {data=a;}
|
||||
};
|
||||
|
||||
int main()
|
||||
@@ -67,7 +61,7 @@ int main()
|
||||
std::cerr << j << "(" << err <<"):\n";
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
std::cerr << "\t" << i%4 <<". FOR: [" << p[i%4]->representation()[0] << "," <<p[i%4]->representation()[1] << "] res: " <<
|
||||
std::cerr << "\t" << i%4 <<". FOR: [" << p[i%4]->operator[](0) << "," <<p[i%4]->operator[](1) << "] res: " <<
|
||||
q.solve(*p[i%4])[0] << " should be " << s[i%4]->operator[](0)<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,8 @@
|
||||
class X: public Shin::NeuronNetwork::Problem
|
||||
{
|
||||
public:
|
||||
X(const X& a) :q(a.q) {}
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<float> q;
|
||||
X(const X& a) :Problem(a) {}
|
||||
X(const std::vector<float> &a):Problem() {data=a;}
|
||||
};
|
||||
|
||||
int main()
|
||||
@@ -28,14 +22,17 @@ int main()
|
||||
|
||||
p.push_back(new X(std::vector<float>({1,1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({1,1});
|
||||
p.push_back(new X(std::vector<float>({1,0})));
|
||||
p.push_back(new X(std::vector<float>({0,1})));
|
||||
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({2,1});
|
||||
Shin::NeuronNetwork::Learning::Reinforcement b(q);
|
||||
int i=0;
|
||||
double targetQuality=1.4;
|
||||
double targetQuality=0.5;
|
||||
b.setQualityFunction(
|
||||
[](const Shin::NeuronNetwork::Problem &pr,const Shin::NeuronNetwork::Solution &s)->float
|
||||
{
|
||||
if(pr.representation()[0]==0)
|
||||
if(pr[0]==1 && pr[1]==1)
|
||||
{
|
||||
//ocekavame 1
|
||||
int e=(s[0]-0.80)*15.0;//+(abs(s[1])-0.5)*100.0;
|
||||
@@ -54,12 +51,12 @@ int main()
|
||||
|
||||
if(i%100000==0)
|
||||
srand(time(NULL));
|
||||
if(err > targetQuality)
|
||||
if(err > targetQuality||i%1000==0)
|
||||
{
|
||||
std::cerr << i << " ("<< err <<").\n";
|
||||
for(int j=0;j<2;j++)
|
||||
for(int j=0;j<4;j++)
|
||||
{
|
||||
std::cerr << j%4 <<". FOR: [" << p[j%4]->representation()[0] << "," <<p[j%4]->representation()[0] << "] res: " << q.solve(*p[j%4])[0] << "\n";
|
||||
std::cerr << j%4 <<". FOR: [" << p[j%4]->operator[](0) << "," <<p[j%4]->operator[](0) << "] res: " << q.solve(*p[j%4])[0] << "\n";
|
||||
}
|
||||
}
|
||||
if(err >targetQuality)
|
||||
|
||||
@@ -5,19 +5,15 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class X: public Shin::NeuronNetwork::Problem
|
||||
{
|
||||
public:
|
||||
X(const X& a) :q(a.q) {}
|
||||
X(const std::vector<float> &a):q(a) {}
|
||||
std::vector<float> representation() const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
protected:
|
||||
std::vector<float> q;
|
||||
X(const X& a) :Problem(a) {}
|
||||
X(const std::vector<float> &a):Problem() {data=a;}
|
||||
};
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
srand(time(NULL));
|
||||
@@ -26,9 +22,9 @@ int main()
|
||||
Shin::NeuronNetwork::FeedForwardNetworkQuick q({2,4,1});
|
||||
Shin::NeuronNetwork::Learning::Reinforcement b(q);
|
||||
//b.setPropagator(new Shin::NeuronNetwork::Learning::OpticalBackPropagation(q));
|
||||
b.getPropagator().setLearningCoeficient(3);
|
||||
b.getPropagator().setLearningCoeficient(0.4);
|
||||
//b.getPropagator().allowEntropy();
|
||||
double targetQuality =1;
|
||||
double targetQuality =2.9;
|
||||
if(test==2)
|
||||
{
|
||||
targetQuality =1.62;
|
||||
@@ -38,9 +34,8 @@ int main()
|
||||
b.getPropagator().setLearningCoeficient(0.5);
|
||||
}
|
||||
b.setQualityFunction(
|
||||
[](const Shin::NeuronNetwork::Problem &pr,const Shin::NeuronNetwork::Solution &s)->float
|
||||
[](const Shin::NeuronNetwork::Problem &p,const Shin::NeuronNetwork::Solution &s)->float
|
||||
{
|
||||
std::vector <float> p=pr;
|
||||
float expect=0.0;
|
||||
if(p[0] && p[1])
|
||||
expect=0;
|
||||
@@ -55,10 +50,10 @@ int main()
|
||||
|
||||
if(expect==0)
|
||||
{
|
||||
expect=0.1-abs(s[0]);
|
||||
expect=0.3-abs(s[0]);
|
||||
}else
|
||||
{
|
||||
expect=s[0]-0.9;
|
||||
expect=s[0]-0.7;
|
||||
}
|
||||
|
||||
// std::cerr << " returnning " << expect*5.0 << "\n";
|
||||
@@ -93,7 +88,7 @@ int main()
|
||||
std::cerr << i << " ("<< err <<").\n";
|
||||
for(int j=0;j<4;j++)
|
||||
{
|
||||
std::cerr << "\t" << j%4 << ". FOR: [" << p[j%4]->representation()[0] << "," <<p[j%4]->representation()[1] << "] res: " <<
|
||||
std::cerr << "\t" << i%4 <<". FOR: [" << p[j%4]->operator[](0) << "," <<p[j%4]->operator[](1) << "] res: " <<
|
||||
q.solve(*p[j%4])[0] << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user