Beispiel #1
0
 /// <summary>
 /// Transfer genomes from GenomeList into GenomeById.
 /// </summary>
 public void LoadWorkingDictionary()
 {
     GenomeById.Clear();
     foreach (var genome in GenomeList)
     {
         GenomeById.Add(genome.Id, genome);
     }
     GenomeList.Clear();
 }
Beispiel #2
0
        public void addPending(bool suppressThresholdUpdate = false)
        {
            int length = pending_addition.Count;


            if (!suppressThresholdUpdate)
            {
                if (length == 0)
                {
                    archive_threshold *= 0.95;
                }
                if (length > 5)
                {
                    archive_threshold *= 1.3;
                }
            }

            for (int i = 0; i < length; i++)
            {
                if (measureAgainstArchive((NeatGenome.NeatGenome)pending_addition[i], false))
                {
                    archive.Add(pending_addition[i]);
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter("NoveltyLog.txt", true))
                        file.WriteLine(pending_addition[i].Fitness);

                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(Chromaria.Modes.NoveltySearchRun.noveltyLogsFolder + "archive.txt", true))
                    {
                        // Write the genome's info to the novelty log
                        file.WriteLine("ID: " + pending_addition[i].GenomeId);
                        file.WriteLine("Fitness: " + pending_addition[i].Fitness);
                        file.Write("Behavior: ");
                        foreach (double behavior in pending_addition[i].Behavior.behaviorList)
                        {
                            file.Write(behavior.ToString() + ", ");
                        }
                        file.WriteLine();
                        file.WriteLine();
                    }

                    // Also print out the genome itself
                    XmlDocument doc = new XmlDocument();
                    XmlGenomeWriterStatic.Write(doc, (NeatGenome.NeatGenome)pending_addition[i]);
                    FileInfo oFileInfo = new FileInfo(Chromaria.Modes.NoveltySearchRun.noveltyLogsFolder + "genome" + pending_addition[i].GenomeId + ".xml");
                    doc.Save(oFileInfo.FullName);
                }
            }
            pending_addition.Clear();
        }
        public void addPending()
        {
            int length = pending_addition.Count;

            if (length == 0)
            {
                archive_threshold *= 0.95;
            }
            if (length > 5)
            {
                archive_threshold *= 1.3;
            }

            for (int i = 0; i < length; i++)
            {
                if (measureAgainstArchive((NeatGenome.NeatGenome)pending_addition[i], false))
                {
                    archive.Add(pending_addition[i]);
                }
            }
            pending_addition.Clear();
        }
Beispiel #4
0
 /// <summary>
 /// Transfer genomes from GenomeById into GenomeList.
 /// </summary>
 public void FlushWorkingDictionary()
 {
     GenomeList.Clear();
     GenomeList.AddRange(GenomeById.Values);
     GenomeById.Clear();
 }
Beispiel #5
0
        public void addPending(bool suppressThresholdUpdate = false)
        {
            int length = pending_addition.Count;

            if (usingProbabilisticArchive)
            { // Do something different for probabilistic archive. No thresholds involved. Just add everyone that is pending.
                if (!probTournament)
                {
                    for (int i = 0; i < length; i++)
                    {
                        archive.Add(pending_addition[i]);
                    }
                    pending_addition.Clear();
                    Console.WriteLine("Added " + length + " to the archive. Current size: " + archive.Count);
                }
                else
                { // Hold a diversity tournament to decide to gets added to the archive
                    int    countThem  = 0;
                    double averageAdd = 0;
                    for (int i = 0; i + 1 < length; i = i + 2)
                    {
                        double first  = valueAgainstArchive(pending_addition[i]);
                        double second = valueAgainstArchive(pending_addition[i + 1]);
                        if (first > second)
                        {
                            archive.Add(pending_addition[i]);
                            averageAdd += first;
                        }
                        else
                        {
                            archive.Add(pending_addition[i + 1]);
                            averageAdd += second;
                        }
                        countThem++;
                    }
                    // The straggler is almost never added... need a more fair method of adding stragglers. Maybe give them an early tournament against someone random?

                    /*if (length % 2 == 1) // The last one was not considered if there was an odd number in the list. We should consider it against the average.
                     * {
                     *  if (countThem != 0)
                     *  {
                     *      averageAdd /= countThem;
                     *      if (valueAgainstArchive(pending_addition[length - 1]) > averageAdd)
                     *      {
                     *          Console.WriteLine("Straggler added! " + valueAgainstArchive(pending_addition[length - 1]) + " beats avg " + averageAdd);
                     *          archive.Add(pending_addition[length - 1]);
                     *      }
                     *      else
                     *      {
                     *          Console.WriteLine("Straggler not added. " + valueAgainstArchive(pending_addition[length - 1]) + " loses to avg " + averageAdd);
                     *      }
                     *  }
                     * }//*/
                    pending_addition.Clear();
                    Console.WriteLine("Added " + countThem + " (" + length + ") to the archive. Current size: " + archive.Count);
                }
            }
            else
            {
                if (!suppressThresholdUpdate)
                {
                    if (length == 0)
                    {
                        archive_threshold *= 0.95;
                        Console.WriteLine("Decreasing threshold. New: " + archive_threshold + ", adding " + length + " to archive. (" + archive.Count + ")");
                    }
                    if (length > 5)
                    {
                        archive_threshold *= 1.3;
                        Console.WriteLine("Increasing threshold. New: " + archive_threshold + ", adding " + length + " to archive. (" + archive.Count + ")");
                    }
                }

                for (int i = 0; i < length; i++)
                {
                    if (measureAgainstArchive((NeatGenome.NeatGenome)pending_addition[i], false))
                    {
                        archive.Add(pending_addition[i]);
                    }
                }
                pending_addition.Clear();
            }

            if (enforceArchiveLimit)
            {
                if (probDeletionTournament)
                {
                    // Check the archive against the size limit and if it exceeds the limit, run a tournament to delete members
                    while (archive.Count > archiveSizeLimit)
                    {
                        int firstIdx  = archiveAddingRNG.Next(archive.Count);
                        int secondIdx = firstIdx;
                        while (firstIdx == secondIdx) // Make sure the indexes are unique
                        {
                            secondIdx = archiveAddingRNG.Next(archive.Count);
                        }
                        // Evaluate the candidate victims against the archive
                        double first  = valueAgainstArchive(archive[firstIdx]);
                        double second = valueAgainstArchive(archive[secondIdx]);
                        // Remove the one with the lower novelty score
                        if (first < second)
                        {
                            archive.RemoveAt(firstIdx);
                            //Console.WriteLine(first + " vs " + second + " : removing first.");
                        }
                        else
                        {
                            archive.RemoveAt(secondIdx);
                            //Console.WriteLine(first + " vs " + second + " : removing second.");
                        }
                    }
                }
                else // No tournament, just delete randomly
                {
                    while (archive.Count > archiveSizeLimit)
                    {
                        int firstIdx = archiveAddingRNG.Next(archive.Count);
                        // Evaluate the candidate victims against the archive
                        double first = valueAgainstArchive(archive[firstIdx]);
                        archive.RemoveAt(firstIdx);
                    }
                }
            }
        }