Пример #1
0
        /// <summary>
        /// Trains a random trainer.
        /// </summary>
        /// <param name="inputs">The inputs.</param>
        /// <param name="predictWindow">The predict window.</param>
        public static void RandomTrainerMethod(int inputs, int predictWindow)
        {
            double[]       firstinput   = MakeInputs(inputs);
            double[]       SecondInput  = MakeInputs(inputs);
            double[]       ThirdInputs  = MakeInputs(inputs);
            double[]       FourthInputs = MakeInputs(inputs);
            var            pair         = SuperUtils.ProcessPair(firstinput, FourthInputs, inputs, predictWindow);
            var            pair2        = SuperUtils.ProcessPair(SecondInput, FourthInputs, inputs, predictWindow);
            var            pair3        = SuperUtils.ProcessPair(ThirdInputs, FourthInputs, inputs, predictWindow);
            var            pair4        = SuperUtils.ProcessPair(FourthInputs, FourthInputs, inputs, predictWindow);
            BasicMLDataSet SuperSet     = new BasicMLDataSet();

            SuperSet.Add(pair);
            SuperSet.Add(pair2);
            SuperSet.Add(pair3);
            SuperSet.Add(pair4);
            var    network = (BasicNetwork)CreateEval.CreateElmanNetwork(SuperSet.InputSize, SuperSet.IdealSize);
            double error   = CreateEval.TrainNetworks(network, SuperSet);

            //Lets create an evaluation.
            Console.WriteLine(@"Last error rate on random trainer:" + error);
        }
        public void Execute(IExampleInterface app)
        {
            this.app = app;
            FileInfo dataDir = new FileInfo(Environment.CurrentDirectory);

            if (String.Compare(app.Args[0], "randomtrainer", true) == 0)
            {
                if (app.Args.Length > 1)
                {
                    Encog.Examples.RangeandMarket.RandomTrainer.RandomTrainerMethod(Convert.ToInt16(app.Args[1]), Convert.ToInt16(app.Args[2]));
                }
                else
                {
                    Console.WriteLine(@"You didn't input enough args in your request, will default to 3000 inputs , and 50 prediction size");
                    Encog.Examples.RangeandMarket.RandomTrainer.RandomTrainerMethod(3000, 50);
                    MakeAPause();
                }
            }


            if (String.Compare(app.Args[0], "eval", true) == 0)
            {
                if (app.Args.Length > 0)
                {
                    //We have enough arguments, lets test them.
                    if (File.Exists(app.Args[1]))
                    {
                        BasicMLDataSet set = CreateEval.CreateEvaluationSetAndLoad(app.Args[1], CONFIG.EvalHowMany, CONFIG.EvalStartFrom, CONFIG.Inputs,
                                                                                   CONFIG.Outputs);

                        //create our network.
                        BasicNetwork network =
                            (BasicNetwork)SuperUtils.LoadNetwork(CONFIG.DIRECTORY, CONFIG.NetWorkFile);
                        CreateEval.EvaluateNetworks(network, set);
                        MakeAPause();
                        app.Exit();
                    }
                }
            }



            if (String.Compare(app.Args[0], "prune", true) == 0)
            {
                //Start pruning.
                Console.WriteLine("Starting the pruning process....");

                Prunes.Incremental(new FileInfo(CONFIG.DIRECTORY), CONFIG.NetWorkFile,
                                   CONFIG.TrainingFile);

                MakeAPause();
                app.Exit();
            }
            if (String.Compare(app.Args[0], "train", true) == 0)
            {
                if (app.Args.Length > 0)
                {
                    //We have enough arguments, lets test them.
                    if (File.Exists(app.Args[1]))
                    {
                        //the file exits lets build the training.

                        //create our basic ml dataset.
                        BasicMLDataSet set = CreateEval.CreateEvaluationSetAndLoad(app.Args[1], CONFIG.HowMany, CONFIG.StartFrom, CONFIG.Inputs,
                                                                                   CONFIG.Outputs);

                        //create our network.
                        BasicNetwork network = (BasicNetwork)CreateEval.CreateElmanNetwork(CONFIG.Inputs, CONFIG.Outputs);

                        //Train it..

                        double LastError = CreateEval.TrainNetworks(network, set);

                        Console.WriteLine("NetWork Trained to :" + LastError);
                        SuperUtils.SaveTraining(CONFIG.DIRECTORY, CONFIG.TrainingFile, set);
                        SuperUtils.SaveNetwork(CONFIG.DIRECTORY, CONFIG.NetWorkFile, network);
                        Console.WriteLine("Network Saved to :" + CONFIG.DIRECTORY + " File Named :" +
                                          CONFIG.NetWorkFile);

                        Console.WriteLine("Training Saved to :" + CONFIG.DIRECTORY + " File Named :" +
                                          CONFIG.TrainingFile);
                        MakeAPause();
                    }
                    else
                    {
                        Console.WriteLine("Couldnt find the file :" + app.Args[2].ToString());
                        Console.WriteLine("Exiting");
                        MakeAPause();
                        app.Exit();
                    }
                }
            }
            else
            {
                Console.WriteLine("Couldnt understand your command..");
                Console.WriteLine(
                    "Valid commands are : RandomTrainer or Randomtrainer [inputs] [output] , or Train [File]");
                Console.WriteLine(
                    "Valid commands are : Range Prune, to prune your network.");
                Console.WriteLine(
                    "Valid commands are : Range eval , to evaluate your network.");
                MakeAPause();
                app.Exit();
            }
        }