Exemplo n.º 1
0
        private static void RunTest(DiffFunc1D f)
        {
            CubicInterpLineSearch cils = new CubicInterpLineSearch((Float)1e-8);
            Float val;
            Float deriv;

            val = f(0, out deriv);
            Float min = cils.Minimize(f, val, deriv);

            val = f(min, out deriv);
            Console.WriteLine(deriv);
            GoldenSectionSearch gss = new GoldenSectionSearch((Float)1e-8);

            min = gss.Minimize(f);
            val = f(min, out deriv);
            Console.WriteLine(deriv);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Makes a new GDOptimizer with the given optimization parameters
 /// </summary>
 /// <param name="terminate">Termination criterion</param>
 /// <param name="lineSearch">Line search to use</param>
 /// <param name="maxSteps">Maximum number of updates</param>
 /// <param name="useCG">Use Cubic interpolation line search or Backtracking line search with Armijo condition</param>
 public GDOptimizer(DTerminate terminate, IDiffLineSearch lineSearch = null, bool useCG = false, int maxSteps = 0)
 {
     Terminate = terminate;
     if (LineSearch == null)
     {
         if (useCG)
         {
             LineSearch = new CubicInterpLineSearch((Float)0.01);
         }
         else
         {
             LineSearch = new BacktrackingLineSearch();
         }
     }
     else
     {
         LineSearch = lineSearch;
     }
     _maxSteps = maxSteps;
     UseCG     = useCG;
 }