public class MultiObjectiveFitness extends Fitness
The object contains two items: an array of floating point values representing the various multiple fitnesses, and a flag (maximize) indicating whether higher is considered better. By default, isIdealFitness() always returns false; you might want to override that, though it'd be unusual -- what is the ideal fitness from the perspective of a pareto front?
The object also contains maximum and minimum fitness values suggested for the problem, on a per-objective basis. By default the maximum values are all 1.0 and the minimum values are all 0.0, but you can change these. Note that maximum does not mean "best" unless maximize is true.
The class also contains utility methods or computing pareto dominance, Pareto Fronts and Pareto Front Ranks, and distance in multiobjective space. The default comparison operators use Pareto Dominance, though this is often overridden by subclasses.
The fitness() method returns the maximum of the fitness values, which is clearly nonsensical: you should not be using this method.
Subclasses of this class may add certain auxiliary fitness measures which are printed out by MultiObjectiveStatistics along with the multiple objectives. To have these values printed out, override the getAuxiliaryFitnessNames() and getAuxiliaryFitnessValues() methods.
Parameters
base.num-objectives (else)multi.num-objectives int >= 1 |
(the number of fitnesses in the objectives array) |
base.maximize bool = true (default) or false |
(are higher values considered "better"?) |
Default Base
multi.fitness
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FITNESS_POSTAMBLE |
boolean[] |
maximize
Maximization.
|
double[] |
maxObjective
Desired maximum fitness values.
|
double[] |
minObjective
Desired minimum fitness values.
|
static java.lang.String |
MULTI_FITNESS_POSTAMBLE |
protected double[] |
objectives
The various fitnesses.
|
static java.lang.String |
P_MAXIMIZE
Is higher better?
|
static java.lang.String |
P_MAXOBJECTIVES
parameter for max fitness values
|
static java.lang.String |
P_MINOBJECTIVES
parameter for min fitness values
|
static java.lang.String |
P_NUMOBJECTIVES
parameter for size of objectives
|
context, FITNESS_PREAMBLE, P_FITNESS, trials
Constructor and Description |
---|
MultiObjectiveFitness() |
Modifier and Type | Method and Description |
---|---|
boolean |
betterThan(Fitness fitness)
Returns true if I'm better than _fitness.
|
java.lang.Object |
clone()
Creates a new individual cloned from a prototype,
and suitable to begin use in its own evolutionary
context.
|
Parameter |
defaultBase()
Returns the default base for this prototype.
|
boolean |
equivalentTo(Fitness _fitness)
Returns true if I'm equivalent in fitness (neither better nor worse) to
_fitness.
|
double |
fitness()
Returns the Max() of objectives, which adheres to Fitness.java's protocol
for this method.
|
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.
|
java.lang.String[] |
getAuxilliaryFitnessNames()
Returns auxilliary fitness value names to be printed by the statistics object.
|
double[] |
getAuxilliaryFitnessValues()
Returns auxilliary fitness values to be printed by the statistics object.
|
int |
getNumObjectives() |
double |
getObjective(int i) |
double[] |
getObjectives()
Returns the objectives as an array.
|
static int[] |
getRankings(java.util.ArrayList<Individual> inds)
Returns the Pareto rank for each individual.
|
boolean |
isIdealFitness()
Returns true if this fitness is the "ideal" fitness.
|
boolean |
isMaximizing()
Deprecated.
Use isMaximizing(objective). This function now just returns whether the first objective is maximizing.
|
boolean |
isMaximizing(int objective) |
double |
manhattanObjectiveDistance(MultiObjectiveFitness other)
Returns the Manhattan difference between two Fitnesses in Objective space.
|
boolean |
paretoDominates(MultiObjectiveFitness other)
Returns true if I'm better than _fitness.
|
static java.util.ArrayList<Individual> |
partitionIntoParetoFront(java.util.ArrayList<Individual> inds,
java.util.ArrayList<Individual> front,
java.util.ArrayList<Individual> nonFront)
Divides an array of Individuals into the Pareto front and the "nonFront" (everyone else).
|
static java.util.ArrayList<java.util.ArrayList<Individual>> |
partitionIntoRanks(java.util.ArrayList<Individual> inds)
Divides inds into pareto front ranks (each an ArrayList), and returns them, in order,
stored in an ArrayList.
|
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 |
setObjectives(EvolutionState state,
double[] newObjectives) |
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.
|
double |
sumSquaredObjectiveDistance(MultiObjectiveFitness other)
Returns the sum of the squared difference between two Fitnesses in Objective space.
|
void |
writeFitness(EvolutionState state,
java.io.DataOutput dataOutput)
Writes the binary form of an individual out to a DataOutput.
|
compareTo, contextIsBetterThan, getContext, merge, printFitness, printFitness, printFitness, printFitnessForHumans, printFitnessForHumans, readTrials, setContext, setContext, writeTrials
public static final java.lang.String MULTI_FITNESS_POSTAMBLE
public static final java.lang.String FITNESS_POSTAMBLE
public static final java.lang.String P_NUMOBJECTIVES
public static final java.lang.String P_MAXOBJECTIVES
public static final java.lang.String P_MINOBJECTIVES
public static final java.lang.String P_MAXIMIZE
public double[] maxObjective
public double[] minObjective
public boolean[] maximize
protected double[] objectives
public java.lang.String[] getAuxilliaryFitnessNames()
public double[] getAuxilliaryFitnessValues()
public boolean isMaximizing()
public boolean isMaximizing(int objective)
public int getNumObjectives()
public double[] getObjectives()
public double getObjective(int i)
public void setObjectives(EvolutionState state, double[] newObjectives)
public Parameter defaultBase()
Prototype
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 double fitness()
public void setup(EvolutionState state, Parameter base)
public boolean isIdealFitness()
isIdealFitness
in class Fitness
public boolean equivalentTo(Fitness _fitness)
equivalentTo
in class Fitness
public boolean betterThan(Fitness fitness)
betterThan
in class Fitness
public boolean paretoDominates(MultiObjectiveFitness other)
public static java.util.ArrayList<Individual> partitionIntoParetoFront(java.util.ArrayList<Individual> inds, java.util.ArrayList<Individual> front, java.util.ArrayList<Individual> nonFront)
public static java.util.ArrayList<java.util.ArrayList<Individual>> partitionIntoRanks(java.util.ArrayList<Individual> inds)
public static int[] getRankings(java.util.ArrayList<Individual> inds)
public double sumSquaredObjectiveDistance(MultiObjectiveFitness other)
public double manhattanObjectiveDistance(MultiObjectiveFitness other)
public java.lang.String fitnessToString()
Fitness
fitnessToString
in class Fitness
public java.lang.String fitnessToStringForHumans()
Fitness
fitnessToStringForHumans
in class Fitness
public void readFitness(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException
Fitness
readFitness
in class Fitness
java.io.IOException
public void writeFitness(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
Fitness
writeFitness
in class Fitness
java.io.IOException
public void readFitness(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
Fitness
readFitness
in class Fitness
java.io.IOException
public void setToBestOf(EvolutionState state, Fitness[] fitnesses)
Fitness
setToBestOf
in class Fitness
public void setToMeanOf(EvolutionState state, Fitness[] fitnesses)
Fitness
setToMeanOf
in class Fitness
public void setToMedianOf(EvolutionState state, Fitness[] fitnesses)
Fitness
setToMedianOf
in class Fitness