Exemple #1
0
        /// <see cref="INetwork.BuildElmanNetwork"/>
        public INetwork BuildElmanNetwork()
        {
            if (TrainedNetworkFile.Exists)
            {
                return(this);
            }

            var pattern = new ElmanPattern {
                ActivationFunction = new ActivationSigmoid(),
                InputNeurons       = InputCount,
                OutputNeurons      = OutputCount
            };

            pattern.AddHiddenLayer(1);

            try {
                var network = (BasicNetwork)pattern.Generate();
                EncogDirectoryPersistence.SaveObject(TrainedNetworkFile, network);
                TrainedNetworkFile = new FileInfo(TrainedNetworkFile.FullName);
            } catch (Exception e) {
                var a = e;
            }

            return(this);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // used for prediction of time series
            // sin(x) in theory
            int DEGREES     = 360;
            int WINDOW_SIZE = 16;

            double[][] Input = new double[DEGREES][];
            double[][] Ideal = new double[DEGREES][];

            // Create array of sin signals
            for (int i = 0; i < DEGREES; i++)
            {
                Input[i] = new double[WINDOW_SIZE];
                Ideal[i] = new double[] { Math.Sin(DegreeToRad(i + WINDOW_SIZE)) };
                for (int j = 0; j < WINDOW_SIZE; j++)
                {
                    Input[i][j] = Math.Sin(DegreeToRad(i + j));
                }
            }
            // construct training set
            IMLDataSet trainingSet = new BasicMLDataSet(Input, Ideal);

            // construct an Elman type network
            // simple recurrent network
            ElmanPattern pattern = new ElmanPattern
            {
                InputNeurons       = WINDOW_SIZE,
                ActivationFunction = new ActivationSigmoid(),
                OutputNeurons      = 1
            };

            pattern.AddHiddenLayer(WINDOW_SIZE);
            IMLMethod    method  = pattern.Generate();
            BasicNetwork network = (BasicNetwork)method;
            // Train network
            IMLTrain train = new Backpropagation(network, trainingSet);
            var      stop  = new StopTrainingStrategy();

            train.AddStrategy(new Greedy());
            train.AddStrategy(stop);
            int epoch = 0;

            while (!stop.ShouldStop())
            {
                train.Iteration();
                Console.WriteLine($"Training Epoch #{epoch} Error:{train.Error}");
                epoch++;
            }
            // Test network
            foreach (IMLDataPair pair in trainingSet)
            {
                IMLData output = network.Compute(pair.Input);
                Console.WriteLine($"actual={output[0]}, ideal={pair.Ideal[0]}");
            }
        }
        public static IMLMethod CreateElmanNetwork(int inputsize, int outputsize)
        {
            // construct an Elman type network
            ElmanPattern pattern = new ElmanPattern();

            pattern.ActivationFunction = new ActivationTANH();
            pattern.InputNeurons       = inputsize;
            pattern.AddHiddenLayer(20);
            pattern.OutputNeurons = outputsize;
            return(pattern.Generate());
        }
Exemple #4
0
        /// <summary>
        /// Creates the elman network as a basicnetwork.
        /// This method create a elmhan patterns but returns a basic network (ready for load/save).
        /// </summary>
        /// <param name="inputsize">The inputsize.</param>
        /// <param name="outputsize">The outputsize.</param>
        /// <param name="hiddenlayers">The hiddenlayers.</param>
        /// <param name="activate">The activation function to use..</param>
        /// <returns>a basic network</returns>
        public static BasicNetwork CreateElmanNetwork(int inputsize, int outputsize, int hiddenlayers, IActivationFunction activate)
        {
            // construct an Elman type network
            ElmanPattern pattern = new ElmanPattern();

            pattern.ActivationFunction = activate;
            pattern.InputNeurons       = inputsize;
            pattern.AddHiddenLayer(hiddenlayers);
            pattern.OutputNeurons = outputsize;
            return((BasicNetwork)pattern.Generate());
        }
Exemple #5
0
        private IMLMethod CreateElmanNetwork(int input)
        {
            // construct an Elman type network
            var pattern = new ElmanPattern
            {
                InputNeurons = input
            };

            pattern.AddHiddenLayer(2);
            pattern.OutputNeurons = 1;
            return(pattern.Generate());
        }
Exemple #6
0
        private IMLMethod CreateElmanNetwork(int input)
        {
            // construct an Elman type network
            var pattern = new ElmanPattern
            {
                ActivationFunction = new ActivationSigmoid(),
                InputNeurons       = input
            };

            pattern.AddHiddenLayer(5);
            pattern.OutputNeurons = 1;
            return(pattern.Generate());
        }
Exemple #7
0
        public override void Create(int input, int layers, int neurons, int output)
        {
            //Setup network, parameters (Activation, bias, number of neurons).
            var elman = new ElmanPattern()
            {
                ActivationFunction = new ActivationSigmoid(),
                InputNeurons       = input,
                OutputNeurons      = output
            };

            elman.AddHiddenLayer(neurons);

            EncogNetwork = (BasicNetwork)elman.Generate();
        }