Documentation of 'ec.gp.GPIndividual' Java class
GPIndividual
ec.gp

Class GPIndividual

  • All Implemented Interfaces:
    Prototype, Setup, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable


    public class GPIndividual
    extends Individual
    GPIndividual is an Individual used for GP evolution runs. GPIndividuals contain, at the very least, a nonempty array of GPTrees. You can use GPIndividual directly, or subclass it to extend it as you see fit.

    GPIndividuals have two clone methods: clone() and lightClone(). clone() is a deep clone method as usual. lightClone() is a light clone which does not copy the trees.

    In addition to serialization for checkpointing, Individuals may read and write themselves to streams in three ways.

    • writeIndividual(...,DataOutput)/readIndividual(...,DataInput)   This method transmits or receives an individual in binary. It is the most efficient approach to sending individuals over networks, etc. These methods write the evaluated flag and the fitness, then call readGenotype/writeGenotype, which you must implement to write those parts of your Individual special to your functions-- the default versions of readGenotype/writeGenotype throw errors. You don't need to implement them if you don't plan on using read/writeIndividual.
    • printIndividual(...,PrintWriter)/readIndividual(...,LineNumberReader)   This approach transmits or receives an indivdual in text encoded such that the individual is largely readable by humans but can be read back in 100% by ECJ as well. Because GPIndividuals are often very large, GPIndividual has overridden these methods -- they work differently than in Individual (the superclass). In specific: readIndividual by default reads in the fitness and the evaluation flag, then calls parseGenotype to read in the trees (via GPTree.readTree(...)). However printIndividual by default prints the fitness and evaluation flag, and prints all the trees by calling GPTree.printTree(...). It does not call genotypeToString at all. This is because it's very wasteful to build up a large string holding the printed form of the GPIndividual just to pump it out a stream once.
    • printIndividualForHumans(...,PrintWriter)   This approach prints an individual in a fashion intended for human consumption only. Because GPIndividuals are often very large, GPIndividual has overridden this methods -- it works differently than in Individual (the superclass). In specific: printIndividual by default prints the fitness and evaluation flag, and prints all the trees by calling GPTree.printTreeForHumans(...). It does not call genotypeToStringForHumans at all. This is because it's very wasteful to build up a large string holding the printed form of the GPIndividual just to pump it out a stream once.

      In general, the various readers and writers do three things: they tell the Fitness to read/write itself, they read/write the evaluated flag, and they read/write the GPTree array (by having each GPTree read/write itself). If you add instance variables to GPIndividual, you'll need to read/write those variables as well.

      Parameters

      base.numtrees
      int >= 1
      (number of trees in the GPIndividual)
      base.tree.n
      classname, inherits or = ec.gp.GPTree
      (class of tree n in the individual)

      Default Base
      gp.individual

      Parameter bases

      base.tree.n tree n in the individual
    See Also:
    Serialized Form
    • Constructor Detail

      • GPIndividual

        public GPIndividual()
    • Method Detail

      • 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(...).
      • equals

        public boolean equals(java.lang.Object ind)
        Description copied from class: Individual
        Returns true if I am genetically "equal" to ind. This should mostly be interpreted as saying that we are of the same class and that we hold the same data. It should NOT be a pointer comparison.
        Specified by:
        equals in class Individual
      • hashCode

        public int hashCode()
        Description copied from class: Individual
        Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.
        Specified by:
        hashCode in class Individual
      • verify

        public void verify(EvolutionState state)
        Verification of validity of the GPIndividual -- strictly for debugging purposes only
      • printTrees

        public void printTrees(EvolutionState state,
                               int log)
        Prints just the trees of the GPIndividual. Broken out like this to be used by GEIndividual to avoid re-printing the fitness and evaluated premables.
      • printIndividualForHumans

        public void printIndividualForHumans(EvolutionState state,
                                             int log)
        Description copied from class: Individual
        Should print the individual out in a pleasing way for humans, with a verbosity of Output.V_NO_GENERAL.
        Overrides:
        printIndividualForHumans in class Individual
      • printIndividual

        public void printIndividual(EvolutionState state,
                                    int log)
        Description copied from class: Individual
        Should print the individual in a way that can be read by computer, including its fitness, with a verbosity of Output.V_NO_GENERAL.
        Overrides:
        printIndividual in class Individual
      • printIndividual

        public void printIndividual(EvolutionState state,
                                    java.io.PrintWriter writer)
        Description copied from class: Individual
        Should print the individual in a way that can be read by computer, including its fitness. You can get fitness to print itself at the appropriate time by calling fitness.printFitness(state,log,writer); Usually you should try to use printIndividual(state,log,verbosity) instead -- use this method only if you can't print through the Output facility for some reason.

        The default form of this method simply prints out whether or not the individual has been evaluated, its fitness, and then calls Individual.genotypeToString(). Feel free to override this to produce more sophisticated behavior, though it is rare to need to -- instead you could just override genotypeToString().

        Overrides:
        printIndividual in class Individual
      • writeGenotype

        public void writeGenotype(EvolutionState state,
                                  java.io.DataOutput dataOutput)
                           throws java.io.IOException
        Overridden for the GPIndividual genotype.
        Overrides:
        writeGenotype in class Individual
        Throws:
        java.io.IOException
      • readGenotype

        public void readGenotype(EvolutionState state,
                                 java.io.DataInput dataInput)
                          throws java.io.IOException
        Overridden for the GPIndividual genotype.
        Overrides:
        readGenotype in class Individual
        Throws:
        java.io.IOException
      • parseGenotype

        public void parseGenotype(EvolutionState state,
                                  java.io.LineNumberReader reader)
                           throws java.io.IOException
        Description copied from class: Individual
        This method is used only by the default version of readIndividual(state,reader), and it is intended to be overridden to parse in that part of the individual that was outputted in the genotypeToString() method. The default version of this method exits the program with an "unimplemented" error. You'll want to override this method, or to override readIndividual(...) to not use this method.
        Throws:
        java.io.IOException
      • clone

        public java.lang.Object clone()
        Deep-clones the GPIndividual. Note that you should not deep-clone the prototypical GPIndividual stored in GPSpecies: they contain blank GPTrees with null roots, and this method, which calls GPTree.clone(), will produce a NullPointerException as a result. Instead, you probably want to use GPSpecies.newIndividual(...) if you're thinking of playing with the prototypical GPIndividual.
        Specified by:
        clone in interface Prototype
        Overrides:
        clone in class Individual
      • lightClone

        public GPIndividual lightClone()
        Like clone(), but doesn't force the GPTrees to deep-clone themselves.
      • size

        public long size()
        Returns the "size" of the individual, namely, the number of nodes in all of its subtrees.
        Overrides:
        size in class Individual

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.