Ejemplo n.º 1
0
        public bool measureAgainstArchive(NeatGenome.NeatGenome neatgenome, bool addToPending)
        {
            foreach (IGenome genome in archive)
            {
                double dist = BehaviorDistance.Distance(neatgenome.Behavior, ((NeatGenome.NeatGenome)genome).Behavior);

                if (dist > maxDistSeen)
                {
                    maxDistSeen = dist;
                    Console.WriteLine("Most novel distance: " + maxDistSeen);
                }

                if (dist < archive_threshold)
                {
                    return(false);
                }
            }

            if (addToPending)
            {
                pending_addition.Add(neatgenome);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void merge_together(GenomeList list, int size)
        {
            Console.WriteLine("total count: " + Convert.ToString(list.Count));

            Random     r       = new Random();
            GenomeList newList = new GenomeList();

            List <bool>   dirty   = new List <bool>();
            List <double> closest = new List <double>();

            //set default values
            for (int x = 0; x < list.Count; x++)
            {
                dirty.Add(false);
                closest.Add(Double.MaxValue);
            }
            //now add the first individual randomly to the new population
            int last_added = r.Next() % list.Count;

            dirty[last_added] = true;
            newList.Add(list[last_added]);

            while (newList.Count < size)
            {
                double mostNovel      = 0.0;
                int    mostNovelIndex = 0;
                for (int x = 0; x < list.Count; x++)
                {
                    if (dirty[x])
                    {
                        continue;
                    }
                    double dist_to_last = BehaviorDistance.Distance(((NeatGenome.NeatGenome)list[x]).Behavior,
                                                                    ((NeatGenome.NeatGenome)list[last_added]).Behavior);
                    if (dist_to_last < closest[x])
                    {
                        closest[x] = dist_to_last;
                    }

                    if (closest[x] > mostNovel)
                    {
                        mostNovel      = closest[x];
                        mostNovelIndex = x;
                    }
                }

                dirty[mostNovelIndex] = true;
                newList.Add(new NeatGenome.NeatGenome((NeatGenome.NeatGenome)list[mostNovelIndex], 0));
                last_added = mostNovelIndex;
            }

            measure_against = newList;
        }
Ejemplo n.º 3
0
        public bool measureAgainstArchive(NeatGenome.NeatGenome neatgenome, bool addToPending)
        {
            foreach (IGenome genome in archive)
            {
                if (BehaviorDistance.Distance(neatgenome.Behavior, ((NeatGenome.NeatGenome)genome).Behavior) < archive_threshold)
                {
                    return(false);
                }
            }

            if (addToPending)
            {
                pending_addition.Add(neatgenome);
            }

            return(true);
        }
Ejemplo n.º 4
0
        // Returns the minimum behavioral distance to all individuals in the archive
        public double valueAgainstArchive(IGenome neatgenome)
        {
            double minSoFar = Double.MaxValue;
            double temp;

            foreach (IGenome genome in archive)
            {
                if (genome.Equals(neatgenome))
                {
                    continue;                            // Don't let a genome be tested against itself, or else we'd always return 0
                }
                temp = BehaviorDistance.Distance(((NeatGenome.NeatGenome)neatgenome).Behavior, ((NeatGenome.NeatGenome)genome).Behavior);
                if (temp < minSoFar)
                {
                    minSoFar = temp;
                }
            }
            return(minSoFar);
        }
Ejemplo n.º 5
0
        //measure the novelty of an organism against the fixed population
        public double measureNovelty(NeatGenome.NeatGenome neatgenome)
        {
            double sum = 0.0;

            if (!initialized)
            {
                return(Double.MinValue);
            }

            List <Pair <double, NeatGenome.NeatGenome> > noveltyList = new List <Pair <double, NeatGenome.NeatGenome> >();

            foreach (IGenome genome in measure_against)
            {
                noveltyList.Add(new Pair <double, NeatGenome.NeatGenome>(BehaviorDistance.Distance(((NeatGenome.NeatGenome)genome).Behavior, neatgenome.Behavior), ((NeatGenome.NeatGenome)genome)));
            }
            foreach (IGenome genome in archive)
            {
                noveltyList.Add(new Pair <double, NeatGenome.NeatGenome>(BehaviorDistance.Distance(((NeatGenome.NeatGenome)genome).Behavior, neatgenome.Behavior), ((NeatGenome.NeatGenome)genome)));
//				noveltyList.Add(BehaviorDistance.Distance(((NeatGenome.NeatGenome)genome).Behavior,neatgenome.Behavior));
            }

            //see if we should add this genome to the archive
            measureAgainstArchive(neatgenome, true);

            noveltyList.Sort();
            int nn = nearest_neighbors;

            if (noveltyList.Count < nearest_neighbors)
            {
                nn = noveltyList.Count;
            }
            for (int x = 0; x < nn; x++)
            {
                sum += noveltyList[x].First;
                if (neatgenome.RealFitness > noveltyList[x].Second.RealFitness)
                {
                    neatgenome.competition += 1;
                }
                noveltyList[x].Second.locality += 1;
                // sum+=10000.0; //was 100
            }
            return(Math.Max(sum, EvolutionAlgorithm.MIN_GENOME_FITNESS));
        }
Ejemplo n.º 6
0
        //measure the novelty of an organism against the fixed population
        public double measureNovelty(NeatGenome.NeatGenome neatgenome)
        {
            double sum = 0.0;

            if (!initialized)
            {
                //Console.WriteLine("NOVELTY NOT INITIALIZED"); //JUSTIN: Debug, Remove this!
                return(Double.MinValue);
            }

            List <Pair <double, NeatGenome.NeatGenome> > noveltyList = new List <Pair <double, NeatGenome.NeatGenome> >();

            foreach (IGenome genome in measure_against)
            {
                noveltyList.Add(new Pair <double, NeatGenome.NeatGenome>(BehaviorDistance.Distance(((NeatGenome.NeatGenome)genome).Behavior, neatgenome.Behavior), ((NeatGenome.NeatGenome)genome)));
            }

            /*foreach(IGenome genome in archive) //JUSTIN: Deciding not to use the archive in the neighborhood. Hope this helps?
             * {
             *  noveltyList.Add(new Pair<double,NeatGenome.NeatGenome>(BehaviorDistance.Distance(((NeatGenome.NeatGenome)genome).Behavior,neatgenome.Behavior),((NeatGenome.NeatGenome)genome)));
             * //				noveltyList.Add(BehaviorDistance.Distance(((NeatGenome.NeatGenome)genome).Behavior,neatgenome.Behavior));
             * }//*/
            //Console.WriteLine("NOVELTYLIST SIZE: " + noveltyList.Count + " m_a: " + measure_against.Count + " archive: " + archive.Count);

            //see if we should add this genome to the archive
            if (usingProbabilisticArchive)
            {
                probabalisticMeasureAgainstArchive(neatgenome);
            }
            else
            {
                measureAgainstArchive(neatgenome, true);
            }

            noveltyList.Sort();
            int nn = nearest_neighbors;

            if (noveltyList.Count < nearest_neighbors)
            {
                nn = noveltyList.Count;
            }
            for (int x = 0; x < nn; x++)
            {
                sum += noveltyList[x].First;
                if (neatgenome.RealFitness == 0 || noveltyList[x].Second.RealFitness == 0)
                {
                    Console.WriteLine("WARNING! SOMEBODY IS ZERO!");
                }
                if (neatgenome.RealFitness > noveltyList[x].Second.RealFitness)
                {
                    neatgenome.competition += 1;
                    //Console.WriteLine(neatgenome.RealFitness + " > " + (noveltyList[x].Second).RealFitness + " so incrementing competition");
                }
                //if (neatgenome.objectives[neatgenome.objectives.Length - 1] > noveltyList[x].Second.objectives[neatgenome.objectives.Length - 1])
                //neatgenome.localGenomeNovelty += 1;
                if (neatgenome.geneticDiversity > noveltyList[x].Second.geneticDiversity)
                {
                    neatgenome.localGenomeNovelty += 1;
                    //Console.WriteLine("localGenomeNovelty: " + neatgenome.geneticDiversity + " > " + noveltyList[x].Second.geneticDiversity);
                }
                noveltyList[x].Second.locality += 1;
                neatgenome.nearestNeighbors++;
                // sum+=10000.0; //was 100
            }
            return(Math.Max(sum, EvolutionAlgorithm.MIN_GENOME_FITNESS));
        }
Ejemplo n.º 7
0
        //measure the novelty of an organism against the fixed population
        public double measureNovelty(NeatGenome.NeatGenome neatgenome)
        {
            double sum = 0.0;

            if (!initialized)
            {
                return(Double.MinValue);
            }

            List <Pair <double, NeatGenome.NeatGenome> > noveltyList = new List <Pair <double, NeatGenome.NeatGenome> >();

            foreach (IGenome genome in measure_against)
            {
                noveltyList.Add(new Pair <double, NeatGenome.NeatGenome>(BehaviorDistance.Distance(((NeatGenome.NeatGenome)genome).Behavior, neatgenome.Behavior), ((NeatGenome.NeatGenome)genome)));
            }
            foreach (IGenome genome in archive)
            {
                noveltyList.Add(new Pair <double, NeatGenome.NeatGenome>(BehaviorDistance.Distance(((NeatGenome.NeatGenome)genome).Behavior, neatgenome.Behavior), ((NeatGenome.NeatGenome)genome)));
//				noveltyList.Add(BehaviorDistance.Distance(((NeatGenome.NeatGenome)genome).Behavior,neatgenome.Behavior));
            }

            //see if we should add this genome to the archive
            measureAgainstArchive(neatgenome, true);

            noveltyList.Sort();
            int nn = nearest_neighbors;

            if (noveltyList.Count < nearest_neighbors)
            {
                nn = noveltyList.Count;
            }
            neatgenome.nearestNeighbors = nn;

            //Paul - reset local competition and local genome novelty -- might have been incrementing over time
            neatgenome.competition        = 0;
            neatgenome.localGenomeNovelty = 0;

            for (int x = 0; x < nn; x++)
            {
                sum += noveltyList[x].First;

                if (neatgenome.RealFitness > noveltyList[x].Second.RealFitness)
                {
                    neatgenome.competition += 1;
                }

                if (neatgenome.objectives[neatgenome.objectives.Length - 1] > noveltyList[x].Second.objectives[neatgenome.objectives.Length - 1])
                {
                    neatgenome.localGenomeNovelty += 1;
                }

                noveltyList[x].Second.locality += 1;
                // sum+=10000.0; //was 100
            }
            //neatgenome.locality = 0;
            //for(int x=0;x<nn;x++)
            //{
            //    sum+=noveltyList[x].First;

            //    if(neatgenome.RealFitness>noveltyList[x].Second.RealFitness)
            //        neatgenome.competition+=1;

            //    noveltyList[x].Second.locality+=1;
            //    //Paul: This might not be the correct meaning of locality, but I am hijacking it instead
            //    //count how many genomes we are neighbored to
            //    //then, if we take neatgenome.competition/neatgenome.locality - we get percentage of genomes that were beaten locally!
            //    neatgenome.locality += 1;
            //    // sum+=10000.0; //was 100
            //}
            return(Math.Max(sum, EvolutionAlgorithm.MIN_GENOME_FITNESS));
        }