/// <summary> /// Trains a random trainer. /// </summary> /// <param name="inputs">The inputs.</param> /// <param name="predictWindow">The predict window.</param> public static double RandomTrainerMethod(int inputs, int predictWindow) { double[] firstinput = MakeInputs(inputs); double[] SecondInput = MakeInputs(inputs); double[] ThirdInputs = MakeInputs(inputs); double[] FourthInputs = MakeInputs(inputs); double[] inp5 = MakeInputs(inputs); double[] inp6 = MakeInputs(inputs); var pair = TrainerHelper.ProcessPairs(firstinput, firstinput, inputs, predictWindow); var pair2 = TrainerHelper.ProcessPairs(SecondInput, firstinput, inputs, predictWindow); var pair3 = TrainerHelper.ProcessPairs(ThirdInputs, firstinput, inputs, predictWindow); var pair4 = TrainerHelper.ProcessPairs(FourthInputs, firstinput, inputs, predictWindow); var pair5 = TrainerHelper.ProcessPairs(inp5, firstinput, inputs, predictWindow); var pair6 = TrainerHelper.ProcessPairs(inp6, firstinput, inputs, predictWindow); BasicMLDataSet SuperSet = new BasicMLDataSet(); SuperSet.Add(pair); SuperSet.Add(pair2); SuperSet.Add(pair3); SuperSet.Add(pair4); var network = new BasicNetwork(); network.AddLayer(new BasicLayer(new ActivationTANH(), true, SuperSet.InputSize)); network.AddLayer(new BasicLayer(new ActivationTANH(), false, 20)); network.AddLayer(new BasicLayer(new ActivationTANH(), true, 0)); network.AddLayer(new BasicLayer(new ActivationLinear(), true, predictWindow)); //var layer = new BasicLayer(new ActivationTANH(), true, SuperSet.InputSize); //layer.Network = network; network.Structure.FinalizeStructure(); network.Reset(); // var network = (BasicNetwork)CreateEval.CreateElmanNetwork(SuperSet.InputSize, SuperSet.IdealSize); return(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) { RandomTrainer.RandomTrainerMethod(Convert.ToInt16(app.Args[1]), Convert.ToInt16(app.Args[2])); MakeAPause(); app.Exit(); } else { Console.WriteLine(@"You didn't input enough args in your request, will default to 3000 inputs , and 50 prediction size"); Console.WriteLine(@"Error % " + RandomTrainer.RandomTrainerMethod(3000, 50)); } Console.ReadKey(); return; } 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)NetworkUtility.LoadNetwork(CONFIG.DIRECTORY, CONFIG.NetWorkFile); CreateEval.EvaluateNetworks(network, set); MakeAPause(); return; } } } 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); NetworkUtility.SaveTraining(CONFIG.DIRECTORY, CONFIG.TrainingFile, set); NetworkUtility.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(); app.Exit(); return; } else { Console.WriteLine("Couldnt find the file :" + app.Args[2].ToString()); Console.WriteLine("Exiting"); MakeAPause(); app.Exit(); return; } } } 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(); } }