by Trent Guidry
3. October 2009 05:28
In this post I develop the code for the bracketing base class.
The previously developed region elimination classes require bracketing, or boundary, values that bound the minimum of the function. The bracketing classes provide the functionality needed to find a bracket of the minimum of a function from a given starting guess.
The bracketing base class, which will be used as the base class for the bracketing classes, is a pretty simple class. It contains two virtual functions which are both overloads of a method called Bracket. The Bracket function takes a function to bracket, a starting position, a starting step size, and an integer indicating the targeted number of bracketing points to save. The Bracket function returns a Search Point Collection that contains the bracket values and possibly additional points if the target return points value is greater than two.
The full code for the bracketing base class is given below.
public class BracketingBase
{
public BracketingBase()
{
}
public virtual SearchPointCollection Bracket(Func<double, double> function, double startPosition, double step, int targetReturnPoints)
{
throw new NotImplementedException();
}
public virtual SearchPointCollection Bracket(Func<double, double> function, double startPosition, double step)
{
return Bracket(function, startPosition, step, 2);
}
protected bool _cancel = false;
public bool Cancel
{
get
{
bool result = false;
lock (this)
{
result = _cancel;
}
return result;
}
set
{
lock (this)
{
_cancel = value;
}
}
}
}