ResultType
- The type of object created by the learning algorithm.
For example, a FeedforwardNeuralNetwork
.DataType
- The type of the data that the algorithm uses to perform
the learning. For example, a
Collection<InputOutputPair<Vector, Double>>
or
String
.@CodeReview(reviewer="Kevin R. Dixon", date="2008-07-22", changesNeeded=false, comments={"Added some HTML formatting to the javadoc, removed useless javadoc.","Code looks fine."}) public abstract class AbstractAnytimeBatchLearner<DataType,ResultType> extends AbstractAnytimeAlgorithm<ResultType> implements AnytimeBatchLearner<DataType,ResultType>
AbstractAnytimeBatchLearner
abstract class
implements a standard method for conforming to the BatchLearner
and
AnytimeLearner
(IterativeAlgorithm
and
StoppableAlgorithm
) interfaces. In doing so it implements
the logic to handle the events that are fired for IterativeLearner and the
method calls required for StoppableAlgorithm
inside of the learn
method for the BatchLearner
interface. This means that classes that
extend this abstract class can focus on the implementation of the logic of
the learning algorithm and get conformance to these useful interfaces without
any real effort.
initializeLearning
- Initializes the learning algorithm.step
- Performs a single step of the learning algorithm.cleanupLearning
- Clean up after learning has been completed.getResult
- Get the result of learning.Modifier and Type | Field and Description |
---|---|
protected DataType |
data
The data to learn from.
|
protected boolean |
keepGoing
Indicates whether or not the learner should make another step.
|
maxIterations
DEFAULT_ITERATION, iteration
Modifier | Constructor and Description |
---|---|
protected |
AbstractAnytimeBatchLearner(int maxIterations)
Creates a new instance of
AbstractAnytimeBatchLearner . |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
cleanupAlgorithm()
Called to clean up the learning algorithm's state after learning has
finished.
|
AbstractAnytimeBatchLearner<DataType,ResultType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
DataType |
getData()
Gets the data to use for learning.
|
boolean |
getKeepGoing()
Gets the keep going value, which indicates if the algorithm should
continue on to another step.
|
protected abstract boolean |
initializeAlgorithm()
Called to initialize the learning algorithm's state based on the
data that is stored in the data field.
|
ResultType |
learn(DataType data)
The
learn method creates an object of ResultType using
data of type DataType , using some form of "learning" algorithm. |
protected void |
setData(DataType data)
Gets the data to use for learning.
|
void |
setKeepGoing(boolean keepGoing)
Sets the keep going value, which indicates if the algorithm should
continue on to another step.
|
protected abstract boolean |
step()
Called to take a single step of the learning algorithm.
|
void |
stop()
Requests that the algorithm stop at the next appropriate point.
|
getMaxIterations, isResultValid, setMaxIterations
addIterativeAlgorithmListener, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListeners
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getMaxIterations, getResult, setMaxIterations
addIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListener
isResultValid
protected boolean keepGoing
protected DataType data
protected AbstractAnytimeBatchLearner(int maxIterations)
AbstractAnytimeBatchLearner
.maxIterations
- The maximum number of iterations, must be greater
than zero.public AbstractAnytimeBatchLearner<DataType,ResultType> clone()
AbstractCloneableSerializable
Object
class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone()
to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil
may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone()
as the basis for your implementation.clone
in interface CloneableSerializable
clone
in class AbstractIterativeAlgorithm
public ResultType learn(DataType data)
BatchLearner
learn
method creates an object of ResultType
using
data of type DataType
, using some form of "learning" algorithm.learn
in interface BatchLearner<DataType,ResultType>
data
- The data that the learning algorithm will use to create an
object of ResultType
.protected abstract boolean initializeAlgorithm()
protected abstract boolean step()
protected abstract void cleanupAlgorithm()
public void stop()
StoppableAlgorithm
stop
in interface StoppableAlgorithm
public boolean getKeepGoing()
AnytimeBatchLearner
getKeepGoing
in interface AnytimeBatchLearner<DataType,ResultType>
public void setKeepGoing(boolean keepGoing)
keepGoing
- The keep going value.public DataType getData()
AnytimeBatchLearner
getData
in interface AnytimeBatchLearner<DataType,ResultType>
protected void setData(DataType data)
data
- The data to use for learning.