Class Fitness
- All Implemented Interfaces:
Prototype,Setup,Serializable,Cloneable,Comparable<Object>
- Direct Known Subclasses:
KozaFitness,MultiObjectiveFitness,SimpleFitness
Rules:
| comparison | method |
| a > b | a.betterThan(b) |
| a >= b | a.betterThan(b) || a.equivalentTo(b) |
| a = b | a.equivalentTo(b) |
- a dominates b :: a > b
- a and b do not dominate each other :: a = b
- b dominates a :: a < b
Parameter bases
| fit | default fitness base |
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionAuxiliary variable, used by coevolutionary processes, to store the individuals involved in producing this given Fitness value.static final StringBasic preamble for printing Fitness values outstatic final Stringbase parameter for defaultsAuxiliary variable, used by coevolutionary processes, to compute the number of trials used to compute this Fitness value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanbetterThan(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.clone()Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.intReturns -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.booleancontextIsBetterThan(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 booleanequivalentTo(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 doublefitness()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).Print to a string the fitness in a fashion intended to be parsed in again via readFitness(...).Print to a string the fitness in a fashion readable by humans, and not intended to be parsed in again.Treat the Individual[] you receive from this as read-only.abstract booleanShould return true if this is a good enough fitness to end the runvoidmerge(EvolutionState state, Fitness other) Merges the other fitness into this fitness.voidprintFitness(EvolutionState state, int log) Should print the fitness out in a computer-readable fashion, with a verbosity of Output.V_NO_GENERAL.voidprintFitness(EvolutionState state, int log, int verbosity) Should print the fitness out in a computer-readable fashion, using state.output.println(...,verbosity,log).voidprintFitness(EvolutionState state, PrintWriter writer) Should print the fitness out in a computer-readable fashion, using writer.println(...).voidprintFitnessForHumans(EvolutionState state, int log) Should print the fitness out fashion pleasing for humans to read, with a verbosity of Output.V_NO_GENERAL.voidprintFitnessForHumans(EvolutionState state, int log, int verbosity) Should print the fitness out fashion pleasing for humans to read, using state.output.println(...,verbosity,log).voidreadFitness(EvolutionState state, DataInput dataInput) Reads the binary form of an individual from a DataInput.voidreadFitness(EvolutionState state, LineNumberReader reader) Reads in the fitness from a form outputted by fitnessToString() and thus printFitnessForHumans(...).voidreadTrials(EvolutionState state, DataInput dataInput) Reads trials in from DataInput.voidsetContext(Individual[] cont) voidsetContext(Individual[] cont, int index) voidsetToBestOf(EvolutionState state, Fitness[] fitnesses) Sets the fitness to be the same value as the best of the provided fitnesses.voidsetToMeanOf(EvolutionState state, Fitness[] fitnesses) Sets the fitness to be the same value as the mean of the provided fitnesses.voidsetToMedianOf(EvolutionState state, Fitness[] fitnesses) Sets the fitness to be the median of the provided fitnesses.voidsetup(EvolutionState state, Parameter base) Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.voidwriteFitness(EvolutionState state, DataOutput dataOutput) Writes the binary form of an individual out to a DataOutput.voidwriteTrials(EvolutionState state, DataOutput dataOutput) Writes trials out to DataOutputMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ec.Prototype
defaultBase
-
Field Details
-
trials
Auxiliary variable, used by coevolutionary processes, to compute the number of trials used to compute this Fitness value. By default trials=null and stays that way. If you set this variable, all of the elements of the ArrayList must be immutable -- once they're set they never change internally. -
context
Auxiliary variable, used by coevolutionary processes, to store the individuals involved in producing this given Fitness value. By default context=null and stays that way. Note that individuals stored here may possibly not themselves have Fitness values to avoid circularity when cloning. -
P_FITNESS
base parameter for defaults- See Also:
-
FITNESS_PREAMBLE
Basic preamble for printing Fitness values out- See Also:
-
-
Constructor Details
-
Fitness
public Fitness()
-
-
Method Details
-
setContext
-
setContext
-
getContext
Treat the Individual[] you receive from this as read-only. -
fitness
public 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). This should be interpreted as: negative infinity is worse than the WORST possible fitness, and positive infinity is better than the IDEAL 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.
-
isIdealFitness
public abstract boolean isIdealFitness()Should return true if this is a good enough fitness to end the run -
equivalentTo
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. You may assume that _fitness is of the same class as yourself. For any two fitnesses fit1 and fit2 of the same class, it must be the case that fit1.equivalentTo(fit2) == fit2.equivalentTo(fit1), and that only one of fit1.betterThan(fit2), fit1.equivalentTo(fit2), and fit2.betterThan(fit1) can be true. -
betterThan
Should return true if this fitness is clearly better than _fitness; You may assume that _fitness is of the same class as yourself. For any two fitnesses fit1 and fit2 of the same class, it must be the case that fit1.equivalentTo(fit2) == fit2.equivalentTo(fit1), and that only one of fit1.betterThan(fit2), fit1.equivalentTo(fit2), and fit2.betterThan(fit1) can be true. -
printFitnessForHumans
Should print the fitness out fashion pleasing for humans to read, with a verbosity of Output.V_NO_GENERAL. -
printFitnessForHumans
Should print the fitness out fashion pleasing for humans to read, using state.output.println(...,verbosity,log). The default version of this method calls fitnessToStringForHumans(), adds context (collaborators) if any, and printlns the resultant string. -
printFitness
Should print the fitness out in a computer-readable fashion, with a verbosity of Output.V_NO_GENERAL. -
printFitness
Should print the fitness out in a computer-readable fashion, using state.output.println(...,verbosity,log). You might use ec.util.Code to encode fitness values. The default version of this method calls fitnessToString() and println's the resultant string. -
printFitness
Should print the fitness out in a computer-readable fashion, using writer.println(...). You might use ec.util.Code to encode fitness values. The default version of this method calls fitnessToString() and println's the resultant string. -
readFitness
Reads in the fitness from a form outputted by fitnessToString() and thus printFitnessForHumans(...). The default version of this method exits the program with an "unimplemented" error.- Throws:
IOException
-
fitnessToStringForHumans
Print to a string the fitness in a fashion readable by humans, and not intended to be parsed in again. The default form simply calls toString(), but you'll probably want to override this to something else. -
fitnessToString
Print to a string the fitness in a fashion intended to be parsed in again via readFitness(...). The fitness and evaluated flag should not be included. The default form simply calls toString(), which is almost certainly wrong, and you'll probably want to override this to something else. When overriding, you may wish to check to see if the 'trials' variable is non-null, and issue an error if so. -
writeFitness
Writes the binary form of an individual out to a DataOutput. This is not for serialization: the object should only write out the data relevant to the object sufficient to rebuild it from a DataInput. The default version exits the program with an "unimplemented" error; you should override this, and be certain to also write the 'trials' variable as well.- Throws:
IOException
-
writeTrials
Writes trials out to DataOutput- Throws:
IOException
-
readFitness
Reads the binary form of an individual from a DataInput. This is not for serialization: the object should only read in the data written out via printIndividual(state,dataInput). The default version exits the program with an "unimplemented" error; you should override this, and be certain to also write the 'trials' variable as well.- Throws:
IOException
-
readTrials
Reads trials in from DataInput.- Throws:
IOException
-
contextIsBetterThan
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. This method by default assumes that trials are Doubles, and that higher Doubles are better. If you are using distributed evaluation and coevolution and your tirals are otherwise, you need to override this method. -
merge
Merges the other fitness into this fitness. May destroy the other Fitness in the process. This method is typically called by coevolution in combination with distributed evauation where the Individual may be sent to various different sites to have trials performed on it, and the results must be merged together to form a relevant fitness. By default merging occurs as follows. First, the trials arrays are concatenated. Then whoever has the best trial has his context retained: this Fitness is determined by calling contextIsBetterThan(other). By default that method assumes that trials are Doubles, and that higher values are better. You will wish to override that method if trials are different. In coevolution nothing else needs to be merged usually, though you may need to override this to handle other things specially.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().
-
clone
Description copied from interface:PrototypeCreates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.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:
- If you hold objects which are shared with other instances, don't clone them.
- If you hold objects which must be unique, clone them.
- If you hold objects which were given to you as a gesture of kindness, and aren't owned by you, you probably shouldn't clone them.
- DON'T attempt to clone: Singletons, Cliques, or Populations, or Subpopulation.
- Arrays are not cloned automatically; you may need to clone an array if you're not sharing it with other instances. Arrays have the nice feature of being copyable by calling clone() on them.
Implementations.
- If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are abstract, then you should not declare clone().
- If no ancestor of yours implements clone(),
and you have no need to do clone deeply,
and you are not abstract, then you should implement
it as follows:
public Object clone() { try { return super.clone(); } catch ((CloneNotSupportedException e) { throw new InternalError(); } // never happens } - If no ancestor of yours implements clone(), but you
need to deep-clone some things, then you should implement it
as follows:
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; } - If an ancestor has implemented clone(), and you also need
to deep clone some things, then you should implement it as follows:
public Object clone() { MyObject myobj = (MyObject) (super.clone()); // put your deep-cloning code here... return myobj; }
-
setup
Description copied from interface:PrototypeSets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.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.
-
compareTo
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.- Specified by:
compareToin interfaceComparable<Object>
-
setToBestOf
Sets the fitness to be the same value as the best of the provided fitnesses. This method calls setToMeanOf(...), so if that method is unimplemented, this method will also fail. -
setToMeanOf
Sets the fitness to be the same value as the mean of the provided fitnesses. The default version of this method exits with an "unimplemented" error; you should override this. -
setToMedianOf
Sets the fitness to be the median of the provided fitnesses. This method calls setToMeanOf(...), so if that method is unimplemented, this method will also fail.
-