public static int MainMethod()
            {
                dynamic nd   = null;
                dynamic d    = new object();
                object  no   = null;
                object  o    = new object();
                DelOut  d_oo = new DelOut(Foo.M01);
                DelOut  d_od = new DelOut(Foo.M02);
                DelOut  d_do = new DelOut(Foo.M03);
                DelOut  d_dd = new DelOut(Foo.M03);

                // object, object
                d_oo(no, out o);
                d_od(o, out no);
                d_do(no, out o);
                d_od(o, out no);
                // object, dynamic
                d_oo(o, out nd);
                d_od(no, out d);
                d_do(o, out nd);
                d_od(no, out d);
                // Assert and Null Ref Exception
                // dynamic, object
                d_oo(nd, out o);
                d_od(nd, out no);
                d_do(d, out o);
                d_od(d, out no);
                // dynamic, dynamic
                d_oo(d, out d);
                d_od(d, out nd);
                d_do(nd, out d);
                d_od(nd, out nd);
                return(0);
            }
コード例 #2
0
ファイル: Form1.cs プロジェクト: hth0901/kdc
        private void btn_test_Click(object sender, EventArgs e)
        {
            //dua du lieu vao mang
            double[][] datatest = new double[listView1.Items.Count][];
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                datatest[i] = new double[25];

                for (int j = 0; j < 25; j++)
                {
                    datatest[i][j] = Double.Parse(listView1.Items[i].SubItems[j].Text);
                }
            }

            //target
            double[] target = { 0 };
            Array.Resize(ref target, listView1.Items.Count + 1);

            for (int i = 1; i < target.Length; i++)
            {
                target[i] = double.Parse(listView1.Items[i - 1].SubItems[26].Text);
            }
            double[] netout = new double[11];
            netout[0] = 1; //tham so cho w0
            double[][] realOut = new double[listView1.Items.Count][];
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                realOut[i] = new double[2];
            }


            DelOut dellHidden = new DelOut(NetInputH);
            DelOut delOut     = new DelOut(NetInputO);

            for (int k = 0; k < datatest.Length; k++)
            {
                //tinh toan netout cho tang an
                for (int i = 1; i < hds.Length; i++)
                {
                    netout[i] = Sigmod(dellHidden(hds[i], datatest[k]));
                }
                realOut[k][1] = Sigmod(delOut(ops[1], netout));
            }

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                listView1.Items[i].SubItems[25].Text = Math.Round(realOut[i][1], 0).ToString();
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: hth0901/kdc
        private void button1_Click(object sender, EventArgs e)
        {
            //he so hoc
            double Lrate = 0.9;

            //khoitao cac trng so cho lop an
            double[][] weightH = { new double[1], new double[] { -0.4, 0.2, 0.4, -0.5, 0.3, 0.1, 0.6, 0.8, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5 },
                                   new double[] { 0.3,0.1, 0.6, 0.8, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 1.5, -1.6, 0.45, -0.12, 0.25, 0.23, -0.71, 0.35, -0.15, 0.31, 0.5, -0.67 },
                                   new double[] { -0.4,0.2, 0.4, -0.5, 0.3, 0.1, 0.6, 0.8, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5 },
                                   new double[] { -0.4,0.2, 0.4, -0.5, 0.3, 0.1, 0.6, 0.8, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5 },
                                   new double[] { 0.3,0.1, 0.6, 0.8, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 1.5, -1.6, 0.45, -0.12, 0.25, 0.23, -0.71, 0.35, -0.15, 0.31, 0.5, -0.67 },
                                   new double[] { -0.4,0.2, 0.4, -0.5, 0.3, 0.1, 0.6, 0.8, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5 },
                                   new double[] { 0.3,0.1, 0.6, 0.8, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 1.5, -1.6, 0.45, -0.12, 0.25, 0.23, -0.71, 0.35, -0.15, 0.31, 0.5, -0.67 },
                                   new double[] { -0.4,0.2, 0.4, -0.5, 0.3, 0.1, 0.6, 0.8, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5 },
                                   new double[] { 0.3,0.1, 0.6, 0.8, 0.5, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 1.5, -1.6, 0.45, -0.12, 0.25, 0.23, -0.71, 0.35, -0.15, 0.31, 0.5, -0.67 },
                                   new double[] { 0.2, -0.3, 0.1, 0.2, 1.4, -1.3, 0.3, 0.1, 1.5, -1.6, 0.45, -0.35, 0.61, 0.75, -1.2, 0.5, 0.6, 0.8, 0.5, 0.45, -1.8, 0.8, 0.4, -0.7, 0.5 } };
            //khoi tao cac trong so cho lop xuat
            double[][] weightO = { new double[1], new double[] { 0.1, 0.2, 0.6, -0.7, -0.3, -0.2, 0.25, 0.1, -0.3, -0.2, 0.25 } };
            //mau huan luyen dau tien
            //double[][] train = { new double[] { Convert.ToInt32(textBox1.Text.ToString()), Convert.ToInt32(textBox2.Text.ToString()), Convert.ToInt32(textBox3.Text.ToString()), Convert.ToInt32(textBox4.Text.ToString()) } };
            //so input = so tham so + 1
            double[][] train = new double[listView1.Items.Count][];
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                train[i] = new double[25];

                for (int j = 0; j < 25; j++)
                {
                    if (listView1.Items[i].SubItems[j].Text != "")
                    {
                        train[i][j] = Double.Parse(listView1.Items[i].SubItems[j].Text);
                    }
                }
            }



            int soluotlatp = 0;

            double[] target = { 0 };
            Array.Resize(ref target, listView1.Items.Count + 1);

            for (int i = 1; i < target.Length; i++)
            {
                target[i] = double.Parse(listView1.Items[i - 1].SubItems[26].Text);
            }
            double[] netout = new double[11];
            netout[0] = 1; //tham so cho w0
            double mse = 0;

            double[][] realOut = new double[listView1.Items.Count][];
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                realOut[i] = new double[2];
            }

            //tao mang cac node hidden
            for (int i = 0; i < 11; i++)
            {
                hds[i] = new double[25]; //co 25 tham so
            }
            for (int i = 1; i < 11; i++)
            {
                for (int j = 0; j < 25; j++)  //j = so tham so + 1
                {
                    hds[i][j] = weightH[i][j];
                }
            }
            DelOut dellHidden = new DelOut(NetInputH);
            DelOut delOut     = new DelOut(NetInputO);


            //khoi tao trong so cho tang xuat
            for (int i = 1; i < ops.Length; i++)
            {
                ops[i] = new double[11];
            }
            for (int i = 1; i < 2; i++)
            {
                for (int j = 0; j < 11; j++)
                {
                    ops[i][j] = weightO[i][j];
                }
            }


            textBox1.Text = NetInputH(hds[1], train[0]).ToString();

            do
            {
                mse = 0;

                //delta cho tang xuat
                double[] deltaOut = new double[2];

                //delta cho tang an
                double[] deltaHidden = new double[11];
                //foreach (double[] tr in train)


                for (int k = 0; k < train.Length; k++)
                {
                    //tinh toan netout cho tang an
                    for (int i = 1; i < hds.Length; i++)
                    {
                        netout[i] = Sigmod(dellHidden(hds[i], train[k]));
                    }

                    realOut[k][1] = Sigmod(delOut(ops[1], netout));

                    //tinh toan cac delta
                    //delta cho tang xuat

                    for (int i = 1; i < deltaOut.Length; i++)
                    {
                        deltaOut[i] = realOut[k][i] * (1 - realOut[k][i]) * (target[k + 1] - realOut[k][i]);
                    }

                    for (int i = 1; i < hds.Length; i++)
                    {
                        deltaHidden[i] = netout[i] * (1 - netout[i]);
                        double sum = 0;
                        for (int j = 1; j < deltaOut.Length; j++)
                        {
                            sum += ops[j][i] * deltaOut[j];
                        }
                        deltaHidden[i] = deltaHidden[i] * sum;
                    }

                    //cap nhat lai trong so
                    //cap nhat trong so cho tang xuat
                    for (int i = 0; i < 11; i++)
                    {
                        ops[1][i] = ops[1][i] + (Lrate * deltaOut[1] * netout[i]);
                    }



                    //cap nhat trong so cho tang an
                    for (int j = 1; j < 11; j++)
                    {
                        for (int i = 0; i < 25; i++)
                        {
                            hds[j][i] = hds[j][i] + (Lrate * deltaHidden[j] * train[k][i]);
                        }
                    }
                    double hihihaha = 1.2;
                }

                for (int i = 0; i < listView1.Items.Count; i++)
                {
                    mse += Math.Pow((realOut[i][1]) - (target[i + 1]), 2) / listView1.Items.Count;
                }
                soluotlatp++;
                lbl_mse.Text = Math.Round(mse, 4).ToString();
            }while (soluotlatp < Convert.ToInt32(txt_soluotlap.Text));
            label6.Text = soluotlatp.ToString();
            label5.Text = realOut[0][1].ToString();
            label6.Text = target[1].ToString();

            /*
             * // xem trong so cuoi cung
             * for (int i = 0; i < 11; i++)
             * {
             *  textBox1.Text += Math.Round(hds[1][i], 6).ToString() + "   ";
             * }*/


            for (int i = 0; i < listView1.Items.Count; i++)
            {
                listView1.Items[i].SubItems[25].Text = Math.Round(realOut[i][1], 0).ToString();
            }

            System.Windows.Forms.Label[] test = { label1, label2, label3 };
            for (int i = 0; i < 3; i++)
            {
                test[i].Text = Math.Round(weightO[1][i], 6).ToString();
            }

            for (int i = 0; i < 4; i++)
            {
                //weightH[1][i] = weightH[1][i] + (Lrate * deltaHidden[1] * train[0][i]);
                //MessageBox.Show("Trong so tang an sau khi cap nhat " + weightH[1][i].ToString());
            }

            for (int i = 0; i < 4; i++)
            {
                //weightH[2][i] = weightH[2][i] + (Lrate * deltaHidden[2] * train[0][i]);
                //MessageBox.Show("Trong so node an thu 2 sau khi cap nhat " + weightH[2][i].ToString());
            }

            //Application.Exit();
        }