gov.sandia.cognition.learning.algorithm.minimization.line
Class AbstractAnytimeLineMinimizer<EvaluatorType extends Evaluator<Double,Double>>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
          extended by gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm<ResultType>
              extended by gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner<EvaluatorType,InputOutputPair<InputType,OutputType>>
                  extended by gov.sandia.cognition.learning.algorithm.minimization.AbstractAnytimeFunctionMinimizer<Double,Double,EvaluatorType>
                      extended by gov.sandia.cognition.learning.algorithm.minimization.line.AbstractAnytimeLineMinimizer<EvaluatorType>
Type Parameters:
EvaluatorType - Type of Evaluator to use
All Implemented Interfaces:
AnytimeAlgorithm<InputOutputPair<Double,Double>>, IterativeAlgorithm, StoppableAlgorithm, AnytimeBatchLearner<EvaluatorType,InputOutputPair<Double,Double>>, BatchLearner<EvaluatorType,InputOutputPair<Double,Double>>, FunctionMinimizer<Double,Double,EvaluatorType>, LineMinimizer<EvaluatorType>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
LineMinimizerBacktracking, LineMinimizerDerivativeBased, LineMinimizerDerivativeFree

public abstract class AbstractAnytimeLineMinimizer<EvaluatorType extends Evaluator<Double,Double>>
extends AbstractAnytimeFunctionMinimizer<Double,Double,EvaluatorType>
implements LineMinimizer<EvaluatorType>

Partial AnytimeAlgorithm implementation of a LineMinimizer.

Since:
2.1
Author:
Kevin R. Dixon
See Also:
Serialized Form

Field Summary
static int DEFAULT_MAX_ITERATIONS
          Default number of iterations to run the algorithm, 100
static double DEFAULT_TOLERANCE
          Default tolerance of the algorithm 1.0E-5
 
Fields inherited from class gov.sandia.cognition.learning.algorithm.minimization.AbstractAnytimeFunctionMinimizer
initialGuess, result, tolerance
 
Fields inherited from class gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner
data, keepGoing
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm
maxIterations
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
DEFAULT_ITERATION, iteration
 
Constructor Summary
AbstractAnytimeLineMinimizer(LineBracketInterpolator<? super EvaluatorType> interpolator)
          Creates a new instance of AbstractAnytimeLineMinimizer
AbstractAnytimeLineMinimizer(LineBracketInterpolator<? super EvaluatorType> interpolator, LineBracket bracket, Double initialGuess, double tolerance, int maxIterations)
          Creates a new instance of AbstractAnytimeLineMinimizer
 
Method Summary
abstract  boolean bracketingStep()
          Continues the bracketing phase of the algorithm, which attempts to place a bracket around a known minimum.
protected  void cleanupAlgorithm()
          Called to clean up the learning algorithm's state after learning has finished.
 LineBracket getBracket()
          Gets the LineBracket used to bound the search
 Double getInitialGuessFunctionValue()
          Getter for initialGuessFunctionValue
 Double getInitialGuessSlope()
          Getter for initialGuessSlope
 LineBracketInterpolator<? super EvaluatorType> getInterpolator()
          Gets the interpolator used to fit data points and derive an interpolated (hypothesized) minimum to try next.
protected  boolean initializeAlgorithm()
          Called to initialize the learning algorithm's state based on the data that is stored in the data field.
 boolean isValidBracket()
          Returns true if the algorithm has found a valid bracket on a minimum, false if the algorithm needs to continue the bracketing phase
 WeightedInputOutputPair<Vector,Double> minimizeAlongDirection(DirectionalVectorToScalarFunction function, Double functionValue, Vector gradient)
          Minimizes a Vector function along the direction given by the DirectionalVectorToScalarFunction.
abstract  boolean sectioningStep()
          Continues the sectioning phase of the algorihtm.
 void setBracket(LineBracket bracket)
          Setter for bracket
 void setData(EvaluatorType data)
          Gets the data to use for learning.
 void setInitialGuess(Double initialGuess)
          Setter for initialGuess
 void setInitialGuessFunctionValue(Double initialGuessFunctionValue)
          Setter for initialGuessFunctionValue
 void setInitialGuessSlope(Double initialGuessSlope)
          Setter for initialGuessSlope
 void setInterpolator(LineBracketInterpolator<? super EvaluatorType> interpolator)
          Setter for interpolator
 void setValidBracket(boolean validBracket)
          Setter for validBracket
protected  boolean step()
          Called to take a single step of the learning algorithm.
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.minimization.AbstractAnytimeFunctionMinimizer
getInitialGuess, getResult, getTolerance, setResult, setTolerance
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.AbstractAnytimeBatchLearner
clone, getData, getKeepGoing, learn, setKeepGoing, stop
 
Methods inherited from class gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm
getMaxIterations, isResultValid, setMaxIterations
 
Methods inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
addIterativeAlgorithmListener, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListeners
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.learning.algorithm.minimization.FunctionMinimizer
getInitialGuess, getTolerance, learn, setTolerance
 
Methods inherited from interface gov.sandia.cognition.util.CloneableSerializable
clone
 
Methods inherited from interface gov.sandia.cognition.algorithm.AnytimeAlgorithm
getMaxIterations, getResult, setMaxIterations
 
Methods inherited from interface gov.sandia.cognition.algorithm.IterativeAlgorithm
addIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListener
 
Methods inherited from interface gov.sandia.cognition.algorithm.StoppableAlgorithm
isResultValid, stop
 

Field Detail

DEFAULT_MAX_ITERATIONS

public static final int DEFAULT_MAX_ITERATIONS
Default number of iterations to run the algorithm, 100

See Also:
Constant Field Values

DEFAULT_TOLERANCE

public static final double DEFAULT_TOLERANCE
Default tolerance of the algorithm 1.0E-5

See Also:
Constant Field Values
Constructor Detail

AbstractAnytimeLineMinimizer

public AbstractAnytimeLineMinimizer(LineBracketInterpolator<? super EvaluatorType> interpolator)
Creates a new instance of AbstractAnytimeLineMinimizer

Parameters:
interpolator - Type of algorithm to fit data points and find an interpolated minimum to the known points.

AbstractAnytimeLineMinimizer

public AbstractAnytimeLineMinimizer(LineBracketInterpolator<? super EvaluatorType> interpolator,
                                    LineBracket bracket,
                                    Double initialGuess,
                                    double tolerance,
                                    int maxIterations)
Creates a new instance of AbstractAnytimeLineMinimizer

Parameters:
interpolator - Type of algorithm to fit data points and find an interpolated minimum to the known points.
bracket - LineBracket bounding a local minimum.
initialGuess - Initial guess to the location of the local minimum.
tolerance - Tolerance of the minimization algorithm.
maxIterations - Maximum number of iterations to run the algorithm before stopping.
Method Detail

initializeAlgorithm

protected boolean initializeAlgorithm()
Description copied from class: AbstractAnytimeBatchLearner
Called to initialize the learning algorithm's state based on the data that is stored in the data field. The return value indicates if the algorithm can be run or not based on the initialization.

Specified by:
initializeAlgorithm in class AbstractAnytimeBatchLearner<EvaluatorType extends Evaluator<Double,Double>,InputOutputPair<Double,Double>>
Returns:
True if the learning algorithm can be run and false if it cannot.

step

protected boolean step()
Description copied from class: AbstractAnytimeBatchLearner
Called to take a single step of the learning algorithm.

Specified by:
step in class AbstractAnytimeBatchLearner<EvaluatorType extends Evaluator<Double,Double>,InputOutputPair<Double,Double>>
Returns:
True if another step can be taken and false it the algorithm should halt.

cleanupAlgorithm

protected void cleanupAlgorithm()
Description copied from class: AbstractAnytimeBatchLearner
Called to clean up the learning algorithm's state after learning has finished.

Specified by:
cleanupAlgorithm in class AbstractAnytimeBatchLearner<EvaluatorType extends Evaluator<Double,Double>,InputOutputPair<Double,Double>>

minimizeAlongDirection

public WeightedInputOutputPair<Vector,Double> minimizeAlongDirection(DirectionalVectorToScalarFunction function,
                                                                     Double functionValue,
                                                                     Vector gradient)
Description copied from interface: LineMinimizer
Minimizes a Vector function along the direction given by the DirectionalVectorToScalarFunction. The offset in function is taken to be the initialGuess.

Specified by:
minimizeAlongDirection in interface LineMinimizer<EvaluatorType extends Evaluator<Double,Double>>
Parameters:
function - Defines the direction to search along, and the initial guess. The direction is scaled by the line-search solution
functionValue - Value of function at initialGuess, may be null
gradient - Derivative of the output with respect to the input of function at the initial guess. Gradient may be null if it's not being computer. So, gradient is not required for all line-search methods, but will throw an exception if it's expected but not available.
Returns:
Location of the minimum-value Vector solution to function and it's corresponding output value. The weight is the length of the optimal line search along "direction".

bracketingStep

public abstract boolean bracketingStep()
Description copied from interface: LineMinimizer
Continues the bracketing phase of the algorithm, which attempts to place a bracket around a known minimum.

Specified by:
bracketingStep in interface LineMinimizer<EvaluatorType extends Evaluator<Double,Double>>
Returns:
True if a valid bracket has been found, false to continue the bracketing phase of the algorithm.

sectioningStep

public abstract boolean sectioningStep()
Description copied from interface: LineMinimizer
Continues the sectioning phase of the algorihtm. This phase occurs after the bracketing phase and attempts to shrink the size of the bracket (using a LineBracketInterpolator) until sufficient accuracy is attained.

Specified by:
sectioningStep in interface LineMinimizer<EvaluatorType extends Evaluator<Double,Double>>
Returns:
True that a valid minimum has been found, false to continue sectioning the bracket.

isValidBracket

public boolean isValidBracket()
Description copied from interface: LineMinimizer
Returns true if the algorithm has found a valid bracket on a minimum, false if the algorithm needs to continue the bracketing phase

Specified by:
isValidBracket in interface LineMinimizer<EvaluatorType extends Evaluator<Double,Double>>
Returns:
True if a valid bracket on a minimum has been found, false otherwise

setValidBracket

public void setValidBracket(boolean validBracket)
Setter for validBracket

Parameters:
validBracket - Flag indicating if the algorithm has already found a valid bracket on a local minimum.

getInterpolator

public LineBracketInterpolator<? super EvaluatorType> getInterpolator()
Description copied from interface: LineMinimizer
Gets the interpolator used to fit data points and derive an interpolated (hypothesized) minimum to try next.

Specified by:
getInterpolator in interface LineMinimizer<EvaluatorType extends Evaluator<Double,Double>>
Returns:
LineBracketInterpolator used in this optimization

setInterpolator

public void setInterpolator(LineBracketInterpolator<? super EvaluatorType> interpolator)
Setter for interpolator

Parameters:
interpolator - Type of algorithm to fit data points and find an interpolated minimum to the known points.

getBracket

public LineBracket getBracket()
Description copied from interface: LineMinimizer
Gets the LineBracket used to bound the search

Specified by:
getBracket in interface LineMinimizer<EvaluatorType extends Evaluator<Double,Double>>
Returns:
LineBracket used to bound the search

setBracket

public void setBracket(LineBracket bracket)
Setter for bracket

Parameters:
bracket - LineBracket bounding a local minimum.

setData

public void setData(EvaluatorType data)
Description copied from class: AbstractAnytimeBatchLearner
Gets the data to use for learning. This is set when learning starts and then cleared out once learning is finished.

Overrides:
setData in class AbstractAnytimeBatchLearner<EvaluatorType extends Evaluator<Double,Double>,InputOutputPair<Double,Double>>
Parameters:
data - The data to use for learning.

setInitialGuess

public void setInitialGuess(Double initialGuess)
Description copied from class: AbstractAnytimeFunctionMinimizer
Setter for initialGuess

Specified by:
setInitialGuess in interface FunctionMinimizer<Double,Double,EvaluatorType extends Evaluator<Double,Double>>
Overrides:
setInitialGuess in class AbstractAnytimeFunctionMinimizer<Double,Double,EvaluatorType extends Evaluator<Double,Double>>
Parameters:
initialGuess - Initial guess of the minimization routine

getInitialGuessFunctionValue

public Double getInitialGuessFunctionValue()
Getter for initialGuessFunctionValue

Returns:
Function value at the initialGuess, may be null.

setInitialGuessFunctionValue

public void setInitialGuessFunctionValue(Double initialGuessFunctionValue)
Setter for initialGuessFunctionValue

Parameters:
initialGuessFunctionValue - Function value at the initialGuess, may be null.

getInitialGuessSlope

public Double getInitialGuessSlope()
Getter for initialGuessSlope

Returns:
Function slope at the initialGuess, may be null.

setInitialGuessSlope

public void setInitialGuessSlope(Double initialGuessSlope)
Setter for initialGuessSlope

Parameters:
initialGuessSlope - Function slope at the initialGuess, may be null.