Esempio n. 1
0
        /// <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();
        }
Esempio n. 2
0
        /// <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();
        }
Esempio n. 3
0
        /// <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();
        }