public abstract class Fitness extends java.lang.Object implements Prototype, java.lang.Comparable
Rules:
comparison | method |
a > b | a.betterThan(b) |
a >= b | a.betterThan(b) || a.equivalentTo(b) |
a = b | a.equivalentTo(b) |
Parameter bases
fit | default fitness base |
Modifier and Type | Field and Description |
---|---|
Individual[] |
context
Auxiliary variable, used by coevolutionary processes, to store the individuals
involved in producing this given Fitness value.
|
static java.lang.String |
FITNESS_PREAMBLE
Basic preamble for printing Fitness values out
|
static java.lang.String |
P_FITNESS
base parameter for defaults
|
java.util.ArrayList |
trials
Auxiliary variable, used by coevolutionary processes, to compute the
number of trials used to compute this Fitness value.
|
Constructor and Description |
---|
Fitness() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
betterThan(Fitness _fitness)
Should return true if this fitness is clearly better than _fitness;
You may assume that _fitness is of the same class as yourself.
|
java.lang.Object |
clone()
Creates a new individual cloned from a prototype,
and suitable to begin use in its own evolutionary
context.
|
int |
compareTo(java.lang.Object o)
Returns -1 if I am FITTER than the other Fitness, 1 if I am LESS FIT than the other Fitness,
and 0 if we are equivalent.
|
boolean |
contextIsBetterThan(Fitness other)
Given another Fitness,
returns true if the trial which produced my current context is "better" in fitness than
the trial which produced his current context, and thus should be retained in lieu of his.
|
abstract boolean |
equivalentTo(Fitness _fitness)
Should return true if this fitness is in the same equivalence class
as _fitness, that is, neither is clearly better or worse than the
other.
|
abstract double |
fitness()
Should return an absolute fitness value ranging from negative
infinity to infinity, NOT inclusive (thus infinity, negative
infinity, and NaN are NOT valid fitness values).
|
java.lang.String |
fitnessToString()
Print to a string the fitness in a fashion intended
to be parsed in again via readFitness(...).
|
java.lang.String |
fitnessToStringForHumans()
Print to a string the fitness in a fashion readable by humans, and not intended
to be parsed in again.
|
Individual[] |
getContext()
Treat the Individual[] you receive from this as read-only.
|
abstract boolean |
isIdealFitness()
Should return true if this is a good enough fitness to end the run
|
void |
merge(EvolutionState state,
Fitness other)
Merges the other fitness into this fitness.
|
void |
printFitness(EvolutionState state,
int log)
Should print the fitness out in a computer-readable fashion,
with a verbosity of Output.V_NO_GENERAL.
|
void |
printFitness(EvolutionState state,
int log,
int verbosity)
Deprecated.
Verbosity no longer has meaning
|
void |
printFitness(EvolutionState state,
java.io.PrintWriter writer)
Should print the fitness out in a computer-readable fashion,
using writer.println(...).
|
void |
printFitnessForHumans(EvolutionState state,
int log)
Should print the fitness out fashion pleasing for humans to read,
with a verbosity of Output.V_NO_GENERAL.
|
void |
printFitnessForHumans(EvolutionState state,
int log,
int verbosity)
Deprecated.
Verbosity no longer has meaning
|
void |
readFitness(EvolutionState state,
java.io.DataInput dataInput)
Reads the binary form of an individual from a DataInput.
|
void |
readFitness(EvolutionState state,
java.io.LineNumberReader reader)
Reads in the fitness from a form outputted by fitnessToString() and thus
printFitnessForHumans(...).
|
void |
readTrials(EvolutionState state,
java.io.DataInput dataInput)
Reads trials in from DataInput.
|
void |
setContext(Individual[] cont) |
void |
setContext(Individual[] cont,
int index) |
void |
setToBestOf(EvolutionState state,
Fitness[] fitnesses)
Sets the fitness to be the same value as the best of the provided fitnesses.
|
void |
setToMeanOf(EvolutionState state,
Fitness[] fitnesses)
Sets the fitness to be the same value as the mean of the provided fitnesses.
|
void |
setToMedianOf(EvolutionState state,
Fitness[] fitnesses)
Sets the fitness to be the median of the provided fitnesses.
|
void |
setup(EvolutionState state,
Parameter base)
Sets up the object by reading it from the parameters stored
in state, built off of the parameter base base.
|
void |
writeFitness(EvolutionState state,
java.io.DataOutput dataOutput)
Writes the binary form of an individual out to a DataOutput.
|
void |
writeTrials(EvolutionState state,
java.io.DataOutput dataOutput)
Writes trials out to DataOutput
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
defaultBase
public java.util.ArrayList trials
public Individual[] context
public static final java.lang.String P_FITNESS
public static final java.lang.String FITNESS_PREAMBLE
public void setContext(Individual[] cont, int index)
public void setContext(Individual[] cont)
public Individual[] getContext()
public abstract double fitness()
You are free to restrict this range any way you like: for example, your fitness values might fall in the range [-5.32, 2.3]
Selection methods relying on fitness proportionate information will assume the fitness is non-negative and should throw an error if it is not. Thus if you plan on using FitProportionateSelection, BestSelection, or GreedyOverselection, for example, your fitnesses should assume that 0 is the worst fitness and positive fitness are better. If you're using other selection methods (Tournament selection, various ES selection procedures, etc.) your fitness values can be anything.
Similarly, if you're writing a selection method and it needs positive fitnesses, you should check for negative values and issue an error; and if your selection method doesn't need an absolute fitness value, it should use the equivalentTo() and betterThan() methods instead.
If your fitness scheme does not use a metric quantifiable to a single positive value (for example, MultiObjectiveFitness), you should perform some reasonable translation.
public abstract boolean isIdealFitness()
public abstract boolean equivalentTo(Fitness _fitness)
public abstract boolean betterThan(Fitness _fitness)
public void printFitnessForHumans(EvolutionState state, int log)
public void printFitnessForHumans(EvolutionState state, int log, int verbosity)
public void printFitness(EvolutionState state, int log)
public void printFitness(EvolutionState state, int log, int verbosity)
public void printFitness(EvolutionState state, java.io.PrintWriter writer)
public void readFitness(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException
java.io.IOException
public java.lang.String fitnessToStringForHumans()
public java.lang.String fitnessToString()
public void writeFitness(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
java.io.IOException
public void writeTrials(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
java.io.IOException
public void readFitness(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
java.io.IOException
public void readTrials(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
java.io.IOException
public boolean contextIsBetterThan(Fitness other)
public void merge(EvolutionState state, Fitness other)
This method only works properly if the other Fitness had its trials deleted before it was sent off for evaluation on a remote machine: thus all of the trials are new and can be concatenated in. This is what sim.eval.Job presently does in its method copyIndividualsForward().
public java.lang.Object clone()
Prototype
Typically this should be a full "deep" clone. However, you may share certain elements with other objects rather than clone hem, depending on the situation:
Implementations.
public Object clone()
{
try
{
return super.clone();
}
catch ((CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
public Object clone()
{
try
{
MyObject myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
}
catch ((CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
return myobj;
}
public Object clone()
{
MyObject myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
return myobj;
}
public void setup(EvolutionState state, Parameter base)
Prototype
For prototypes, setup(...) is typically called once for the prototype instance; cloned instances do not receive the setup(...) call. setup(...) may be called more than once; the only guarantee is that it will get called at least once on an instance or some "parent" object from which it was ultimately cloned.
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
public void setToBestOf(EvolutionState state, Fitness[] fitnesses)
public void setToMeanOf(EvolutionState state, Fitness[] fitnesses)
public void setToMedianOf(EvolutionState state, Fitness[] fitnesses)