private void pictureBox1_Paint(object sender, PaintEventArgs e) { DrawF draw = new DrawF(50.0f, 5.0f, 5.0f); //draw.drawHistogram(e.Graphics, 10, 10); //DrawCoordinate(e.Graphics, draw); DrawBlock(e.Graphics, draw); //DrawGradient(e.Graphics, draw); //DrawSGD(e.Graphics, draw); //DrawMomentum(e.Graphics, draw); //DrawAdaGrad(e.Graphics, draw); //DrawRMSProp(e.Graphics, draw); DrawAdam(e.Graphics, draw); }
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]); } }
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); }
private void DrawCoordinate(Graphics graphics, DrawF draw) { draw.drawCoordinate(graphics, 200.0f, 200.0f); draw.drawPoint(graphics, Brushes.Red, draw.Center); }
private void DrawBlock(Graphics graphics, DrawF draw) { draw.drawBlock(graphics, 10.0f, 10.0f); draw.drawPoint(graphics, Brushes.Red, draw.Center); }