Example #1
0
        public static void RunTestAdder()
        {
            TestAdder               network = new TestAdder();
            Fitness <TestAdder>     fit     = x => x.RunTests();
            EvolSpecies <TestAdder> evol    = new EvolSpecies <TestAdder>(500, 1.0, fit);

            evol.Initialise(network);

            TestAdder best = new TestAdder();

            for (int i = 0; i < MAX_GEN; i++)
            {
                evol.Evolve();
                evol.GetTopSpec(best);

                double fitness = evol.TopFitness;
                int    species = evol.NumSpecies;

                int    nodes = best.NumNurons;
                int    axons = best.NumAxons;
                double fx    = evol.TopFitness;

                Console.WriteLine();
                Console.WriteLine("Generation " + i + ": " + nodes + " " + axons + " " + fx);
                Console.WriteLine("Num Species: " + evol.NumSpecies);
                Console.WriteLine("Threshold: " + evol.Threshold.ToString("0.00"));


                if (fitness > 0.999)
                {
                    Console.WriteLine();
                    Console.WriteLine("#############################################################");
                    Console.WriteLine("TARGET FITNESS REACHED!!!");
                    Console.WriteLine("#############################################################");
                    Console.WriteLine();

                    best.ReduceNetwork();
                    nodes = best.NumNurons;
                    axons = best.NumAxons;
                    fx    = fit(best);

                    Console.WriteLine("Final Network: " + nodes + " " + axons + " " + fx);

                    Console.WriteLine("Press any key...");
                    Console.ReadKey(true);
                    break;
                }

                //Thread.Sleep(500);
            }
        }
Example #2
0
        public static void TestGennetics3()
        {
            GenString target = new GenString(
                "Twas brillig, and the slithy toves did gyer and gimble in the wabe.");
            GenString best = new GenString("Hello");

            Console.WriteLine("Target: " + target);

            Fitness <GenString> fit = delegate(GenString gs)
            {
                double dist = gs.Distance(target);
                //return 1.0 / (dist + 1.0);
                //return -dist;

                dist = 100.0 - dist;
                if (dist < 0.1)
                {
                    dist = 0.1;
                }
                return(dist);
            };

            EvolSpecies <GenString> evol = new EvolSpecies <GenString>(1000, 0.1, fit);

            evol.Initialise(best);

            for (int i = 0; i < MAX_GEN; i++)
            {
                evol.Evolve();
                evol.GetTopSpec(best);

                double fitness = evol.TopFitness;
                int    species = evol.NumSpecies;

                Console.WriteLine();
                Console.WriteLine("Generation " + i + ": " + fitness);
                Console.WriteLine("Num Species: " + species);
                Console.WriteLine(best);

                //Thread.Sleep(500);
            }
        }