Parabolic reduction region elimination for single variable line search optimization

by Trent Guidry 2. October 2009 04:56

In this article I develop the code for the parabolic region elimination class.

This algorithm uses a working set of three points. It starts with the two bracket points and, if a third point is not provided, it uses the midpoint between them as the third point. It then calculates the function value at each point.

For each iteration of the parabolic region elimination, a parabola is fitted to the three points and a new X is estimated using the algorithm posted previously at Fitting a parabola to three points and finding the minimum in C#. If the new X value is not already in the set of points, the function value of the new point is computed, added to the set, and the point with the largest Y value is removed.

The source code for the parabolic region elimination class is given below. The code for the region elimination base class was posted previously.

public class ParabolicRegionElimination : RegionEliminationBase
    {
        public ParabolicRegionElimination()
            : base()
        {
            _numStartingPoints = 3;
        }
 
        public override RegionEliminationResults RegionEliminate(Func<double, double> function, SearchPointCollection startPoint, double eliminationFraction)
        {
            Debug.Assert(startPoint.Count >= 2);
            bool succeeded = true;
            Cancel = false;
 
            SearchPointCollection searchPoints = startPoint.Clone(3);
            CalculateMissingValues(searchPoints, function);
 
            if (searchPoints.Count < 3)
            {
                double midPoint = (searchPoints[0].X + searchPoints[1].X) / 2.0;
                double functionValue = function(midPoint);
                searchPoints.Add(new SearchPoint(midPoint, functionValue));
            }
 
            double stopRegionSize = (searchPoints[2].X - searchPoints[0].X) * eliminationFraction;
 
            while (!Cancel)
            {
                try
                {
                    double newX = searchPoints.ParabolicMinYEstimate();
                    if (!double.IsNaN(newX))
                    {
                        if (searchPoints.CanAdd(newX))
                        {
                            double functionValue = function(newX);
                            SearchPoint newPoint = new SearchPoint(newX, functionValue);
                            if (searchPoints.CanAdd(newPoint))
                            {
                                searchPoints.Add(newPoint);
                            }
                            else
                            {
                                Cancel = true;
                            }
                        }
                        else
                        {
                            Cancel = true;
                        }
                    }
                    else
                    {
                        Cancel = true;
                        succeeded = false;
                    }
                    if (searchPoints[2].X - searchPoints[0].X < stopRegionSize)
                    {
                        Cancel = true;
                    }
                }
                catch (SingularMatrixException)
                {
                    Cancel = true;
                }
            }
            SearchPoint minimumPoint = searchPoints.FindMinY();
 
            return new RegionEliminationResults(minimumPoint.X, minimumPoint.Y, succeeded);
        }
    }

 

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading