简体   繁体   中英

Neural Networks in C# using NeuronDotNet

I'm testing the NeuronDotNet library for a class assignment using C#. I have a very simple console application that I'm using to test some of the code snippets provided in the manual fro the library, the goal of the assignment is to teach the program how to distinguish between random points in a square which may or may not be within a circle that is also inside the square. So basically, which points inside the square are also inside the circle. Here is what I have so far:

namespace _469_A7
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initlaize the backpropogation network
            LinearLayer inputLayer = new LinearLayer(2);
            SigmoidLayer hiddenLayer = new SigmoidLayer(8);
            SigmoidLayer outputLayer = new SigmoidLayer(2);
            new BackpropagationConnector(inputLayer, hiddenLayer);
            new BackpropagationConnector(hiddenLayer, outputLayer);
            BackpropagationNetwork network = new BackpropagationNetwork(inputLayer, outputLayer);

            //Generate a training set for the ANN
            TrainingSet trainingSet = new TrainingSet(2, 2);

            //TEST: Generate random set of points and add to training set, 
            //for testing purposes start with 10 samples;
            Point p;
            Program program = new Program(); //Used to access randdouble function
            Random rand = new Random();
            for(int i = 0; i < 10; i++)
            {
                //These points will be within the circle radius Type A
                if(rand.NextDouble() > 0.5)
                {
                    p = new Point(rand.NextDouble(), rand.NextDouble());
                    trainingSet.Add(new TrainingSample(new double[2] { p.getX(), p.getY() }, new double[2] { 1, 0 }));
                    continue;
                }
                //These points will either be on the border or outside the circle Type B
                p = new Point(program.randdouble(1.0, 4.0), program.randdouble(1.0, 4.0));
                trainingSet.Add(new TrainingSample(new double[2] { p.getX(), p.getY() }, new double[2] { 0, 1 }));
            }

            //Start network learning
            network.Learn(trainingSet, 100);
            //Stop network learning
            //network.StopLearning();

        }

        //generates a psuedo-random double between min and max 
        public double randdouble(double min, double max)
        {
            Random rand = new Random();
            if (min > max)
            {
                return rand.NextDouble() * (min - max) + max;
            }
            else
            {
                return rand.NextDouble() * (max - min) + min;
            }
        }

    }

    //Class defines a point in X/Y coordinates
    public class Point
    {
        private double X;
        private double Y;

        public Point(double xVal, double yVal)
        {
            this.X = xVal;
            this.Y = yVal;
        }

        public double getX()
        {
            return X;
        }

        public double getY()
        {
            return Y;
        }
    }

}

This is basically all that I need, the only question I have is how to handle output?? More specifically, I need to output the value of the "step size" and the "momentum", although it would be nice to output other information as well. Anyone with experience using NeuronDotNet, your input is appreciated.

since you have two outputs so you can get the output in a textbox using the following code

Output1.Text = Program.Run(new double[] {...your inputs ....})[0].ToString("0.000000");

Output2.Text = Program.Run(new double[] {.....your inputs ...})[1].ToString("0.000000");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM