コード例 #1
0
        /// <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();
        }
コード例 #2
0
        /// <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();
        }