Ejemplo n.º 1
0
 public B_Brain(B_Brain Parent1, B_Brain Parent2)
 {
     Neurons    = new B_Neuron[Parent1.Neurons.Length][];
     Neurons[0] = new B_Neuron[Parent1.Neurons[0].Length];
     for (int i = 0; i < Neurons[0].Length; i++)
     {
         Neurons[0][i] = new B_Neuron(RandomParent(Parent1, Parent2).Neurons[0][i]);
     }
     for (int layer = 0; layer < Parent1.Neurons.Length - 2; layer++)
     {
         Neurons[layer + 1] = new B_Neuron[Parent1.Neurons[layer + 1].Length];
         for (int i = 0; i < Parent1.Neurons[layer + 1].Length; i++)
         {
             Neurons[layer + 1][i] = new B_Neuron(RandomParent(Parent1, Parent2).Neurons[layer + 1][i]);
         }
     }
     Neurons[Parent1.Neurons.Length - 1] = new B_Neuron[Parent1.Neurons[Parent1.Neurons.Length - 1].Length];
     for (int i = 0; i < Parent1.Neurons[Parent1.Neurons.Length - 1].Length; i++)
     {
         Neurons[Parent1.Neurons.Length - 1][i] = new B_Neuron(RandomParent(Parent1, Parent2).Neurons[Parent1.Neurons.Length - 1][i]);
     }
     M_NeuronID = Parent1.M_NeuronID;
     for (int layer = 0; layer < Neurons.Length; layer++)
     {
         for (int i = 0; i < Neurons[layer].Length; i++)
         {
             Neurons[layer][i].CloneConnections(this, RandomParent(Parent1, Parent2).Neurons[layer][i]);
         }
     }
 }
Ejemplo n.º 2
0
 public B_Brain(B_Brain clone)
 {
     Neurons    = new B_Neuron[clone.Neurons.Length][];
     Neurons[0] = new B_Neuron[clone.Neurons[0].Length];
     for (int i = 0; i < Neurons[0].Length; i++)
     {
         Neurons[0][i] = new B_Neuron(clone.Neurons[0][i]);
     }
     for (int layer = 0; layer < clone.Neurons.Length - 2; layer++)
     {
         Neurons[layer + 1] = new B_Neuron[clone.Neurons[layer + 1].Length];
         for (int i = 0; i < clone.Neurons[layer + 1].Length; i++)
         {
             Neurons[layer + 1][i] = new B_Neuron(clone.Neurons[layer + 1][i]);
         }
     }
     Neurons[clone.Neurons.Length - 1] = new B_Neuron[clone.Neurons[clone.Neurons.Length - 1].Length];
     for (int i = 0; i < clone.Neurons[clone.Neurons.Length - 1].Length; i++)
     {
         Neurons[clone.Neurons.Length - 1][i] = new B_Neuron(clone.Neurons[clone.Neurons.Length - 1][i]);
     }
     M_NeuronID = clone.M_NeuronID;
     for (int layer = 0; layer < Neurons.Length; layer++)
     {
         for (int i = 0; i < Neurons[layer].Length; i++)
         {
             Neurons[layer][i].CloneConnections(this, clone.Neurons[layer][i]);
         }
     }
 }
Ejemplo n.º 3
0
 public B_Brain RandomParent(B_Brain Parent1, B_Brain Parent2)
 {
     if (GlobalRandom.random.Next(500) % 2 == 0)
     {
         return(Parent1);
     }
     return(Parent2);
 }
Ejemplo n.º 4
0
 public void CloneConnections(B_Brain brain, B_Neuron cloneme)
 {
     connections = new List <B_Connection>(cloneme.connections.Count);
     foreach (B_Connection c in cloneme.connections)
     {
         connections.Add(new B_Connection(brain.getNeuron(c.target.Neuron_Id), c.Weight));
     }
 }