示例#1
0
 static void Main(string[] args)
 {
     Console.WriteLine("---------------------------");
     Console.WriteLine("Evolutive XOR with population wrapper");
     Console.WriteLine("---------------------------");
     // EvoXOR.Run();
     XORPopulation.Run();
     // FactoryExample.Run();
 }
示例#2
0
        // ==============================================
        // Static runner
        // ==============================================

        public static void Run()
        {
            // Generate first population
            XORPopulation pop = new XORPopulation();

            // The record
            float kingFitness = 0;

            CerebroML.Cerebro king = BrainFactory.Create()
                                     .WithWeightBiasAmplitude(10f)
                                     .WithInput(2)
                                     .WithLayer(2, LayerType.Tanh)
                                     .WithLayer(1, LayerType.Sigmoid)
                                     .Build();

            // Iterate until the king has a good fitness
            while (kingFitness < 0.999) // && generation < GENERATION_LIMT)
            {
                pop.Next();

                kingFitness = pop.bestFitness;
                king.SetGenome(pop.best);

                // Write to the console the current king and the average fitness
                if (pop.generationNumber % 250 == 0)
                {
                    Console.WriteLine($"Gen {pop.generationNumber}");
                    Console.WriteLine($"Fitness: King- {kingFitness:0.00} AVG- {pop.GetAVGFitness():0.00}");
                }
            }

            // Show the final results
            if (king != null)
            {
                Console.WriteLine($"FINAL -  Gen: {pop.generationNumber}");
                Console.WriteLine($"Fitness: King- {kingFitness:0.00}");

                Console.WriteLine($" - (0, 0) = {king.Run(new float[] { 0.0f, 0.0f })[0]:0.00}");
                Console.WriteLine($" - (1, 0) = {king.Run(new float[] { 1.0f, 0.0f })[0]:0.00}");
                Console.WriteLine($" - (0, 1) = {king.Run(new float[] { 0.0f, 1.0f })[0]:0.00}");
                Console.WriteLine($" - (1, 1) = {king.Run(new float[] { 1.0f, 1.0f })[0]:0.00}");
            }
        }