Exemple #1
0
 public void LoadGenome(ref FileIO.GenomeData data)
 {
     if (data.weights.Count != 0)
     {
         Genome bestGenome = CreateGenomeWithoutWeights();
         bestGenome.Weights = data.weights;
         if (populationGenomes.Count > 0)
         {
             int   worstGenome = 0;
             float fitness     = populationGenomes[0].Fitness;
             for (int i = 1; i < populationGenomes.Count; i++)
             {
                 if (populationGenomes[i].Fitness < fitness)
                 {
                     fitness     = populationGenomes[i].Fitness;
                     worstGenome = i;
                 }
             }
             populationGenomes[worstGenome].Index   = bestGenome.Index;
             populationGenomes[worstGenome].Weights = bestGenome.Weights;
         }
         else
         {
             populationGenomes.Add(bestGenome);
         }
     }
 }
Exemple #2
0
 void InsertBestGenomeInPopulation()
 {
     FileIO.GenomeData data = LoadBestGenome();
     if (data != null)
     {
         geneticAlgorithm.LoadGenome(ref data);
     }
 }
Exemple #3
0
    void SaveBestGenome()
    {
        Genome bestGenome = geneticAlgorithm.GetBestGenome();

        FileIO.GenomeData data = new FileIO.GenomeData(bestGenome.Weights);
        string            path = "BestGenomeWeights-" + data.weights.Count + "_Generation-" + geneticAlgorithm.Generation;

        FileIO.WriteJson(path + ".json", ref data);
    }
Exemple #4
0
 public Genome CreateGenomeFromData(FileIO.GenomeData data)
 {
     if (data.weights.Count != 0)
     {
         Genome bestGenome = CreateGenomeWithoutWeights();
         bestGenome.Weights = data.weights;
         return(bestGenome);
     }
     else
     {
         return(CreateNewGenome());
     }
 }
Exemple #5
0
    void SetupBestGenomes()
    {
        FileIO.GenomeData data          = LoadBestGenome();
        NeuralNetwork     neuralNetwork = new NeuralNetwork();

        if (data != null)
        {
            Genome genome = geneticAlgorithm.CreateGenomeFromData(LoadBestGenome());
            neuralNetwork.SetFromGenomes(genome, neuralNet);
            for (int i = 0; i < nnAgents.Count; i++)
            {
                nnAgents[i].InitializeNeuralNetwork(neuralNetwork);
            }
        }
        else
        {
            for (int i = 0; i < nnAgents.Count; i++)
            {
                neuralNetwork.Create(neuralNet);
                nnAgents[i].InitializeNeuralNetwork(neuralNetwork);
            }
        }
    }