Ejemplo n.º 1
0
        private void DrawMomentum(Graphics graphics, DrawF draw)
        {
            ArrayList history   = new ArrayList();
            PointF2D  point     = new PointF2D(-4.0f, 2.0f);
            Function2 fun       = new Function2();
            Momentum  optimizer = new Momentum(0.07f, 0.9f);

            for (int index = 0; index < 30; index++)
            {
                PointF2D xyPoint = draw.getBlockPoint(point.X, point.Y);
                history.Add(xyPoint);
                PointF2D diff = fun.DiffFormula(point.X, point.Y);
                optimizer.Update(point, diff);
            }

            PointF2D prePoint = ((PointF2D)history[0]);

            for (int index = 0; index < 30; index++)
            {
                draw.drawPoint(graphics, Brushes.Blue, ((PointF2D)history[index]));
                draw.drawLine(graphics, prePoint, ((PointF2D)history[index]));
                prePoint = ((PointF2D)history[index]);
            }
        }
Ejemplo n.º 2
0
        private void DrawGradient(Graphics graphics, DrawF draw)
        {
            ArrayList xyPoints = new ArrayList();
            ArrayList uvPoints = new ArrayList();

            //float[] x = { -2, -1, 0, 1, -2, -1, 0, 1 };
            //float[] y = { -2, -2, -2, -2, 1, 1, 1, 1 };
            float[] x = { -2, -1, 0, 1, -2, -1, 0, 1 };
            float[] y = { -2, -2, -2, -2, 1, 1, 1, 1 };

            Function2 fun = new Function2();

            for (int index = 0; index < 8; index++)
            {
                PointF2D xyPoint = draw.getBlockPoint(x[index], y[index]);
                PointF2D uvPoint = Fun(fun, -x[index], -y[index]);
                Console.Write(uvPoint.X + " " + uvPoint.Y);
                xyPoints.Add(xyPoint);
                uvPoints.Add(uvPoint);
                draw.drawPoint(graphics, Brushes.Blue, xyPoint);
            }

            draw.drawGradients(graphics, xyPoints, uvPoints);
        }