Example #1
0
File: Network.cs Project: alxio/gen
 public Network(Network n)
 {
     for (int i = 0; i < _neurons.Length; i++){
         _neurons[i] = new Neuron[NETWORK_BREADTH];
         for (int j = 0; j < _neurons[i].Length; j++){
             _neurons[i][j] = new Neuron(n._neurons[i][j]);
         }
     }
 }
Example #2
0
File: Evolve.cs Project: alxio/gen
 private bool AddToRated(float rating, Network n)
 {
     try{
         _rated.Add(rating, n);
         return true;
     }
     catch (Exception e){
         return false;
     }
 }
Example #3
0
File: Evolve.cs Project: alxio/gen
 private void Breed()
 {
     for (int i = _survivedSize; i + 1 < _popSize - _freshSize; i += 2){
         int p1 = RandomParentId(INF,true);
         int p2 = RandomParentId(p1,false);
         _population[i] = new Network(_population[p1]);
         _population[i + 1] = new Network(_population[p2]);
         Network.Crossover(_population[i], _population[i + 1]);
     }
     for (int i = _popSize - _freshSize; i < _popSize; i++){
         _population[i] = new Network();
     }
     for (int i = 0; i < _popSize - _freshSize; i++){
         if (Program.RandomGenerator.Next()%100 < _mutationChance){
             _population[i].Mutate();
         }
     }
 }
Example #4
0
File: Network.cs Project: alxio/gen
 public static void Crossover(Network s1, Network s2)
 {
     for (int i = 0; i < s1._neurons.Length; i++){
         for (int j = 0; j < s1._neurons[i].Length; j++){
             var los = Program.RandomGenerator.Next(3);
             switch (los){
                 case 0:
                     break;
                 case 1:
                     var temp = s1._neurons[i][j];
                     s1._neurons[i][j] = s2._neurons[i][j];
                     s2._neurons[i][j] = temp;
                     break;
                 case 2:
                     Neuron.Crossover(s1._neurons[i][j], s2._neurons[i][j]);
                     break;
             }
         }
     }
 }
Example #5
0
File: Evolve.cs Project: alxio/gen
 private void InitPopulation()
 {
     _population = new Network[_popSize];
     for (int i = 0; i < _popSize; i++){
         _population[i] = new Network();
     }
 }
Example #6
0
File: Evolve.cs Project: alxio/gen
 private float RateNetwork(Network network)
 {
     float rating = 0;
     foreach (var test in _tests){
         float eval = network.Calculate(test) - test[0];
         rating += Math.Abs(eval);
     }
     return rating;
 }