예제 #1
0
파일: Form1.cs 프로젝트: quider/neuron
        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;
        }
예제 #2
0
파일: MLPTest.cs 프로젝트: quider/neuron
        public void ResetAutoTest()
        {
            int[] layers = new int[] { 4,5,1 };
            MultilayerPerceptron nn = new MLPGenerator().Create(layers,1,new Sigmoid());
            double[] randomSelected=new double[] {
                nn.Structure.Input[1].Next[1].Weight.Value,
                nn.Structure.Input[1].Next[2].Weight.Value,
                nn.Structure.Input[1].Next[2].Next.Next[0].Weight.Value,
                nn.Structure.Output[0].Previous[1].Weight.Value
            };
            double[] inp = new double[] { -0.978, 2.34, 0.2, -0.33};
            double[] pulsed=nn.Pulse(inp);

            nn.Reset(0,1);
            double[] randomSelected2=new double[] {
                nn.Structure.Input[1].Next[1].Weight.Value,
                nn.Structure.Input[1].Next[2].Weight.Value,
                nn.Structure.Input[1].Next[2].Next.Next[0].Weight.Value,
                nn.Structure.Output[0].Previous[1].Weight.Value
            };
            for(int i=0;i<randomSelected.Length;i++) {
                Assert.AreNotEqual(randomSelected[i],randomSelected2[i]);
            }
            double[] pulsed2=nn.Pulse(inp);
            for(int i=0;i<pulsed.Length;i++) {
                Assert.AreNotEqual(pulsed[i],pulsed2[i]);
            }
        }