new implementation of FF Network

This commit is contained in:
2014-11-04 22:25:11 +01:00
parent 0238312a5b
commit 75ca9bc21f
23 changed files with 370 additions and 104 deletions

View File

@@ -21,12 +21,12 @@ class X: public Shin::NeuronNetwork::Problem
class S: public Shin::Genetics::Individual
{
public:
S():n(2,4,1)
S():n({2,4,1})
{
}
void mutate()
{
for(int i=0;i<3;i++)
for(unsigned int i=0;i<n.size();i++)
{
for (int j=0;j<n[i]->size();j++)
{
@@ -39,12 +39,14 @@ class S: public Shin::Genetics::Individual
}
int k;
if(i==0)
k=0;
continue;
else if(i==1)
k=2;
k=1;
else
k=3;
for(;k>=0;--k)
{
std::cerr << "i: "<<i <<" " << k << std::endl;
if(rand()%20==0)
{
if(rand()%2)
@@ -52,15 +54,16 @@ class S: public Shin::Genetics::Individual
else
n[i]->operator[](j)->setWeight(k,n[i]->operator[](j)->getWeight(k)+1);
}
}
}
}
};
S* SQ(S *s)
}
S combine(S &s)
{
S * a= new S();
S a;
for(int i=0;i<3;i++)
{
for (int j=0;j<n[i]->size();j++)
for (int j=0;j<s.n[i]->size();j++)
{
Shin::NeuronNetwork::Neuron *q;
if(rand()%2==1)
@@ -68,9 +71,9 @@ class S: public Shin::Genetics::Individual
q=n[i]->operator[](j);
}else
{
q=s->n[i]->operator[](j);
q=s.n[i]->operator[](j);
}
a->n[i]->operator[](j)->setPotential(q->getPotential());
a.n[i]->operator[](j)->setPotential(q->getPotential());
int k;
if(i==0)
@@ -80,15 +83,11 @@ class S: public Shin::Genetics::Individual
else
k=3;
for(;k>=0;--k)
a->n[i]->operator[](j)->setWeight(k,q->getWeight(k));
a.n[i]->operator[](j)->setWeight(k,q->getWeight(k));
}
}
return a;
}
Individual* combine(Individual *s)
{
return SQ(dynamic_cast<S*>(s));
}
Shin::NeuronNetwork::FeedForwardNetwork n;
double getFitness()
@@ -113,6 +112,7 @@ class S: public Shin::Genetics::Individual
int main()
{
Shin::Genetics::Genetics<S> g;
S* s=(S*)g.getSolution(99999,999999);
s->dump();
g.addIndividual(S());
S &s=g.getSolution(99999,999999);
s.dump();
}