Exemple #1
0
 public void Cross(NeuroNetwork other)
 {
     for (int i = 0; i < HiddenLayers.Count; i++)
     {
         for (int j = 0; j < HiddenLayers[i].Count; j++)
         {
             if (StaticRandom.NextDouble() > 0.5)
             {
                 HiddenLayers[i][j] = other.HiddenLayers[i][j].Copy();
             }
         }
     }
     for (int j = 0; j < Outputs.Count; j++)
     {
         if (StaticRandom.NextDouble() > 0.5)
         {
             Outputs[j] = other.Outputs[j].Copy();
         }
     }
 }
Exemple #2
0
 public static double GetRandomWeight()
 {
     return(StaticRandom.NextDouble() * 2 - 1);
 }
Exemple #3
0
        public void NeuroShake(double rate)
        {
            for (int i = 0; i < HiddenLayers.Count; i++)
            {
                for (int j = 0; j < HiddenLayers[i].Count; j++)
                {
                    for (int w = 0; w < HiddenLayers[i][j].Weights.Length; w++)
                    {
                        if (StaticRandom.NextDouble() < rate)
                        {
                            HiddenLayers[i][j].Weights[w] = GetRandomWeight();
                        }
                    }
                }
            }

            for (int i = 0; i < Outputs.Count; i++)
            {
                for (int w = 0; w < Outputs[i].Weights.Length; w++)
                {
                    if (StaticRandom.NextDouble() < rate)
                    {
                        Outputs[i].Weights[w] = GetRandomWeight();
                    }
                }
            }

            for (int i = 0; i < Memory.Count; i++)
            {
                for (int w = 0; w < Memory[i].Weights.Length; w++)
                {
                    if (StaticRandom.NextDouble() < rate)
                    {
                        Memory[i].Weights[w] = GetRandomWeight();
                    }
                }
            }

            /*for (int i = 0; i < 10 * rate; i++)
             * {
             * if (R.NextDouble() > 0.3)
             * {
             * var j = R.Next(HiddenLayers.Count);
             * var k = R.Next(HiddenLayers[j].Count);
             * var prevLayer = j == 0 ? Inputs : HiddenLayers[j - 1];
             * var l = R.Next(prevLayer.Count);
             * HiddenLayers[j][k].Weights[l] = GetRandomWeight();
             * }
             * else if (R.NextDouble() > 0.5)
             * {
             * var j = R.Next(Memory.Count);
             * var k = R.Next(HiddenLayers[HiddenLayers.Count - 1].Count);
             * Memory[j].Weights[k] = GetRandomWeight();
             * }
             * else
             * {
             * var j = R.Next(Outputs.Count);
             * var k = R.Next(HiddenLayers[HiddenLayers.Count - 1].Count);
             * Outputs[j].Weights[k] = GetRandomWeight();
             * }
             * }*/
        }