AnnealedType - Class returned from the learn() method, such as a
FeedforwardNeuralNetwork, for exampleCostParametersType - Cost parameters given to the learn() method, such
as Collection<InputOutputPair>, for example@CodeReview(reviewer="Kevin R. Dixon",date="2008-07-22",changesNeeded=false,comments={"Moved previous code review to annotation.","Added HTML tags to javadoc.","Fixed a few typos in javadoc.","Code looks fine."}) @CodeReview(reviewer="Justin Basilico",date="2006-10-02",changesNeeded=false,comments={"Did some reformatting of the code.","Added missing documentation.","Cleaned up the use of default parameter values."}) public class SimulatedAnnealer<CostParametersType,AnnealedType> extends AbstractAnytimeBatchLearner<CostParametersType,AnnealedType> implements BatchCostMinimizationLearner<CostParametersType,AnnealedType>, MeasurablePerformanceAlgorithm
| Modifier and Type | Field and Description |
|---|---|
static double |
DEFAULT_COOLING_FACTOR
The default cooling factor for learning, 0.1.
|
static int |
DEFAULT_MAX_ITERATIONS
The default number of maximum iterations, 1000.
|
static double |
DEFAULT_STARTING_TEMPERATURE
The default starting temperature for the algorithm, 1.0.
|
data, keepGoingmaxIterationsDEFAULT_ITERATION, iteration| Constructor and Description |
|---|
SimulatedAnnealer(AnnealedType initial,
Perturber<AnnealedType> perturber,
CostFunction<? super AnnealedType,? super CostParametersType> cost)
Creates a new instance of SimulatedAnnealer.
|
SimulatedAnnealer(AnnealedType initial,
Perturber<AnnealedType> perturber,
CostFunction<? super AnnealedType,? super CostParametersType> cost,
int maxIterations)
Creates a new instance of SimulatedAnnealer.
|
SimulatedAnnealer(AnnealedType initial,
Perturber<AnnealedType> perturber,
CostFunction<? super AnnealedType,? super CostParametersType> cost,
int maxIterations,
int maxIterationsWithoutImprovement)
Creates a new instance of SimulatedAnnealer.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
cleanupAlgorithm()
Called to clean up the learning algorithm's state after learning has
finished.
|
SimulatedAnnealer<CostParametersType,AnnealedType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
protected AnnealedType |
getBestSoFar()
Gets the best state found so far.
|
protected double |
getBestSoFarScore()
Gets the score for the best state found so far.
|
double |
getCoolingFactor()
Gets the cooling factor.
|
CostFunction<? super AnnealedType,? super CostParametersType> |
getCostFunction()
Gets the cost function that the learner is minimizing.
|
protected AnnealedType |
getCurrent()
Gets the current state of the system.
|
protected double |
getCurrentScore()
Gets the score of the current state.
|
protected int |
getIterationsWithoutImprovement()
Gets the current number of iterations without improvement.
|
int |
getMaxIterationsWithoutImprovement()
Gets the maximum number of iterations to go without improvement before
stopping.
|
NamedValue<java.lang.Double> |
getPerformance()
Gets the performance, which is the best score so far.
|
Perturber<AnnealedType> |
getPerturber()
Gets the perturber.
|
java.util.Random |
getRandom()
Gets the random number generator.
|
AnnealedType |
getResult()
Gets the current result of the algorithm.
|
protected double |
getTemperature()
Gets the current temperature of the system.
|
protected boolean |
initializeAlgorithm()
Called to initialize the learning algorithm's state based on the
data that is stored in the data field.
|
protected void |
setBestSoFar(AnnealedType bestSoFar)
Sets the best state found so far.
|
protected void |
setBestSoFarScore(double bestSoFarScore)
Sets the score for the best state found so far.
|
void |
setCoolingFactor(double coolingFactor)
Sets the cooling factor.
|
void |
setCostFunction(CostFunction<? super AnnealedType,? super CostParametersType> cost)
Sets the cost function.
|
protected void |
setCurrent(AnnealedType current)
Sets the current state of the system.
|
protected void |
setCurrentScore(double currentScore)
Sets the score of the current state.
|
protected void |
setIterationsWithoutImprovement(int iterationsWithoutImprovement)
Sets the current number of iterations without improvement.
|
void |
setMaxIterationsWithoutImprovement(int maxIterationsWithoutImprovement)
Sets the maximum number of iterations to go without improvement before
stopping.
|
void |
setPerturber(Perturber<AnnealedType> perturber)
Sets the perturber.
|
void |
setRandom(java.util.Random random)
Sets the random number generator.
|
protected void |
setTemperature(double temperature)
Sets the current temperature of the system.
|
protected boolean |
step()
Takes one step in the Simulated Annealing process.
|
getData, getKeepGoing, learn, setData, setKeepGoing, stopgetMaxIterations, isResultValid, setMaxIterationsaddIterativeAlgorithmListener, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListenersequals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitlearngetMaxIterations, setMaxIterationsaddIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListenerisResultValidpublic static final double DEFAULT_STARTING_TEMPERATURE
public static final double DEFAULT_COOLING_FACTOR
public static final int DEFAULT_MAX_ITERATIONS
public SimulatedAnnealer(AnnealedType initial, Perturber<AnnealedType> perturber, CostFunction<? super AnnealedType,? super CostParametersType> cost)
initial - Initial candidate to considerperturber - The perturbing function to use.cost - The cost function to minimize.public SimulatedAnnealer(AnnealedType initial, Perturber<AnnealedType> perturber, CostFunction<? super AnnealedType,? super CostParametersType> cost, int maxIterations)
initial - Initial candidate to considerperturber - The perturbing function to use.cost - The cost function to minimize.maxIterations - The maximum number of iterations to perform.public SimulatedAnnealer(AnnealedType initial, Perturber<AnnealedType> perturber, CostFunction<? super AnnealedType,? super CostParametersType> cost, int maxIterations, int maxIterationsWithoutImprovement)
initial - Initial candidate to considerperturber - The perturbing function to use.cost - The cost function to minimize.maxIterations - The maximum number of iterations to perform.maxIterationsWithoutImprovement - The maximum number of iterations
to go without improvement before stopping.public SimulatedAnnealer<CostParametersType,AnnealedType> clone()
AbstractCloneableSerializableObject 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 CloneableSerializableclone in class AbstractAnytimeBatchLearner<CostParametersType,AnnealedType>protected boolean initializeAlgorithm()
AbstractAnytimeBatchLearnerinitializeAlgorithm in class AbstractAnytimeBatchLearner<CostParametersType,AnnealedType>protected boolean step()
step in class AbstractAnytimeBatchLearner<CostParametersType,AnnealedType>public CostFunction<? super AnnealedType,? super CostParametersType> getCostFunction()
BatchCostMinimizationLearnergetCostFunction in interface BatchCostMinimizationLearner<CostParametersType,AnnealedType>public Perturber<AnnealedType> getPerturber()
protected double getTemperature()
public int getMaxIterationsWithoutImprovement()
protected int getIterationsWithoutImprovement()
public double getCoolingFactor()
public java.util.Random getRandom()
protected AnnealedType getBestSoFar()
protected double getBestSoFarScore()
protected AnnealedType getCurrent()
protected double getCurrentScore()
public void setCostFunction(CostFunction<? super AnnealedType,? super CostParametersType> cost)
cost - The new cost function.public void setPerturber(Perturber<AnnealedType> perturber)
perturber - The new perturber.protected void setTemperature(double temperature)
temperature - The new temperature.public void setMaxIterationsWithoutImprovement(int maxIterationsWithoutImprovement)
maxIterationsWithoutImprovement - The new maximum.protected void setIterationsWithoutImprovement(int iterationsWithoutImprovement)
iterationsWithoutImprovement - The new iteration.public void setCoolingFactor(double coolingFactor)
coolingFactor - The new cooling factor.public void setRandom(java.util.Random random)
random - The new random number generator.protected void setBestSoFar(AnnealedType bestSoFar)
bestSoFar - The new best state.protected void setBestSoFarScore(double bestSoFarScore)
bestSoFarScore - The new score.protected void setCurrent(AnnealedType current)
current - The new current state.protected void setCurrentScore(double currentScore)
currentScore - The new score.protected void cleanupAlgorithm()
AbstractAnytimeBatchLearnercleanupAlgorithm in class AbstractAnytimeBatchLearner<CostParametersType,AnnealedType>public AnnealedType getResult()
AnytimeAlgorithmgetResult in interface AnytimeAlgorithm<AnnealedType>public NamedValue<java.lang.Double> getPerformance()
getPerformance in interface MeasurablePerformanceAlgorithm