Ejemplo n.º 1
0
        public static void Optim2D(Graphique G)
        {
            G.ClearWhite();
            DrawFnt2D(Fnt);
            G.DrawAxis();

            double x = Utils.RND();
            double y = Utils.RND();

            G.Cross(x, y, Color.White);

            //////////////////////////////////////////////////////
            double k      = 0.1;
            double x_prev = 0;
            double y_prev = 0;

            while ((x_prev == 0 && y_prev == 0) || (Math.Abs(x_prev) - Math.Abs(x) > zero || Math.Abs(y_prev) - Math.Abs(y) > zero))
            {
                x_prev = x;
                y_prev = y;
                x      = x_prev - (k * Fnt_dx(x_prev, y_prev));
                y      = y_prev - (k * Fnt_dy(x_prev, y_prev));
                G.Cross(x, y, Color.White);
            }

            //////////////////////////////////////////////////////
        }
Ejemplo n.º 2
0
        public static void Final(Graphique G)
        {
            Element.InitSpirale();
            List <Element> data = Element.List;

            ////////////////////////////////////////////////////////////////////////

            int round_nbr = 2000;



            // gradient descent loop
            for (int round = 0; round < round_nbr; round++)
            {
                float data_loss = 0;



                if (round % 20 == 0)
                {
                    G.ClearBlack();
                    DrawScore();

                    G.DrawAxis();
                    G.DrawData();
                    Form1.Schema.Invalidate();
                    Form1.Schema.Update();
                    Form1.iteration2.Text += "Iteration " + round + " : Loss = " + data_loss + "\r\n";
                    Form1.iteration2.Update();
                }
            }
        }
Ejemplo n.º 3
0
        public static void Final(Graphique G)
        {
            List <Element> data = Element.List;

            Form1.iteration.Text = "";

            int    K = 3; // nombre de classes
            int    D = 3; // dimension 2 + 1 for the biais
            Matrix W = new Matrix(K, D);

            W.RandomInit();
            double data_loss = 0;

            //////////////////////////////////////////////////////////////////////////////////////////////


            // gradient descent loop
            for (int round = 0; round < 200; round++)
            {
                /////////////////////////////////////////////////////////////////////////////////////////

                if (round % 10 == 0)
                {
                    G.ClearBlack();
                    DrawScore(W.matrix);

                    G.DrawAxis();
                    G.DrawData();
                    Form1.Schema.Invalidate();
                    Form1.Schema.Update();
                    Form1.iteration.Text += "Iteration " + round + " : Loss = " + data_loss + "\r\n";
                    Form1.iteration.Update();
                }
            }
        }
Ejemplo n.º 4
0
        public static void Optim2Dmax(Graphique G)
        {
            G.ClearWhite();
            DrawFnt2D(Fntmax);
            G.DrawAxis();

            var r = new Random();

            double gamma = .01; // step size multiplier

            double x = r.NextDouble() - 0.5;
            double y = r.NextDouble() - 0.5;
            double z = Fntmax(x, y);

            ///////////////////////////////////////////////////////////////////

            for (int i = 0; i < 1000; i++)
            {
                if (Fntmax(x, y) == Fntv1(x, y))
                {
                    x += -gamma *dFntv1x(x, y);

                    y += -gamma *dFntv1y(x, y);
                }
                else
                {
                    x += -gamma *dFntv2x(x, y);

                    y += -gamma *dFntv2y(x, y);
                }
                G.Cross(x, y, Color.White);
            }

            ///////////////////////////////////////////////////////////////////
        }
Ejemplo n.º 5
0
 public static void test3(Graphique G)
 {
     G.ClearBlack();
     float[,] W = new float[3, 3]
     {
         { 1, 0, 0 },
         { -1, 0, 1.5f },
         { 0, 1, 0 }
     };
     OneLayer.DrawScore(W);
     OneLayer.LevelSet(W, 0.5f);
     G.DrawAxis();
 }
Ejemplo n.º 6
0
        public static void test4(Graphique G)
        {
            G.ClearBlack();

            float[,] W = new float[3, 3]
            {
                { 1, 0, 0 },
                { -1, 0, 0 },
                { 1f, 1f, 0 }
            };

            /*float[,] W = new float[3, 3]
             * {
             *  {  1, 0f, 0f },
             *  { -1, 0f, 0f },
             *  {  1f, 0.8f, 0f }
             * };*/
            OneLayer.DrawScore(W);
            OneLayer.LevelSet(W, 0.4f);
            G.DrawAxis();
        }
Ejemplo n.º 7
0
        static public void DrawFnt(FntX F, Color c)
        {
            Graphique G = Form1.G;

            for (int xecran = 1; xecran < G.GetH(); xecran++)
            {
                double x      = G.XPixToVal(xecran - 1);
                double y      = F(x);
                int    yecran = G.YValToPix(y);

                double x2      = G.XPixToVal(xecran);
                double y2      = F(x2);
                int    yecran2 = G.YValToPix(y2);

                Utils.minmax(ref yecran, ref yecran2);

                for (int yy = yecran; yy <= yecran2; yy++)
                {
                    G.SetPixel(xecran, yy, c);
                }
            }

            G.DrawAxis();
        }
Ejemplo n.º 8
0
        public static void Optim2D(Graphique G)
        {
            G.ClearWhite();
            DrawFnt2D(Fnt);
            G.DrawAxis();
            var r = new Random();

            double gamma = .1; // step size multiplier
            //double precision = .1; // range limit

            double x = r.NextDouble() - 0.5;
            double y = r.NextDouble() - 0.5;
            double z = Fnt(x, y);

            for (int i = 0; i < 30; i++)
            {
                x += -gamma *dFntx(x, y);

                y += -gamma *dFnty(x, y);

                z = Fnt(x, y);
                G.Cross(x, y, Color.White);
            }
        }
Ejemplo n.º 9
0
 private void button1_Click(object sender, EventArgs e)
 {
     //G.DrawCat(GetMyCategorie);
     G.DrawAxis();
     pictureBox1.Invalidate();
 }