Neural Networks in C# using NeuronDotNet

Posted by kingrichard2005 on Stack Overflow See other posts from Stack Overflow or by kingrichard2005
Published on 2010-04-27T04:11:43Z Indexed on 2010/04/27 4:13 UTC
Read the original article Hit count: 565

Filed under:
|
|

Hello, 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.

© Stack Overflow or respective owner

Related posts about artificial-intelligence

Related posts about c#