Пример #1
0
        private static void RunNeat(double[][] inputs, double[][] expectedOutputs, DenormalizationVariables denormalizationVariables)
        {
            Neat neat = new Neat();

            neat.OnGenerationEnd += (a) =>
            {
                Console.WriteLine(">  Gen " + a.Generation + "\tErr: " + a.Error);
            };

            Ann ann = neat.Train(100, 100, 0.03, 2, 30, false, inputs, expectedOutputs, Crossover.TwoPointCrossover, ActivationFunction.Sigmoid);

            double finalError = neat.CalculateError(ann, inputs, expectedOutputs, true);

            Console.WriteLine("Final error: " + finalError);

            int index = 1;

            double normalizedResult = Math.Round(ann.Execute(inputs[index])[0], 2);
            double actualResult     = DataManager.DenormalizeNumeric(normalizedResult, denormalizationVariables.NormalizedFloor, denormalizationVariables.NormalizedCeiling, denormalizationVariables.NumericNormalizationMargin, denormalizationVariables.SmallestTrainingValue, denormalizationVariables.LargestTrainingValue);
            double expectedResult   = DataManager.DenormalizeNumeric(expectedOutputs[index][0], denormalizationVariables.NormalizedFloor, denormalizationVariables.NormalizedCeiling, denormalizationVariables.NumericNormalizationMargin, denormalizationVariables.SmallestTrainingValue, denormalizationVariables.LargestTrainingValue);

            Console.WriteLine($">>> Expected Normalized result: {expectedOutputs[index][0]}");
            Console.WriteLine($">>> Actual Normalized result: {normalizedResult}");
            Console.WriteLine($">>> Expected real result: {expectedResult}");
            Console.WriteLine($">>> Actual real result: {actualResult}");
            Console.WriteLine($">>> Error in USD: {actualResult - expectedResult}");
            Console.WriteLine();
        }