Beispiel #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]);
         }
     }
 }
Beispiel #2
0
        public B_Brain(int inputCount, int outputCount, int numberOfIntermediateLayers, int intermediateLayerCount)
        {
            int nid = 0;

            Neurons    = new B_Neuron[numberOfIntermediateLayers + 2][];
            Neurons[0] = new B_Neuron[inputCount];
            for (int i = 0; i < inputCount; i++)
            {
                Neurons[0][i] = new B_Neuron(nid++);
            }
            for (int layer = 0; layer < numberOfIntermediateLayers; layer++)
            {
                Neurons[layer + 1] = new B_Neuron[intermediateLayerCount];
                for (int i = 0; i < intermediateLayerCount; i++)
                {
                    Neurons[layer + 1][i] = new B_Neuron(nid++);
                }
            }
            Neurons[numberOfIntermediateLayers + 1] = new B_Neuron[outputCount];
            for (int i = 0; i < outputCount; i++)
            {
                Neurons[numberOfIntermediateLayers + 1][i] = new B_Neuron(nid++);
            }
            for (int layer = 1; layer < Neurons.Length; layer++)
            {
                for (int i = 0; i < Neurons[layer - 1].Length; i++)
                {
                    for (int j = 0; j < Neurons[layer].Length; j++)
                    {
                        Neurons[layer][j].AddConnection(Neurons[layer - 1][i], GlobalRandom.NextBetween(-1, 1));
                    }
                }
            }
            M_NeuronID = nid;
        }
Beispiel #3
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]);
         }
     }
 }
Beispiel #4
0
 public B_Neuron(B_Neuron cloneme)
 {
     connections = new List <B_Connection>(cloneme.connections.Count);
     Neuron_Id   = cloneme.Neuron_Id;
     Value       = 0;
     hasValue    = false;
 }
Beispiel #5
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));
     }
 }
Beispiel #6
0
        public void Mutate(double cAdjust, int mCV)
        {
            int      tgt    = GlobalRandom.random.Next(M_NeuronID);
            B_Neuron target = getNeuron(tgt);

            if (target.connections.Count > 0)
            {
                B_Connection adjc = target.connections[GlobalRandom.random.Next(target.connections.Count)];
                adjc.Weight += GlobalRandom.NextBetween(-cAdjust, cAdjust);
                adjc.Weight  = MathHelper.Clamp((float)adjc.Weight, -mCV, mCV);
            }
        }
Beispiel #7
0
 public B_Connection(B_Neuron n, double v)
 {
     target = n;
     Weight = v;
 }
Beispiel #8
0
 public void AddConnection(B_Neuron neuron, double amt)
 {
     connections.Add(new B_Connection(neuron, amt));
 }