/// <summary> /// Run this instance. /// </summary> public static void Run() { _TestNetworkStructure = new Network(); BuildStructure(); _TestNetworkStructure.RandomiseWeights(0.3d); PrepData(); Int32 epoch = 0; Boolean Continue = true; while (Continue) { Continue = false; epoch++; // No need to fully clear the screen constantly if (epoch%200 == 0) Console.Clear(); Console.SetCursorPosition(0, 0); Console.WriteLine("XOR3Test"); for (Int32 x = 0; x < 8; x++) { PresentData(x); ForwardPass(); ReversePass(x); if (x == 0 && _OutputLayer.GetNodes()[0].GetValue() > 0.02f) Continue = true; if (x > 0 && x < 7 && _OutputLayer.GetNodes()[0].GetValue() < 0.98f) Continue = true; if (x == 7 && _OutputLayer.GetNodes()[0].GetValue() > 0.02f) Continue = true; Console.WriteLine(_InputLayer.GetNodes()[0].GetValue() + "-" + _InputLayer.GetNodes()[1].GetValue() + "-" + _InputLayer.GetNodes()[2].GetValue() + " - " + Math.Round(_OutputLayer.GetNodes()[0].GetValue(), 2)); } } Console.WriteLine("Training complete in " + epoch + " epochs"); Console.ReadKey(); }
/// <summary> /// Run this instance. /// </summary> public static void Run() { _TestNetworkStructure = new Network(); BuildStructure(); _TestNetworkStructure.RandomiseWeights(0.9d); PrepData(); Int32 epoch = 0; Boolean Continue = true; while (Continue) { Continue = false; epoch++; Console.Clear(); Console.WriteLine("XOR2Test"); for (Int32 x = 0; x < 4; x++) { PresentData(x); ForwardPass(); ReversePass(x); if (x == 0 && _OutputLayer.GetNodes()[0].GetValue() > 0.02f) Continue = true; if ((x == 1 || x == 2) && _OutputLayer.GetNodes()[0].GetValue() < 0.98f) Continue = true; if (x == 3 && _OutputLayer.GetNodes()[0].GetValue() > 0.02f) Continue = true; Console.WriteLine(_InputLayer.GetNodes()[0].GetValue() + "-" + _InputLayer.GetNodes()[1].GetValue() + " - " + Math.Round(_OutputLayer.GetNodes()[0].GetValue(), 3)); } } Console.WriteLine("Training complete in " + epoch + " epochs"); Console.ReadKey(); }
/// <summary> /// Initializes a new instance of the <see cref="Activity.Testing.Base" /> class, for use by the serialiser. /// </summary> protected Base(SerializationInfo info, StreamingContext context) : base(info, context) { _InputNodes = (List<Structure.Node.Base>)info.GetValue("_InputNodes", typeof(List<Structure.Node.Base>)); _OutputNodes = (List<Structure.Node.Base>)info.GetValue("_OutputNodes", typeof(List<Structure.Node.Base>)); _Recurrentlayers = (List<Structure.Layer.Base>)info.GetValue("_Recurrentlayers", typeof(List<Structure.Layer.Base>)); _TargetNetwork = (Network)info.GetValue("_TargetNetwork", typeof(Network)); }
/// <summary> /// Run this instance. /// </summary> public static void Run() { //Build Network _TestNetworkStructure = new Network(); BuildStructure(); _TestNetworkStructure.SaveToFile("test.dat"); _TestNetworkStructure.RandomiseWeights(1.1d); //PrepData Double[][] dataSet = StandardDeviationVariance.ProduceDataset("TestData/Mackey-Glass-Pure.csv").DataSet; //Prepare training activity _SlidingWindowTraining = new SlidingWindow(); _SlidingWindowTraining.SetTargetNetwork(_TestNetworkStructure); _SlidingWindowTraining.SetMomentum(0.5f); _SlidingWindowTraining.SetLearningRate(0.004f); _SlidingWindowTraining.SetDatasetReservedLength(120); _SlidingWindowTraining.SetDistanceToForcastHorrison(3); _SlidingWindowTraining.SetWindowWidth(12); _SlidingWindowTraining.SetMaximumEpochs(1000); _SlidingWindowTraining.SetInputNodes(_InputLayerNodes); _SlidingWindowTraining.SetOutputNodes(_OuputLayerNodes); _SlidingWindowTraining.SetWorkingDataset(dataSet); _SlidingWindowTraining.SetRecurrentConextLayers(new List<Base>()); Console.WriteLine("Starting Training"); _SlidingWindowTraining.Start(); Thread.Sleep(1000); while (_SlidingWindowTraining.IsRunning()) Thread.Sleep(20); Console.WriteLine("Complete Training"); Console.WriteLine("Starting Testing"); Activity.Testing.SlidingWindow slidingWindowTesting = new Activity.Testing.SlidingWindow(); slidingWindowTesting.SetDatasetReservedLength(0); slidingWindowTesting.SetInputNodes(_SlidingWindowTraining.GetTargetNetwork().GetDetectedBottomLayers()[0].GetNodes().ToList()); slidingWindowTesting.SetOutputNodes(_SlidingWindowTraining.GetTargetNetwork().GetDetectedTopLayers()[0].GetNodes().ToList()); slidingWindowTesting.SetRecurrentConextLayers(new List<Base>()); slidingWindowTesting.SetWorkingDataset(dataSet); slidingWindowTesting.SetWindowWidth(6); slidingWindowTesting.SetDistanceToForcastHorrison(3); slidingWindowTesting.SetTargetNetwork(_SlidingWindowTraining.GetTargetNetwork()); Activity.Testing.SlidingWindow.SlidingWindowTestResults result = (Activity.Testing.SlidingWindow.SlidingWindowTestResults) slidingWindowTesting.TestNetwork(); Console.WriteLine(result.Rmse); Functions.PrintArrayToFile(result.ActualOutputs, "ActualOutputs.csv"); Functions.PrintArrayToFile(result.ExpectedOutputs, "ExpectedOutputs.csv"); Console.WriteLine("Complete Testing"); Console.WriteLine("Comparing Against Random Walk 3 Step"); Console.WriteLine(Math.Round(RandomWalkCompare.CalculateError(result.ExpectedOutputs, result.ActualOutputs, 3)[0]*100, 3)); Console.WriteLine("Comparing Against Random Walk 2 Step"); Console.WriteLine(Math.Round(RandomWalkCompare.CalculateError(result.ExpectedOutputs, result.ActualOutputs, 2)[0]*100, 3)); Console.WriteLine("Comparing Against Random Walk 1 Step"); Console.WriteLine(Math.Round(RandomWalkCompare.CalculateError(result.ExpectedOutputs, result.ActualOutputs, 1)[0]*100, 3)); Console.ReadKey(); }
protected Base(SerializationInfo info, StreamingContext context) : base(info, context) { _CurrentEpoch = info.GetInt32("_CurrentEpoch"); _DynamicLearningRate = (DynamicVariable) info.GetValue("_DynamicLearningRate", typeof (DynamicVariable)); _DynamicMomentum = (DynamicVariable) info.GetValue("_DynamicMomentum", typeof (DynamicVariable)); _MaxEpochs = info.GetInt32("_MaxEpochs"); _TargetNetwork = (Network) info.GetValue("_TargetNetwork", typeof (Network)); _WorkingDataset = (Double[][]) info.GetValue("_WorkingDataset", typeof (Double[][])); }
/// <summary> /// Builds the structure of the neural network ready for training and testing /// </summary> public static void BuildStructure(Base inputLayer, Base outputLayer, List<Structure.Node.Base> inputLayerNodes, List<Structure.Node.Base> ouputLayerNodes, Network testNetworkStructure) { for (Int32 i = 0; i < 1; i++) inputLayerNodes.Add(new Structure.Node.Base(inputLayer, new Elliott())); inputLayer.SetNodes(inputLayerNodes); EchoReservoir echoLayer = new EchoReservoir(130, 0.4f, 0, 5, new Elliott()); for (Int32 i = 0; i < 1; i++) ouputLayerNodes.Add(new Output(outputLayer, new Elliott())); outputLayer.SetNodes(ouputLayerNodes); inputLayer.ConnectFowardLayer(echoLayer); echoLayer.ConnectFowardLayer(outputLayer); testNetworkStructure.AddLayer(inputLayer); testNetworkStructure.AddLayer(echoLayer); testNetworkStructure.AddLayer(outputLayer); foreach (Base layer in testNetworkStructure.GetCurrentLayers()) layer.PopulateNodeConnections(); }
/// <summary> /// Run this instance. /// </summary> public static void Run() { Double[][] dataSet = StandardDeviationVariance.ProduceDataset("TestData/Mackey-Glass-Pure.csv").DataSet; List<Guid> outstandingWork = new List<Guid>(); CommsClient lobeConnection = new CommsClient(); lobeConnection.ConnectToManager("localhost", 17432); for (Int32 x = 0; x < 20; x++) { Network testNetworkStructure; SlidingWindow slidingWindowTraining; Base inputLayer = new Base(); ; Base outputLayer = new Base(); ; List<Structure.Node.Base> inputLayerNodes = new List<Structure.Node.Base>(); List<Structure.Node.Base> ouputLayerNodes = new List<Structure.Node.Base>(); //Build Network testNetworkStructure = new Network(); BuildStructure(inputLayer, outputLayer, inputLayerNodes, ouputLayerNodes, testNetworkStructure); testNetworkStructure.SaveToFile("test.dat"); testNetworkStructure.RandomiseWeights(1.1d); //PrepData //Prepare training activity slidingWindowTraining = new SlidingWindow(); slidingWindowTraining.SetTargetNetwork(testNetworkStructure); slidingWindowTraining.SetMomentum(0.5f); slidingWindowTraining.SetLearningRate(0.004f); slidingWindowTraining.SetDatasetReservedLength(0); slidingWindowTraining.SetDistanceToForcastHorrison(3); slidingWindowTraining.SetWindowWidth(12); slidingWindowTraining.SetMaximumEpochs(100); slidingWindowTraining.SetInputNodes(inputLayerNodes); slidingWindowTraining.SetOutputNodes(ouputLayerNodes); slidingWindowTraining.SetWorkingDataset(dataSet); slidingWindowTraining.SetRecurrentConextLayers(new List<Base>()); outstandingWork.Add(lobeConnection.SendJob(slidingWindowTraining)); } while (outstandingWork.Count > 0) { Thread.Sleep(1000); List<Guid> tempList = new List<Guid>(outstandingWork); foreach (Guid guid in tempList) { SlidingWindow work = (SlidingWindow) lobeConnection.GetCompletedWork(guid); if (work == null) continue; outstandingWork.Remove(guid); Console.WriteLine("Starting Testing"); Activity.Testing.SlidingWindow slidingWindowTesting = new Activity.Testing.SlidingWindow(); slidingWindowTesting.SetDatasetReservedLength(0); slidingWindowTesting.SetInputNodes(work.GetTargetNetwork().GetDetectedBottomLayers()[0].GetNodes().ToList()); slidingWindowTesting.SetOutputNodes(work.GetTargetNetwork().GetDetectedTopLayers()[0].GetNodes().ToList()); slidingWindowTesting.SetRecurrentConextLayers(new List<Base>()); slidingWindowTesting.SetWorkingDataset(dataSet); slidingWindowTesting.SetWindowWidth(12); slidingWindowTesting.SetDistanceToForcastHorrison(3); slidingWindowTesting.SetTargetNetwork(work.GetTargetNetwork()); Activity.Testing.SlidingWindow.SlidingWindowTestResults result = (Activity.Testing.SlidingWindow.SlidingWindowTestResults) slidingWindowTesting.TestNetwork(); Console.WriteLine(result.Rmse); Functions.PrintArrayToFile(result.ActualOutputs, "ActualOutputs.csv"); Functions.PrintArrayToFile(result.ExpectedOutputs, "ExpectedOutputs.csv"); Console.WriteLine("Complete Testing"); Console.WriteLine("Comparing Against Random Walk 3 Step"); Console.WriteLine(Math.Round(RandomWalkCompare.CalculateError(result.ExpectedOutputs, result.ActualOutputs, 3)[0]*100, 3)); Console.WriteLine("Comparing Against Random Walk 2 Step"); Console.WriteLine(Math.Round(RandomWalkCompare.CalculateError(result.ExpectedOutputs, result.ActualOutputs, 2)[0]*100, 3)); Console.WriteLine("Comparing Against Random Walk 1 Step"); Console.WriteLine(Math.Round(RandomWalkCompare.CalculateError(result.ExpectedOutputs, result.ActualOutputs, 1)[0]*100, 3)); } } //////////////////////////////////////////////// //////////////////////////////////////////////// Console.WriteLine("all Jobs Done"); Console.ReadKey(); }
/// <summary> /// Sets the target network. /// </summary> /// <param name='targetNetwork'> /// Target network. /// </param> public virtual void SetTargetNetwork(Network targetNetwork) { _TargetNetwork = targetNetwork; }
/// <summary> /// Run this instance. /// </summary> public static void Run() { //Build Network _TestNetworkStructure = new Network(); BuildStructure(); _TestNetworkStructure.RandomiseWeights(0.5f); //PrepData Double[][] dataSet = BuildDataSet(3000); //Prepare training activity _SlidingWindowTraining = new AdaptedSlidingWindowTraining(); _SlidingWindowTraining.SetTargetNetwork(_TestNetworkStructure); _SlidingWindowTraining.SetMomentum(0.8f); _SlidingWindowTraining.SetLearningRate(0.05f); _SlidingWindowTraining.SetDatasetReservedLength(0); _SlidingWindowTraining.SetDistanceToForcastHorrison(0); _SlidingWindowTraining.SetWindowWidth(300); _SlidingWindowTraining.SetMaximumEpochs(1000); _SlidingWindowTraining.SetInputNodes(_InputLayerNodes); _SlidingWindowTraining.SetOutputNodes(_OuputLayerNodes); _SlidingWindowTraining.SetWorkingDataset(dataSet); _SlidingWindowTraining.SetOutputToTarget(false); _SlidingWindowTraining.SetRecurrentConextLayers(new List<Base>() { _RecurrentLayer }); Console.WriteLine("Starting Training"); _SlidingWindowTraining.Start(); Thread.Sleep(1000); while (_SlidingWindowTraining.IsRunning()) Thread.Sleep(20); Console.WriteLine("Complete Training"); Console.WriteLine("Starting Testing"); foreach (Structure.Node.Base node in _TestNetworkStructure.GetCurrentLayers().SelectMany(layer => layer.GetNodes())) node.SetValue(0); Double[] input = new Double[1000]; Double[] output = new Double[1000]; Single frequency = 0.5f; for (Int32 x = 0; x < 1000; x++) { if (x%100 == 0) frequency = 0.5f; // input[x] = frequency; _InputLayerNodes[0].SetValue(frequency); _TestNetworkStructure.FowardPass(); _RecurrentLayer.UpdateExtra(); output[x] = _OuputLayerNodes[0].GetValue(); } Functions.PrintArrayToFile(input, "intput.csv"); Functions.PrintArrayToFile(output, "output.csv"); Console.WriteLine("Complete Testing"); Console.ReadKey(); }
/// <summary> /// Run this instance. /// </summary> public static void Run() { _TestNetworkStructure = new Network(); BuildStructure(); _TestNetworkStructure.RandomiseWeights(1); PrepData(); Int32 epoch = 0; Boolean Continue = true; while (Continue) { Continue = false; epoch++; // No need to update the screen constantly if (epoch%100 == 0) { Console.Clear(); Console.WriteLine("RNNTest2"); } for (Int32 x = 0; x < 8; x++) { foreach (Structure.Node.Base n in _ContextLayer.GetNodes()) n.SetValue(0); for (Int32 i = 0; i < 3; i++) { _InputLayer.GetNodes()[0].SetValue(_InputData[(x*3) + i]); ForwardPass(); _ContextLayer.UpdateExtra(); } ReversePass(x); if (x == 0 && _OutputLayer.GetNodes()[0].GetValue() > 0.02f) Continue = true; if (x > 0 && x < 7 && _OutputLayer.GetNodes()[0].GetValue() < 0.98f) Continue = true; if (x == 7 && _OutputLayer.GetNodes()[0].GetValue() > 0.02f) Continue = true; if (epoch%100 == 0) Console.WriteLine(_InputData[x*3] + "-" + _InputData[(x*3) + 1] + "-" + _InputData[(x*3) + 2] + " - " + Math.Round(_OutputLayer.GetNodes()[0].GetValue(), 2)); } } Console.WriteLine("Training complete in " + epoch + " epochs"); Console.ReadKey(); }
/// <summary> /// Run this instance. /// </summary> public static void Run() { //Build Network _TestNetworkStructure = new Network(); BuildStructure(); _TestNetworkStructure.RandomiseWeights(0.01d); //PrepData Double[][] dataSet = StandardDeviationVariance.ProduceDataset("TestData/Mackey-Glass-Pure.csv").DataSet; //Prepare training activity _SlidingWindowTraining = new SlidingWindow(); _SlidingWindowTraining.SetTargetNetwork(_TestNetworkStructure); // the target network for the training to take place on _SlidingWindowTraining.SetMomentum(0.7f); // The ammount of the previous weight change applied to current weight change - google if u need to know more _SlidingWindowTraining.SetLearningRate(0.004f); // The rate at which the neural entwork learns (the more agressive this is the harded itll be for the network) _SlidingWindowTraining.SetDatasetReservedLength(0); // How many elements off the end of the dataset should not be used for training _SlidingWindowTraining.SetDistanceToForcastHorrison(3); // How far beyond the window should be be trying to predict _SlidingWindowTraining.SetWindowWidth(12); // The window of elements that should be presented before the backward pass is performed _SlidingWindowTraining.SetMaximumEpochs(300); // The maximum number of epochs the network can train for _SlidingWindowTraining.SetInputNodes(_InputLayerNodes); // Setting the nodes that are used for input _SlidingWindowTraining.SetOutputNodes(_OuputLayerNodes); // Setting the nodes that are generating output _SlidingWindowTraining.SetWorkingDataset(dataSet); // Setting the working dataset for the training phase _SlidingWindowTraining.SetDynamicLearningRateDelegate(DynamicLearningRate); // Sets the contect layers that are used as part of the training (have to updates) List<Base> contextLayers = new List<Base> {_ContextLayer}; _SlidingWindowTraining.SetRecurrentConextLayers(contextLayers); //////////////////////////////////////////////// //////////////////////////////////////////////// Console.WriteLine("Starting Training"); _SlidingWindowTraining.Start(); Thread.Sleep(1000); while (_SlidingWindowTraining.IsRunning()) Thread.Sleep(20); //////////////////////////////////////////////// //////////////////////////////////////////////// Console.WriteLine("Starting Testing"); Lib.Activity.Testing.SlidingWindow slidingWindowTesting = new Lib.Activity.Testing.SlidingWindow(); slidingWindowTesting.SetDatasetReservedLength(0); slidingWindowTesting.SetInputNodes(_InputLayerNodes); slidingWindowTesting.SetOutputNodes(_OuputLayerNodes); slidingWindowTesting.SetRecurrentConextLayers(contextLayers); slidingWindowTesting.SetWorkingDataset(dataSet); slidingWindowTesting.SetWindowWidth(12); slidingWindowTesting.SetDistanceToForcastHorrison(3); slidingWindowTesting.SetTargetNetwork(_TestNetworkStructure); Lib.Activity.Testing.SlidingWindow.SlidingWindowTestResults result = (Lib.Activity.Testing.SlidingWindow.SlidingWindowTestResults) slidingWindowTesting.TestNetwork(); Console.WriteLine(result.Rmse); Functions.PrintArrayToFile(result.ActualOutputs, "ActualOutputs.csv"); Functions.PrintArrayToFile(result.ExpectedOutputs, "ExpectedOutputs.csv"); Console.WriteLine("Comparing Against Random Walk 3 Step"); Console.WriteLine(Math.Round(RandomWalkCompare.CalculateError(result.ExpectedOutputs, result.ActualOutputs, 3)[0]*100, 3)); Console.WriteLine("Comparing Against Random Walk 2 Step"); Console.WriteLine(Math.Round(RandomWalkCompare.CalculateError(result.ExpectedOutputs, result.ActualOutputs, 2)[0]*100, 3)); Console.WriteLine("Comparing Against Random Walk 1 Step"); Console.WriteLine(Math.Round(RandomWalkCompare.CalculateError(result.ExpectedOutputs, result.ActualOutputs, 1)[0]*100, 3)); Console.ReadKey(); }