Operator - The operator for the solver.@PublicationReference(author="Jonathan Richard Shewchuk", title="An Introduction to the Conjugate Gradient Method Without the Agonizing Pain", type=WebPage, year=1994, url="http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf\u200e") public abstract class IterativeMatrixSolver<Operator extends MatrixVectorMultiplier> extends java.lang.Object implements FunctionMinimizer<Vector,Vector,Operator>
| Modifier and Type | Field and Description |
|---|---|
protected int |
iterationCounter
Counts the number of iterations executed thus far.
|
protected java.util.Set<IterativeAlgorithmListener> |
listeners
Listeners to the algorithms progress have the opportunity to stop the
algorithm after a specified number of iterations.
|
protected int |
maxIterations
Execution will stop after this number of iterations even if it has not
converged.
|
protected Vector |
rhs
The right-hand-side vector (b).
|
protected boolean |
shouldStop
If set to true, the algorithm will stop after the current iteration
completes.
|
protected double |
tolerance
The tolerance of the error accepted before stopping iterations.
|
protected Vector |
x0
The initial guess for the left-hand-side vector (x).
|
| Modifier | Constructor and Description |
|---|---|
protected |
IterativeMatrixSolver(IterativeMatrixSolver<Operator> copy)
Protected copy constructor
|
protected |
IterativeMatrixSolver(Vector x0,
Vector rhs)
Initializes a solver with basic necessary values
|
protected |
IterativeMatrixSolver(Vector x0,
Vector rhs,
double tolerance)
Initializes a solver with a few more values
|
protected |
IterativeMatrixSolver(Vector x0,
Vector rhs,
double tolerance,
int maxIterations)
Inititalizes a solver with all user-definable parameters
|
| Modifier and Type | Method and Description |
|---|---|
void |
addIterativeAlgorithmListener(IterativeAlgorithmListener listener)
Adds a listener for the iterations of the algorithm.
|
abstract CloneableSerializable |
clone()
Creates a new clone (shallow copy) of this object.
|
protected abstract InputOutputPair<Vector,Vector> |
completeSolver()
Called after the final iteration.
|
boolean |
equals(java.lang.Object o) |
Vector |
getInitialGuess()
Returns the initial guess at "x"
|
int |
getIteration()
Gets the current number of iterations executed by this algorithm since
its it was started.
|
int |
getMaxIterations()
Gets the maximum number of total iterations before stopping.
|
InputOutputPair<Vector,Vector> |
getResult()
Gets the current result of the algorithm.
|
double |
getTolerance()
Gets the tolerance of the minimization algorithm
|
int |
hashCode() |
protected abstract void |
initializeSolver(Operator function)
Called before iterations begin in learn.
|
boolean |
isResultValid()
Returns true if execution stopped because the residual was below the
acceptable tolerance (vs.
|
protected abstract double |
iterate()
Called during each step of the iterative solver.
|
InputOutputPair<Vector,Vector> |
learn(Operator function)
Shell that solves for Ax = b (x0 and rhs passed in on initialization, A
is contained in function).
|
void |
removeIterativeAlgorithmListener(IterativeAlgorithmListener listener)
Removes a listener for the iterations of the algorithm.
|
void |
setInitialGuess(Vector initialGuess)
Sets the initial guess ("x0")
|
void |
setMaxIterations(int maxIterations)
Sets the maximum number of iterations before this will stop iterating.
|
void |
setTolerance(double tolerance)
Sets the minimum tolerance before iterations complete (must be
non-negative).
|
void |
stop()
Execution will stop after the current iteration completes.
|
protected double tolerance
protected Vector x0
protected Vector rhs
protected int maxIterations
protected java.util.Set<IterativeAlgorithmListener> listeners
protected int iterationCounter
protected boolean shouldStop
protected IterativeMatrixSolver(Vector x0, Vector rhs)
x0 - The initial guess for xrhs - The "b" to solveprotected IterativeMatrixSolver(Vector x0, Vector rhs, double tolerance)
x0 - The initial guess for xrhs - The "b" to solvetolerance - The minimum acceptable errorprotected IterativeMatrixSolver(Vector x0, Vector rhs, double tolerance, int maxIterations)
x0 - The initial guess for xrhs - The "b" to solvetolerance - The minimum acceptable errormaxIterations - The maximum number of iterationsprotected IterativeMatrixSolver(IterativeMatrixSolver<Operator> copy)
copy - The "self" to copypublic final InputOutputPair<Vector,Vector> learn(Operator function)
learn in interface BatchLearner<Operator extends MatrixVectorMultiplier,InputOutputPair<Vector,Vector>>learn in interface FunctionMinimizer<Vector,Vector,Operator extends MatrixVectorMultiplier>function - Matrix wrapperprotected abstract void initializeSolver(Operator function)
function - The matrix wrapper to save for iterate.protected abstract double iterate()
protected abstract InputOutputPair<Vector,Vector> completeSolver()
public abstract CloneableSerializable clone()
CloneableSerializableclone in interface CloneableSerializableclone in class java.lang.ObjectCloneableSerializable.clone()public final double getTolerance()
FunctionMinimizergetTolerance in interface FunctionMinimizer<Vector,Vector,Operator extends MatrixVectorMultiplier>FunctionMinimizer.getTolerance()public final void setTolerance(double tolerance)
setTolerance in interface FunctionMinimizer<Vector,Vector,Operator extends MatrixVectorMultiplier>tolerance - The minimum tolerance acceptable before returning the
result.public final Vector getInitialGuess()
getInitialGuess in interface FunctionMinimizer<Vector,Vector,Operator extends MatrixVectorMultiplier>public final void setInitialGuess(Vector initialGuess)
setInitialGuess in interface FunctionMinimizer<Vector,Vector,Operator extends MatrixVectorMultiplier>initialGuess - the initial guess ("x0")public final int getMaxIterations()
AnytimeAlgorithmgetMaxIterations in interface AnytimeAlgorithm<InputOutputPair<Vector,Vector>>AnytimeAlgorithm.getMaxIterations()public final void setMaxIterations(int maxIterations)
setMaxIterations in interface AnytimeAlgorithm<InputOutputPair<Vector,Vector>>maxIterations - The maximum number of iterationspublic InputOutputPair<Vector,Vector> getResult()
AnytimeAlgorithmgetResult in interface AnytimeAlgorithm<InputOutputPair<Vector,Vector>>AnytimeAlgorithm.getResult()public int getIteration()
IterativeAlgorithmgetIteration in interface IterativeAlgorithmIterativeAlgorithm.getIteration()public final void addIterativeAlgorithmListener(IterativeAlgorithmListener listener)
IterativeAlgorithmaddIterativeAlgorithmListener in interface IterativeAlgorithmlistener - The listener to add.IterativeAlgorithm.addIterativeAlgorithmListener(gov.sandia.cognition.algorithm.IterativeAlgorithmListener)public final void removeIterativeAlgorithmListener(IterativeAlgorithmListener listener)
IterativeAlgorithmremoveIterativeAlgorithmListener in interface IterativeAlgorithmlistener - The listener to remove.IterativeAlgorithm.removeIterativeAlgorithmListener(gov.sandia.cognition.algorithm.IterativeAlgorithmListener)public void stop()
stop in interface StoppableAlgorithmpublic final boolean isResultValid()
isResultValid in interface StoppableAlgorithmpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.ObjectObject.hashCode()