Пример #1
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();
        }
Пример #2
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();
        }