【发布时间】: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