Пример #1
0
        /// <summary>
        /// This is where encog network settings are configured and training is being processed.
        /// </summary>
        public static void LogisticTrain()
        {
            Console.WriteLine("\n\nEncog network structure: \nNumber of Input neurons 1 \nNumber of output neurons 9 ");

            int hiddenLayers       = Util.GetInput("Number of hidden layers [default 1]: ", 1);
            int hiddenLayerNeurons = Util.GetInput("Hidden layer neurons [default 100]: ", 100);
            int type       = Util.GetInput("\nSelect a training method [Annealing - 0][Genetic - 1 default]:", 1);
            int numOfEpoch = Util.GetInput("Number of Epochs [default 10]:", 10);

            BasicNetwork network    = CreateNetwork(hiddenLayers, hiddenLayerNeurons);
            var          pilotScore = new EncogLogisticScore();
            IMLTrain     train;

            if (type == 0)
            {
                int startTemp = Util.GetInput("Start Temperature [default 10]:", 10);
                int endTemp   = Util.GetInput("End Temperature [default 2]:", 2);
                int cycles    = Util.GetInput("Cycles [default 10]:", 10);
                train = new NeuralSimulatedAnnealing(network, pilotScore, endTemp, startTemp, cycles);
            }
            else
            {
                int populationSize = Util.GetInput("Population Size [default 10]:", 10);
                train = new MLMethodGeneticAlgorithm(() => {
                    BasicNetwork result = CreateNetwork(hiddenLayers, hiddenLayerNeurons);
                    ((IMLResettable)result).Reset();
                    return(result);
                }, pilotScore, populationSize); // population size
            }

            Stopwatch watch = new Stopwatch();

            watch.Start();
            Console.WriteLine("\n\nTraining: \n");

            for (int i = 0; i < numOfEpoch; i++) // num of epochs
            {
                train.Iteration();

                double totalCosts    = train.Error;
                string currencyScore = totalCosts.ToString("$#,##0");
                Console.WriteLine($"Epoch # {i} \t Score: {currencyScore,10}");
            }

            watch.Stop();

            Console.WriteLine("\nPredicted outputs:");
            network = (BasicNetwork)train.Method;
            var pilot = new EncogLogisticSimulator(network, true);

            pilot.CalculateScore(LogisticSimulator.GenerateCustomerOrders(), true);

            Console.WriteLine($"\nElapsed: {watch.Elapsed}");
            Console.WriteLine("\nThe total number of times it tried the Logistic Simulation for training: " + pilotScore.SessionCnt);
            Console.ReadLine();
        }
Пример #2
0
        public double CalculateScore(IMLMethod network)
        {
            int cnt = Interlocked.Increment(ref sessionCnt);

            EncogLogisticSimulator sim = new EncogLogisticSimulator((BasicNetwork)network, false);
            var score = sim.CalculateScore(CustomerOrders, false);

            Console.WriteLine($"Session #{cnt} \t Score: {Math.Abs(score).ToString("$#,##0")}");

            return(score);
        }