Ejemplo n.º 1
0
        public static void DisplayResults(GeneticAlgorithmHandler algorithmHandler)
        {
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("CurrentGeneration: " + algorithmHandler.CurrentGeneration);
            Console.ForegroundColor = ConsoleColor.Gray;

            for (int i = 0; i < TotalNumberOfNetworksToDisplayEachGeneration && i < algorithmHandler.NetworkList.Count; i++)
            {
                int lastCurrentDataSet = 0;
                if (algorithmHandler.CurrentDataSets?.Count > 0)
                {
                    lastCurrentDataSet = algorithmHandler.CurrentDataSets.Last();
                }
                double[] expectedArray = algorithmHandler.ExpectedList[lastCurrentDataSet];
                DisplayResult(algorithmHandler.NetworkList[i], expectedArray);
            }
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            InitializeLists();

            NetworkCreator networkCreator = new NetworkCreator(inputLayerSize, HIDDEN_LAYERSIZE, outputLayerSize, NETWORK_AMOUNT, rand);

            networkList = networkCreator.NetworkList;

            GeneticAlgorithmHandler algorithmHandler = new GeneticAlgorithmHandler(rand, networkList)
            {
                InputList                = inputList,
                ExpectedList             = expectedList,
                MutationChance           = MUTATION_CHANCE,
                MutationRate             = MUTATION_RATE,
                NumberOfNetworksToKeep   = NUMBER_OF_NETWORKS_TO_KEEP,
                NumberOfDataSetsPerCycle = NUMBER_OF_DATASETS_PER_CYCLE,
            };

            NetworkOutputDisplayer.TotalNumberOfNetworksToDisplayEachGeneration = TOTAL_NUMBER_OF_NETWORKS_TO_DISPLAY_EACH_GENERATION;
            NetworkOutputDisplayer.DisplayResults(algorithmHandler);
            for (int i = 0; i < TOTAL_GENERATIONS_TO_CALCULATE; ++i)
            {
                algorithmHandler.IterateNetworks(1);
                NetworkOutputDisplayer.DisplayResults(algorithmHandler);
            }

            Network bestNetwork = algorithmHandler.NetworkList[0];

            while (true)
            {
                Console.WriteLine("Enter a number");
                double[] inputValues    = new double[] { Convert.ToDouble(Console.ReadLine()) };
                double[] expectedValues = new double[] { inputValues[0] % 2 == 0 ? 1 : 0, inputValues[0] % 2 == 1 ? 1 : 0 };
                bestNetwork.SetInputs(inputValues);
                bestNetwork.Propagate();
                NetworkOutputDisplayer.DisplayResult(bestNetwork, expectedValues);
            }
        }