Пример #1
0
 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());
 }
Пример #2
0
        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;
        }
Пример #3
0
 public void BPMinCyclesTest()
 {
     int[] layers = new int[] { 4,5,1 };
     MultilayerPerceptron nn = new MLPGenerator().Create(layers,1,new Sigmoid());
     var result=nn.BP(new BPRequest(TestVec,5000,40));
     Assert.IsTrue(result.Epochs.Length>=40);
 }
Пример #4
0
 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);
 }
Пример #5
0
 public void PulseManySameResultsTest()
 {
     MLPGenerator gen = new MLPGenerator();
     int[] layers = new int[] { 4,3,2 };
     MultilayerPerceptron nn = gen.Create(layers,1,new Sigmoid());
     double[] inp = new double[] { -0.978, 2.34, 0.2, -0.33};
     double[] res = nn.Pulse(inp);
     double[] res2 = nn.Pulse(inp);
     double[] res3 = nn.Pulse(inp);
     Assert.AreEqual(res.Length, res2.Length);
     Assert.AreEqual(res.Length, res3.Length);
     for(int i=0; i<res.Length; i++) {
         Assert.AreEqual(res[i], res2[i]);
         Assert.AreEqual(res[i], res3[i]);
     }
 }
Пример #6
0
        public void FullNetworkScanTest()
        {
            int[] layers=new int[]{2,3,1};
            MultilayerPerceptron nn=new MLPGenerator().Create(layers,1,new Sigmoid());
            //check input and output layer
            Assert.AreEqual(nn.Structure.Input.Length,2);
            Assert.AreEqual(nn.Structure.Output.Length,1);

            int count=0;
            foreach(var i in nn.Structure.Input) {
                foreach(var j in i.Next)
                    CheckConnection(i,j.Next,ref count);
            }
            Assert.AreEqual(count,12);
            //check bias
            Assert.AreEqual(nn.Structure.Bias.Next.Length,4);
            Assert.IsTrue(nn.Structure.Bias.Next.All(x => x.Next is Neuron));
        }
Пример #7
0
        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]);
            }
        }
Пример #8
0
 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);
 }
Пример #9
0
 public void ResetManualTest()
 {
     int[] layers = new int[] { 4,5,1 };
     MultilayerPerceptron nn = new MLPGenerator().Create(layers,1,new Sigmoid());
     nn.Reset(() => 0.7);
     Assert.AreEqual(nn.Structure.Input[1].Next[2].Weight.Value,0.7); // random selected
 }