Documentation of 'ec.Fitness' Java class
Fitness
ec

Class Fitness

  • All Implemented Interfaces:
    Prototype, Setup, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable
    Direct Known Subclasses:
    KozaFitness, MultiObjectiveFitness, SimpleFitness


    public abstract class Fitness
    extends java.lang.Object
    implements Prototype, java.lang.Comparable
    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:

    comparisonmethod
    a > ba.betterThan(b)
    a >= ba.betterThan(b) || a.equivalentTo(b)
    a = ba.equivalentTo(b)
    This applies even to multiobjective pareto-style dominance, eg:
    • 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:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      Individual[] context
      Auxiliary variable, used by coevolutionary processes, to store the individuals involved in producing this given Fitness value.
      static java.lang.String FITNESS_PREAMBLE
      Basic preamble for printing Fitness values out
      static java.lang.String P_FITNESS
      base parameter for defaults
      java.util.ArrayList trials
      Auxiliary variable, used by coevolutionary processes, to compute the number of trials used to compute this Fitness value.
    • Constructor Summary

      Constructors 
      Constructor and Description
      Fitness() 
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method and Description
      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.
      java.lang.Object clone()
      Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
      int compareTo(java.lang.Object o)
      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.
      boolean contextIsBetterThan(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 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 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).
      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.
      Individual[] getContext()
      Treat the Individual[] you receive from this as read-only.
      abstract boolean isIdealFitness()
      Should return true if this is a good enough fitness to end the run
      void merge(EvolutionState state, Fitness other)
      Merges the other fitness into this fitness.
      void printFitness(EvolutionState state, int log)
      Should print the fitness out in a computer-readable fashion, with a verbosity of Output.V_NO_GENERAL.
      void printFitness(EvolutionState state, int log, int verbosity)
      Deprecated. 
      Verbosity no longer has meaning
      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)
      Should print the fitness out fashion pleasing for humans to read, with a verbosity of Output.V_NO_GENERAL.
      void printFitnessForHumans(EvolutionState state, int log, int verbosity)
      Deprecated. 
      Verbosity no longer has meaning
      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 readTrials(EvolutionState state, java.io.DataInput dataInput)
      Reads trials in from DataInput.
      void setContext(Individual[] cont) 
      void setContext(Individual[] cont, int index) 
      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 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.
      void writeTrials(EvolutionState state, java.io.DataOutput dataOutput)
      Writes trials out to DataOutput
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • trials

        public java.util.ArrayList 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

        public Individual[] 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

        public static final java.lang.String P_FITNESS
        base parameter for defaults
        See Also:
        Constant Field Values
      • FITNESS_PREAMBLE

        public static final java.lang.String FITNESS_PREAMBLE
        Basic preamble for printing Fitness values out
        See Also:
        Constant Field Values
    • Constructor Detail

      • Fitness

        public Fitness()
    • Method Detail

      • setContext

        public void setContext(Individual[] cont,
                               int index)
      • setContext

        public void setContext(Individual[] cont)
      • getContext

        public Individual[] 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

        public 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. 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

        public 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. 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

        public void printFitnessForHumans(EvolutionState state,
                                          int log)
        Should print the fitness out fashion pleasing for humans to read, with a verbosity of Output.V_NO_GENERAL.
      • printFitnessForHumans

        public void printFitnessForHumans(EvolutionState state,
                                          int log,
                                          int verbosity)
        Deprecated. Verbosity no longer has meaning
        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

        public void printFitness(EvolutionState state,
                                 int log)
        Should print the fitness out in a computer-readable fashion, with a verbosity of Output.V_NO_GENERAL.
      • printFitness

        public void printFitness(EvolutionState state,
                                 int log,
                                 int verbosity)
        Deprecated. Verbosity no longer has meaning
        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

        public void printFitness(EvolutionState state,
                                 java.io.PrintWriter writer)
        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

        public void readFitness(EvolutionState state,
                                java.io.LineNumberReader reader)
                         throws java.io.IOException
        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:
        java.io.IOException
      • fitnessToStringForHumans

        public java.lang.String 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

        public java.lang.String 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

        public void writeFitness(EvolutionState state,
                                 java.io.DataOutput dataOutput)
                          throws java.io.IOException
        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:
        java.io.IOException
      • writeTrials

        public void writeTrials(EvolutionState state,
                                java.io.DataOutput dataOutput)
                         throws java.io.IOException
        Writes trials out to DataOutput
        Throws:
        java.io.IOException
      • readFitness

        public void readFitness(EvolutionState state,
                                java.io.DataInput dataInput)
                         throws java.io.IOException
        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:
        java.io.IOException
      • readTrials

        public void readTrials(EvolutionState state,
                               java.io.DataInput dataInput)
                        throws java.io.IOException
        Reads trials in from DataInput.
        Throws:
        java.io.IOException
      • contextIsBetterThan

        public boolean contextIsBetterThan(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. 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

        public void merge(EvolutionState state,
                          Fitness other)
        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

        public java.lang.Object clone()
        Description copied from interface: Prototype
        Creates 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 Groups.
        • 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;
               } 
                  
        Specified by:
        clone in interface Prototype
        Overrides:
        clone in class java.lang.Object
      • 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
      • compareTo

        public int compareTo(java.lang.Object o)
        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:
        compareTo in interface java.lang.Comparable
      • setToBestOf

        public void setToBestOf(EvolutionState state,
                                Fitness[] fitnesses)
        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

        public void setToMeanOf(EvolutionState state,
                                Fitness[] fitnesses)
        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

        public void setToMedianOf(EvolutionState state,
                                  Fitness[] fitnesses)
        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.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.