private void button2_Click(object sender, EventArgs e) { int cycles = int.Parse(textBox1.Text); int hiddenNeurons = int.Parse(textBox2.Text); double learnRate = double.Parse(textBox3.Text); double momentum = double.Parse(textBox4.Text); int[] layers = new int[] { 1, hiddenNeurons, 1 }; MultilayerPerceptron ann = new MLPGenerator().Create(layers, 1, new Sigmoid(2)); ann.Reset(-1, 1); ann.Momentum = momentum; ann.LearnFactor = learnRate; List <TrainingData> trainingList = new List <TrainingData>(); for (int i = 0; i < Map.Count; i++) { double[] input = new double[] { (double)Map[i].Item1 / (double)pictureBox1.Width }; double[] output = new double[] { (double)Map[i].Item2 / (double)pictureBox1.Height }; trainingList.Add(new TrainingData(input, output)); } var res = ann.BP(new BPRequest(trainingList.ToArray(), cycles)); for (int i = 0; i < pictureBox1.Width; i++) { int x = i; double yd = ann.Pulse(new double[] { (double)i / (double)pictureBox1.Width })[0]; int y = Convert.ToInt32(yd * pictureBox1.Height); Point p = new Point(x, y); Graph.DrawRectangle(new Pen(new SolidBrush(Color.Orange)), p.X, p.Y, 1, 1); } pictureBox1.Image = Bitmap; }
public void BPMaxMSETest() { int[] layers = new int[] { 4, 5, 1 }; MultilayerPerceptron nn = new MLPGenerator().Create(layers, 1, new Sigmoid()); var result = nn.BP(new BPRequest(TestVec, 1000, 0, 0.7)); Assert.IsTrue(result.Epochs.Length < 1000); }
public void BPMaxCyclesTest() { int[] layers = new int[] { 4, 5, 1 }; MultilayerPerceptron nn = new MLPGenerator().Create(layers, 1, new Sigmoid()); var result = nn.BP(new BPRequest(TestVec, 5)); Assert.AreEqual(result.Epochs.Length, 5); }
public void ExplicitBPTimeTest() { int[] layers = new int[] { 4, 10, 1 }; MultilayerPerceptron nn = new MLPGenerator().Create(layers, 1, new Sigmoid()); var result = nn.BP(new BPRequest(TestVec, 1500 * 10)); throw new NotImplementedException("BP Total ms=" + result.BPTime.TotalMilliseconds.ToString()); }
public void ReasonableBPTimeTest() { int[] layers = new int[] { 4, 5, 1 }; MultilayerPerceptron nn = new MLPGenerator().Create(layers, 1, new Sigmoid()); var result = nn.BP(new BPRequest(TestVec, 10000)); Assert.IsTrue(result.BPTime.TotalMilliseconds < 2000); }
static void Main(string[] args) { TrainingData[] xor=new TrainingData[] { new TrainingData(new double[] {1,0}, new double[] {1}), new TrainingData(new double[] {0,1}, new double[] {1}), new TrainingData(new double[] {1,1}, new double[] {0}), new TrainingData(new double[] {0,0}, new double[] {0}), }; int[] layers = new int[] { 2,2,1 }; MultilayerPerceptron mlp=new MLPGenerator().Create(layers,1,new Sigmoid()); mlp.Inspector=new SignalInspector(); //shows the neurons processing in VS Output window mlp.Inspector.Debug=true; mlp.Inspector.TraceLevel=3; mlp.LearnFactor=0.9; var response=mlp.BP(new BPRequest(xor,1000)); Console.ReadKey(); }
static void Main(string[] args) { TrainingData[] xor = new TrainingData[] { new TrainingData(new double[] { 1, 0 }, new double[] { 1 }), new TrainingData(new double[] { 0, 1 }, new double[] { 1 }), new TrainingData(new double[] { 1, 1 }, new double[] { 0 }), new TrainingData(new double[] { 0, 0 }, new double[] { 0 }), }; int[] layers = new int[] { 2, 2, 1 }; MultilayerPerceptron mlp = new MLPGenerator().Create(layers, 1, new Sigmoid()); mlp.Inspector = new SignalInspector(); //shows the neurons processing in VS Output window mlp.Inspector.Debug = true; mlp.Inspector.TraceLevel = 3; mlp.LearnFactor = 0.9; var response = mlp.BP(new BPRequest(xor, 1000)); Console.ReadKey(); }