示例#1
0
        private static void RunGradientDescent()
        {
            double alpha = 0.01;
            double Tol   = 0.001;
            int    N     = 1000;

            double[] x0  = { -1, 2 };
            int      dim = 2;

            Console.WriteLine("Running Gradient Descent...");
            double[] gradDescentResult = MinFinder.GradDescent(BealesFunction, BealesPartialDerivative, new double[] { -1, 2 }
                                                               , alpha, dim, Tol, N);
            Console.WriteLine("Done !!");
            Console.WriteLine("Gradient Descent Result : " + gradDescentResult[0] + "," + gradDescentResult[1]);
        }
示例#2
0
        private static void RunGradientDescentWithMom()
        {
            double alpha = 0.01;
            double gamma = 0.8;
            // The result seems to converge too early for Tol = 0.001. Hence, using a smaller value
            //double Tol = 0.001;
            double Tol = 0.00000001;
            int    N   = 1000;

            double[] x0  = { -1, 2 };
            int      dim = 2;

            Console.WriteLine("Running Gradient Descent With Momentum..");
            double[] gradDescentMomResult = MinFinder.GradDescentMOM(BealesFunction, BealesPartialDerivative
                                                                     , x0, alpha, gamma, dim, Tol, N);
            Console.WriteLine("Done !!");
            Console.WriteLine("Gradient Descent with momentum Result : " + gradDescentMomResult[0] + "," + gradDescentMomResult[1]);
        }