【问题标题】:Neural Networks in C# using NeuronDotNet使用 NeuronDotNet 的 C# 神经网络
【发布时间】:2010-04-27 04:11:43
【问题描述】:

我正在使用 C# 测试 NeuronDotNet 库的类分配。我有一个非常简单的控制台应用程序,我用它来测试库手册中提供的一些代码 sn-ps,任务的目标是教程序如何区分正方形中的随机点,这可能或者可能不在一个也在正方形内的圆圈内。所以基本上,正方形内的哪些点也在圆内。这是我目前所拥有的:

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;
        }
    }

}

这基本上就是我所需要的,我唯一的问题是如何处理输出?更具体地说,我需要输出“步长”和“动量”的值,尽管也可以输出其他信息。任何有使用 NeuronDotNet 经验的人,都非常感谢您的意见。

【问题讨论】:

    标签: c# .net artificial-intelligence


    【解决方案1】:

    由于您有两个输出,因此您可以使用以下代码在文本框中获取输出

    Output1.Text = Program.Run(new double[] {...你的输入 ....})[0].ToString("0.000000");

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

    【讨论】:

      猜你喜欢
      • 2010-12-30
      • 2014-01-15
      • 2018-11-01
      • 2016-12-15
      • 2021-12-06
      • 1970-01-01
      • 2014-12-02
      • 2011-03-26
      • 2017-08-27
      相关资源
      最近更新 更多