Class SimpleFitness
- All Implemented Interfaces:
Prototype,Setup,Serializable,Cloneable,Comparable<Object>
- Direct Known Subclasses:
DOVSFitness
Some kinds of selection methods require a more stringent definition of fitness. For example, FitProportionateSelection requires that fitnesses be non-negative (since it must place them into a proportionate distribution). You may wish to restrict yourself to values in [0,1] or [0,infinity) in such cases.
Default Base
simple.fitness
- See Also:
-
Field Summary
FieldsFields inherited from class ec.Fitness
context, FITNESS_PREAMBLE, P_FITNESS, trials -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbetterThan(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.Returns the default base for this prototype.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.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.booleanShould return true if this is a good enough fitness to end the runvoidreadFitness(EvolutionState state, DataInput dataInput) Reads the binary form of an individual from a DataInput.voidreadFitness(EvolutionState state, LineNumberReader reader) Presently does not decode the fact that the fitness is ideal or notvoidsetFitness(EvolutionState state, double _f) Deprecated -- now redefined to set the fitness but ALWAYS say that it's not ideal.voidsetFitness(EvolutionState state, double _f, boolean _isIdeal) voidsetToMeanOf(EvolutionState state, Fitness[] fitnesses) Sets the fitness to be the same value as the mean 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.Methods inherited from class ec.Fitness
clone, compareTo, contextIsBetterThan, getContext, merge, printFitness, printFitness, printFitness, printFitnessForHumans, printFitnessForHumans, readTrials, setContext, setContext, setToBestOf, setToMedianOf, writeTrials
-
Field Details
-
isIdeal
protected boolean isIdeal
-
-
Constructor Details
-
SimpleFitness
public SimpleFitness()
-
-
Method Details
-
defaultBase
Description copied from interface:PrototypeReturns the default base for this prototype. This should generally be implemented by building off of the static base() method on the DefaultsForm object for the prototype's package. This should be callable during setup(...). -
setFitness
Deprecated -- now redefined to set the fitness but ALWAYS say that it's not ideal. If you need to specify that it's ideal, you should use the new function setFitness(final EvolutionState state, double _f, boolean _isIdeal). -
setFitness
-
fitness
public double fitness()Description copied from class:FitnessShould 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.
-
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.
-
isIdealFitness
public boolean isIdealFitness()Description copied from class:FitnessShould return true if this is a good enough fitness to end the run- Specified by:
isIdealFitnessin classFitness
-
equivalentTo
Description copied from class:FitnessShould 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.- Specified by:
equivalentToin classFitness
-
betterThan
Description copied from class:FitnessShould 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.- Specified by:
betterThanin classFitness
-
fitnessToString
Description copied from class:FitnessPrint 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.- Overrides:
fitnessToStringin classFitness
-
fitnessToStringForHumans
Description copied from class:FitnessPrint 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.- Overrides:
fitnessToStringForHumansin classFitness
-
readFitness
Presently does not decode the fact that the fitness is ideal or not- Overrides:
readFitnessin classFitness- Throws:
IOException
-
writeFitness
Description copied from class:FitnessWrites 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.- Overrides:
writeFitnessin classFitness- Throws:
IOException
-
readFitness
Description copied from class:FitnessReads 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.- Overrides:
readFitnessin classFitness- Throws:
IOException
-
setToMeanOf
Description copied from class:FitnessSets 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.- Overrides:
setToMeanOfin classFitness
-