コード例 #1
0
            static void Main(string[] args)
            {
                int    dimension = 2;
                int    numNeuronsPerDimension = 4;
                double volumeNeuronWidth      = 2.0 / numNeuronsPerDimension;;
                bool   includeEdgeRBFs        = true;

                RBFNetwork n = new RBFNetwork(dimension, numNeuronsPerDimension, 1, RBFEnum.Gaussian);

                n.SetRBFCentersAndWidthsEqualSpacing(0, 1, RBFEnum.Gaussian, volumeNeuronWidth, includeEdgeRBFs);


                INeuralDataSet trainingSet = new BasicNeuralDataSet(XORInput, XORIdeal);
                SVDTraining    train       = new SVDTraining(n, trainingSet);

                int epoch = 1;

                do
                {
                    train.Iteration();
                    Console.WriteLine(@"Epoch #" + epoch + @" Error:" + train.Error);
                    epoch++;
                } while ((epoch < 1) && (train.Error > 0.001));

                Console.WriteLine(@"Neural Network Results:");
                foreach (IMLDataPair pair in trainingSet)
                {
                    IMLData output = n.Compute(pair.Input);
                    Console.WriteLine(pair.Input[0] + @"," + pair.Input[1]
                                      + @", actual=" + output[0] + @",ideal=" + pair.Ideal[0]);
                }

                Console.Read();
            }
コード例 #2
0
        static void Main(string[] args)
        {
            int dimension = 2;                             // XORInput provides two-dimensional inputs. Not 8.

            /*
             * If XORInput is  8 dimensional  it should be like this:
             *
             * public static double[][] XORInput = {
             * new[] {0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0},
             * .
             * .
             * .*/
            int        numNeuronsPerDimension = 4;                      // could be also 16, 64, 256. I suppose it should accept 8, 32 but it needs additional investigation
            double     volumeNeuronWidth      = 2.0 / numNeuronsPerDimension;
            bool       includeEdgeRBFs        = true;
            RBFNetwork n = new RBFNetwork(dimension, numNeuronsPerDimension, 1, RBFEnum.Gaussian);

            n.SetRBFCentersAndWidthsEqualSpacing(0, 1, RBFEnum.Gaussian, volumeNeuronWidth, includeEdgeRBFs);
            //n.RandomizeRBFCentersAndWidths(0, 1, RBFEnum.Gaussian);
            INeuralDataSet trainingSet = new BasicNeuralDataSet(XORInput, XORIdeal);
            SVDTraining    train       = new SVDTraining(n, trainingSet);
            int            epoch       = 1;

            do
            {
                train.Iteration();
                Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error);
                epoch++;
            } while ((epoch < 1) && (train.Error > 0.001));
        }
コード例 #3
0
        private void Train(RBFNetwork network, IMLDataSet trainingSet)
        {
            var train = new SVDTraining(network, trainingSet);

            //SVD is a single step solve
            int epoch = 1;

            do
            {
                train.Iteration();
                Console.WriteLine(@"Epoch #" + epoch + @" Error:" + train.Error);
                epoch++;
            } while ((epoch < 1) && (train.Error > mMaxError));
        }
コード例 #4
0
        public void TestPersistEG()
        {
            IMLDataSet trainingSet = XOR.CreateXORDataSet();
            RBFNetwork network     = new RBFNetwork(2, 4, 1, RBFEnum.Gaussian);

            SVDTraining training = new SVDTraining(network, trainingSet);

            training.Iteration();
            XOR.VerifyXOR(network, 0.1);

            EncogDirectoryPersistence.SaveObject(EG_FILENAME, network);
            RBFNetwork network2 = (RBFNetwork)EncogDirectoryPersistence.LoadObject(EG_FILENAME);

            XOR.VerifyXOR(network2, 0.1);
        }
コード例 #5
0
        public void Execute(IExampleInterface app)
        {
            //Specify the number of dimensions and the number of neurons per dimension
            int dimensions             = 2;
            int numNeuronsPerDimension = 7;

            //Set the standard RBF neuron width.
            //Literature seems to suggest this is a good default value.
            double volumeNeuronWidth = 2.0 / numNeuronsPerDimension;

            //RBF can struggle when it comes to flats at the edge of the sample space.
            //We have added the ability to include wider neurons on the sample space boundary which greatly
            //improves fitting to flats
            bool includeEdgeRBFs = true;

            #region Setup
            //General setup is the same as before
            RadialBasisPattern pattern = new RadialBasisPattern();
            pattern.InputNeurons  = dimensions;
            pattern.OutputNeurons = 1;

            //Total number of neurons required.
            //Total number of Edges is calculated possibly for future use but not used any further here
            int numNeurons = (int)Math.Pow(numNeuronsPerDimension, dimensions);
            int numEdges   = (int)(dimensions * Math.Pow(2, dimensions - 1));

            pattern.AddHiddenLayer(numNeurons);

            BasicNetwork             network  = pattern.Generate();
            RadialBasisFunctionLayer rbfLayer = (RadialBasisFunctionLayer)network.GetLayer(RadialBasisPattern.RBF_LAYER);
            network.Reset();

            //Position the multidimensional RBF neurons, with equal spacing, within the provided sample space from 0 to 1.
            rbfLayer.SetRBFCentersAndWidthsEqualSpacing(0, 1, RBFEnum.Gaussian, dimensions, volumeNeuronWidth, includeEdgeRBFs);

            #endregion

            //Create some training data that can not easily be represented by gaussians
            //There are other training examples for both 1D and 2D
            //Degenerate training data only provides outputs as 1 or 0 (averaging over all outputs for a given set of inputs would produce something approaching the smooth training data).
            //Smooth training data provides true values for the provided input dimensions.
            Create2DSmoothTainingDataGit();

            //Create the training set and train.
            INeuralDataSet trainingSet = new BasicNeuralDataSet(INPUT, IDEAL);
            ITrain         train       = new SVDTraining(network, trainingSet);

            //SVD is a single step solve
            int epoch = 1;
            do
            {
                train.Iteration();
                Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error);
                epoch++;
            } while ((epoch < 1) && (train.Error > 0.001));

            // test the neural network
            Console.WriteLine("Neural Network Results:");

            //Create a testing array which may be to a higher resoltion than the original training data
            Set2DTestingArrays(100);
            trainingSet = new BasicNeuralDataSet(INPUT, IDEAL);

            //Write out the results data
            using (var sw = new System.IO.StreamWriter("results.csv", false))
            {
                foreach (INeuralDataPair pair in trainingSet)
                {
                    INeuralData output = network.Compute(pair.Input);
                    //1D//sw.WriteLine(InverseScale(pair.Input[0]) + ", " + Chop(InverseScale(output[0])));// + ", " + pair.Ideal[0]);
                    sw.WriteLine(InverseScale(pair.Input[0]) + ", " + InverseScale(pair.Input[1]) + ", " + Chop(InverseScale(output[0])));// + ", " + pair.Ideal[0]);// + ",ideal=" + pair.Ideal[0]);
                    //3D//sw.WriteLine(InverseScale(pair.Input[0]) + ", " + InverseScale(pair.Input[1]) + ", " + InverseScale(pair.Input[2]) + ", " + Chop(InverseScale(output[0])));// + ", " + pair.Ideal[0]);// + ",ideal=" + pair.Ideal[0]);
                    //Console.WriteLine(pair.Input[0] + ", actual=" + output[0] + ",ideal=" + pair.Ideal[0]);
                }
            }

            Console.WriteLine("\nFit output saved to results.csv");
            Console.WriteLine("\nComplete - Please press the 'any' key to close.");
            Console.ReadKey();
        }