|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectec.Fitness
Fitness is a prototype which describes the fitness of an individual. Every individual contains exactly one Fitness object. Fitness objects are compared to each other with the equivalentTo() and betterThan(), etc. methods.
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 |
Field Summary | |
static java.lang.String |
P_FITNESS
|
Constructor Summary | |
Fitness()
|
Method Summary | |
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. |
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 float |
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. |
abstract boolean |
isIdealFitness()
Should return true if this is a good enough fitness to end the run |
void |
printFitness(EvolutionState state,
int log,
int verbosity)
Should print the fitness out in a computer-readable fashion, using state.output.println(...,verbosity,log). |
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,
int verbosity)
Should print the fitness out fashion pleasing for humans to read, using state.output.println(...,verbosity,log). |
java.lang.Object |
protoClone()
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context. |
java.lang.Object |
protoCloneSimple()
This should be implemented in a the top-level Prototype ONLY; in fact, it should probably be declared final. |
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 |
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface ec.Prototype |
defaultBase |
Field Detail |
public static final java.lang.String P_FITNESS
Constructor Detail |
public Fitness()
Method Detail |
public abstract float 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, int verbosity)
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.lang.CloneNotSupportedException
java.io.IOException
java.lang.CloneNotSupportedException
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 readFitness(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException, java.lang.CloneNotSupportedException
java.io.IOException
java.lang.CloneNotSupportedException
public java.lang.Object protoClone() throws java.lang.CloneNotSupportedException
Prototype
The question here is whether or not this means to perform a "deep" or "light" ("shallow") clone, or something in-between. You may need to deep-clone parts of your object rather than simply copying their references, depending on the situation:
Implementations.
public Object protoClone() throws CloneNotSupportedException
{
return super.clone();
}
public Object protoClone() throws CloneNotSupportedException
{
myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
public Object protoClone() throws CloneNotSupportedException
{
MyObject myobj = (MyObject)(super.protoClone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
If you know that your superclasses will never change their protoClone() implementations, you might try inlining them in your overridden protoClone() method. But this is dangerous (though it yields a small net increase).
In general, you want to keep your deep cloning to an absolute minimum, so that you don't have to call protoClone() but one time.
The approach taken here is the fastest that I am aware of while still permitting objects to be specified at runtime from a parameter file. It would be faster to use the "new" operator; but that would require hard-coding that we can't do. Although using java.lang.Object.clone() entails an extra layer that deals with stripping away the "protected" keyword and also wrapping the exception handling (which is a BIG hit, about three times as slow as using "new"), it's still MUCH faster than using java.lang.Class.newInstance(), and also much faster than rolling our own Clone() method.
protoClone
in interface Prototype
java.lang.CloneNotSupportedException
public java.lang.Object protoCloneSimple()
Prototype
public final Object protoCloneSimple()
{
try { return protoClone(); }
catch (CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
protoCloneSimple
in interface Prototype
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.
setup
in interface Prototype
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |