/// <summary>
        ///     Builds the structure of the neural network ready for training and testing
        /// </summary>
        public static void BuildStructure()
        {
            _InputLayer = new Base();
            _InputLayerNodes = new List<Structure.Node.Base>();
            for (Int32 i = 0; i < 1; i++) _InputLayerNodes.Add(new Structure.Node.Base(_InputLayer, new Tanh()));
            _InputLayer.SetNodes(_InputLayerNodes);

            EchoReservoir echoLayer = new EchoReservoir(50, 0.4f, 0, 30, new Tanh());

            _OutputLayer = new Base();
            _OuputLayerNodes = new List<Structure.Node.Base>();
            for (Int32 i = 0; i < 1; i++) _OuputLayerNodes.Add(new Output(_OutputLayer, new Tanh()));
            _OutputLayer.SetNodes(_OuputLayerNodes);

            _RecurrentLayer = new RecurrentContext(2, new Tanh());
            _RecurrentLayer.AddSourceNodes(_OuputLayerNodes);

            _InputLayer.ConnectFowardLayer(echoLayer);
            _RecurrentLayer.ConnectFowardLayer(echoLayer);

            echoLayer.ConnectFowardLayer(_OutputLayer);

            _TestNetworkStructure.AddLayer(_InputLayer);
            _TestNetworkStructure.AddLayer(_RecurrentLayer);
            _TestNetworkStructure.AddLayer(echoLayer);
            _TestNetworkStructure.AddLayer(_OutputLayer);

            foreach (Base layer in _TestNetworkStructure.GetCurrentLayers()) layer.PopulateNodeConnections();
            ((Structure.Node.RecurrentContext)_RecurrentLayer.GetNodes()[0]).OverrideRateOfUpdate(1);
        }
        /// <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();
        }
Beispiel #3
0
        /// <summary>
        ///     Builds the structure of the neural network ready for training and testing
        /// </summary>
        public static void BuildStructure()
        {
            _InputLayer = new Base();
            _InputLayerNodes = new List<Structure.Node.Base>();
            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());

            _OutputLayer = new Base();
            _OuputLayerNodes = new List<Structure.Node.Base>();
            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();
        }
Beispiel #4
0
 /// <summary>
 ///     Removes a layer from the neuralNetwork Structure causing a structure update
 /// </summary>
 /// <param name='layer'>
 ///     Layer.
 /// </param>
 public void RemoveLayer(Base layer)
 {
     if (!_CurrentLayers.Contains(layer)) return;
     _CurrentLayers.Remove(layer);
     StructureUpdate();
 }
Beispiel #5
0
 /// <summary>
 ///     Adds a layer to the NeuralNetwork Structure causing a structure update
 /// </summary>
 /// <param name='newLayer'>
 ///     New layer.
 /// </param>
 public void AddLayer(Base newLayer)
 {
     if (_CurrentLayers.Contains(newLayer)) return;
     _CurrentLayers.Add(newLayer);
     StructureUpdate();
 }
Beispiel #6
0
 /// <summary>
 ///     Adds a layer to the list of layers that are connected forward
 /// </summary>
 /// <param name='layer'>
 ///     Layer.
 /// </param>
 public virtual void ConnectFowardLayer(Base layer)
 {
     _ForwardConnectedLayers.Add(layer);
     layer._ReverseConnectedLayers.Add(this);
 }
        /// <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();
        }