Package ec.gp.koza

# Class KozaFitness

java.lang.Object
ec.Fitness
ec.gp.koza.KozaFitness

All Implemented Interfaces:
  `Prototype`, `Setup`, `Serializable`, `Cloneable`, `Comparable<Object>`

public class KozaFitness extends Fitness
KozaFitness is a Fitness which stores an individual's fitness as described in Koza I. Well, almost. In KozaFitness, standardized fitness and raw fitness are considered the same (there are different methods for them, but they return the same thing). Standardized fitness ranges from 0.0 inclusive (the best) to infinity exclusive (the worst). Adjusted fitness converts this, using the formula adj_f = 1/(1+f), into a scale from 0.0 exclusive (worst) to 1.0 inclusive (best). While it's the standardized fitness that is stored, it is the adjusted fitness that is printed out. This is all just convenience stuff anyway; selection methods generally don't use these fitness values but instead use the betterThan and equalTo methods.

Default Base
gp.koza.fitness

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `int`
  `hits`
  This auxillary measure is used in some problems for additional information.
  `static final String`
  `P_KOZAFITNESS`
  `protected double`
  `standardizedFitness`
  This ranges from 0 (best) to infinity (worst).

  ### Fields inherited from class ec.Fitness

  `context, FITNESS_PREAMBLE, P_FITNESS, trials`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `KozaFitness()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `double`
  `adjustedFitness()`
  Returns the adjusted fitness metric, which recasts the fitness to the half-open interval (0,1], where 1 is ideal and 0 is worst.
  `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.
  `Parameter`
  `defaultBase()`
  Returns the default base for this prototype.
  `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.
  `double`
  `fitness()`
  Returns the adjusted fitness metric, which recasts the fitness to the half-open interval (0,1], where 1 is ideal and 0 is worst.
  `String`
  `fitnessToString()`
  Print to a string the fitness in a fashion intended to be parsed in again via readFitness(...).
  `String`
  `fitnessToStringForHumans()`
  Print to a string the fitness in a fashion readable by humans, and not intended to be parsed in again.
  `boolean`
  `isIdealFitness()`
  Should return true if this is a good enough fitness to end the run
  `double`
  `rawFitness()`
  Returns the raw fitness metric.
  `void`
  `readFitness(EvolutionState state, DataInput dataInput)`
  Reads the binary form of an individual from a DataInput.
  `void`
  `readFitness(EvolutionState state, LineNumberReader reader)`
  Reads in the fitness from a form outputted by fitnessToString() and thus printFitnessForHumans(...).
  `void`
  `setFitness(EvolutionState state, double _f)`
  Do not use this function.
  `void`
  `setStandardizedFitness(EvolutionState state, double _f)`
  Set the standardized fitness in the half-open interval [0.0,infinity) which is defined (NOTE: DIFFERENT FROM fitness()!!!) as 0.0 being the IDEAL and infinity being worse than the worst possible.
  `void`
  `setToMeanOf(EvolutionState state, Fitness[] fitnesses)`
  Sets the fitness to be the same value as the mean 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.
  `double`
  `standardizedFitness()`
  Returns the standardized fitness metric.
  `void`
  `writeFitness(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`

  ### Methods inherited from class java.lang.Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### P_KOZAFITNESS

    public static final String P_KOZAFITNESS
    See Also:
      - Constant Field Values

  - ### standardizedFitness

    protected double standardizedFitness
    This ranges from 0 (best) to infinity (worst). I define it here as equivalent to the standardized fitness.

  - ### hits

    public int hits
    This auxillary measure is used in some problems for additional information. It's a traditional feature of Koza-style GP, and so although I think it's not very useful, I'll leave it in anyway.

- ## Constructor Details

  - ### KozaFitness

    public KozaFitness()

- ## Method Details

  - ### defaultBase

    public Parameter defaultBase()
    Description copied from interface: `Prototype`
    Returns 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

    public void setFitness(EvolutionState state, double _f)
    Do not use this function. Use the identical setStandardizedFitness() instead. The reason for the name change is that fitness() returns a differently-defined value than setFitness() sets, ugh.

  - ### setStandardizedFitness

    public void setStandardizedFitness(EvolutionState state, double _f)
    Set the standardized fitness in the half-open interval [0.0,infinity) which is defined (NOTE: DIFFERENT FROM fitness()!!!) as 0.0 being the IDEAL and infinity being worse than the worst possible. This is the GP tradition. The fitness() function instead will output the equivalent of Adjusted Fitness.

  - ### fitness

    public double fitness()
    Returns the adjusted fitness metric, which recasts the fitness to the half-open interval (0,1], where 1 is ideal and 0 is worst. Same as adjustedFitness().
    Specified by:
      `fitness` in class `Fitness`

  - ### rawFitness

    public double rawFitness()
    Returns the raw fitness metric.

  - ### standardizedFitness

    public double standardizedFitness()
    Returns the standardized fitness metric.

  - ### adjustedFitness

    public double adjustedFitness()
    Returns the adjusted fitness metric, which recasts the fitness to the half-open interval (0,1], where 1 is ideal and 0 is worst. This metric is used when printing the fitness out.

  - ### setup

    public void setup(EvolutionState state, Parameter base)
    Description copied from interface: `Prototype`
    Sets 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.

    Specified by:
      `setup` in interface `Prototype`
    Specified by:
      `setup` in interface `Setup`
    Overrides:
      `setup` in class `Fitness`

  - ### isIdealFitness

    public boolean isIdealFitness()
    Description copied from class: `Fitness`
    Should return true if this is a good enough fitness to end the run
    Specified by:
      `isIdealFitness` in class `Fitness`

  - ### equivalentTo

    public boolean equivalentTo(Fitness _fitness)
    Description copied from class: `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. 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:
      `equivalentTo` in class `Fitness`

  - ### betterThan

    public boolean betterThan(Fitness _fitness)
    Description copied from class: `Fitness`
    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.
    Specified by:
      `betterThan` in class `Fitness`

  - ### fitnessToString

    public String fitnessToString()
    Description copied from class: `Fitness`
    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.
    Overrides:
      `fitnessToString` in class `Fitness`

  - ### fitnessToStringForHumans

    public String fitnessToStringForHumans()
    Description copied from class: `Fitness`
    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.
    Overrides:
      `fitnessToStringForHumans` in class `Fitness`

  - ### readFitness

    public void readFitness(EvolutionState state, LineNumberReader reader) throws IOException
    Description copied from class: `Fitness`
    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.
    Overrides:
      `readFitness` in class `Fitness`
    Throws:
      `IOException`

  - ### writeFitness

    public void writeFitness(EvolutionState state, DataOutput dataOutput) throws IOException
    Description copied from class: `Fitness`
    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.
    Overrides:
      `writeFitness` in class `Fitness`
    Throws:
      `IOException`

  - ### readFitness

    public void readFitness(EvolutionState state, DataInput dataInput) throws IOException
    Description copied from class: `Fitness`
    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.
    Overrides:
      `readFitness` in class `Fitness`
    Throws:
      `IOException`

  - ### setToMeanOf

    public void setToMeanOf(EvolutionState state, Fitness[] fitnesses)
    Description copied from class: `Fitness`
    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.
    Overrides:
      `setToMeanOf` in class `Fitness`