ec.vector
Class FloatVectorIndividual

java.lang.Object
  |
  +--ec.Individual
        |
        +--ec.vector.VectorIndividual
              |
              +--ec.vector.FloatVectorIndividual
All Implemented Interfaces:
java.lang.Cloneable, Prototype, java.io.Serializable, Setup

public class FloatVectorIndividual
extends VectorIndividual

FloatVectorIndividual is a VectorIndividual whose genome is an array of floats. Gene values may range from species.mingene(x) to species.maxgene(x), inclusive. The default mutation method randomizes genes to new values in this range, with species.mutationProbability.

Default Base
vector.float-vect-ind

See Also:
Serialized Form

Field Summary
 float[] genome
           
static java.lang.String P_FLOATVECTORINDIVIDUAL
           
 
Fields inherited from class ec.vector.VectorIndividual
EVALUATED_PREAMBLE
 
Fields inherited from class ec.Individual
evaluated, fitness, species
 
Constructor Summary
FloatVectorIndividual()
           
 
Method Summary
 Parameter defaultBase()
          Returns the default base for this prototype.
 void defaultCrossover(EvolutionState state, int thread, VectorIndividual ind)
          Destructively crosses over the individual with another in some default manner.
 void defaultMutate(EvolutionState state, int thread)
          Destructively mutates the individual in some default manner.
 boolean equals(java.lang.Object ind)
          Returns true if I am genetically "equal" to ind.
 long genomeLength()
          Returns the length of the gene array.
 java.lang.Object getGenome()
          Returns the gene array.
 int hashCode()
          Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.
 void join(java.lang.Object[] pieces)
          Joins the n pieces and sets the genome to their concatenation.
 void printIndividual(EvolutionState state, int log, int verbosity)
          Should print the individual in a way that can be read by computer, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitness(state,log,verbosity);
 void printIndividual(EvolutionState state, java.io.PrintWriter writer)
          Should print the individual in a way that can be read by computer, including its fitness.
 void printIndividualForHumans(EvolutionState state, int log, int verbosity)
          Should print the individual out in a pleasing way for humans, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitnessForHumans(state,log,verbosity);
 java.lang.Object protoClone()
          Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
 void readIndividual(EvolutionState state, java.io.LineNumberReader reader)
          Reads in the individual from a form printed by printIndividual().
 void reset(EvolutionState state, int thread)
          Initializes the individual by randomly choosing floats uniformly from mingene to maxgene.
 void setGenome(java.lang.Object gen)
          Sets the gene array.
 void setup(EvolutionState state, Parameter base)
          This should be used to set up only those things which you share in common with all other individuals in your species; individual-specific items which make you you should be filled in by Species.newIndividual(...), and modified by breeders.
 void split(int[] points, java.lang.Object[] pieces)
          Splits the genome into n pieces, according to points, which *must* be sorted.
 
Methods inherited from class ec.vector.VectorIndividual
size
 
Methods inherited from class ec.Individual
deepClone, protoCloneSimple
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

P_FLOATVECTORINDIVIDUAL

public static final java.lang.String P_FLOATVECTORINDIVIDUAL

genome

public float[] genome
Constructor Detail

FloatVectorIndividual

public FloatVectorIndividual()
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(...).

protoClone

public java.lang.Object protoClone()
                            throws java.lang.CloneNotSupportedException
Description copied from interface: Prototype
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.

The question here is whether or not this means to perform a "deep" or "light" ("shallow") clone, or something in-between. You may need to deep-clone parts of your object rather than simply copying their references, depending on the situation:

Implementations.

If you know that your superclasses will never change their protoClone() implementations, you might try inlining them in your overridden protoClone() method. But this is dangerous (though it yields a small net increase).

In general, you want to keep your deep cloning to an absolute minimum, so that you don't have to call protoClone() but one time.

The approach taken here is the fastest that I am aware of while still permitting objects to be specified at runtime from a parameter file. It would be faster to use the "new" operator; but that would require hard-coding that we can't do. Although using java.lang.Object.clone() entails an extra layer that deals with stripping away the "protected" keyword and also wrapping the exception handling (which is a BIG hit, about three times as slow as using "new"), it's still MUCH faster than using java.lang.Class.newInstance(), and also much faster than rolling our own Clone() method.

Overrides:
protoClone in class Individual

setup

public void setup(EvolutionState state,
                  Parameter base)
Description copied from class: Individual
This should be used to set up only those things which you share in common with all other individuals in your species; individual-specific items which make you you should be filled in by Species.newIndividual(...), and modified by breeders.
Overrides:
setup in class Individual
Following copied from class: ec.Individual
See Also:
Prototype.setup(EvolutionState,Parameter)

defaultCrossover

public void defaultCrossover(EvolutionState state,
                             int thread,
                             VectorIndividual ind)
Description copied from class: VectorIndividual
Destructively crosses over the individual with another in some default manner. In most implementations provided in ECJ, one-, two-, and any-point crossover is done with a for loop, rather than a possibly more efficient approach like arrayCopy(). The disadvantage is that arrayCopy() takes advantage of a CPU's bulk copying. The advantage is that arrayCopy() would require a scratch array, so you'd be allocing and GCing an array for every crossover. Dunno which is more efficient.
Overrides:
defaultCrossover in class VectorIndividual

split

public void split(int[] points,
                  java.lang.Object[] pieces)
Splits the genome into n pieces, according to points, which *must* be sorted. pieces.length must be 1 + points.length
Overrides:
split in class VectorIndividual

join

public void join(java.lang.Object[] pieces)
Joins the n pieces and sets the genome to their concatenation.
Overrides:
join in class VectorIndividual

defaultMutate

public void defaultMutate(EvolutionState state,
                          int thread)
Destructively mutates the individual in some default manner. The default form simply randomizes genes to a uniform distribution from the min and max of the gene values.
Overrides:
defaultMutate in class VectorIndividual

reset

public void reset(EvolutionState state,
                  int thread)
Initializes the individual by randomly choosing floats uniformly from mingene to maxgene.
Overrides:
reset in class VectorIndividual

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.
Overrides:
hashCode in class Individual

readIndividual

public void readIndividual(EvolutionState state,
                           java.io.LineNumberReader reader)
                    throws java.io.IOException,
                           java.lang.CloneNotSupportedException
Description copied from class: Individual
Reads in the individual from a form printed by printIndividual().
Overrides:
readIndividual in class Individual

printIndividualForHumans

public void printIndividualForHumans(EvolutionState state,
                                     int log,
                                     int verbosity)
Description copied from class: Individual
Should print the individual out in a pleasing way for humans, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitnessForHumans(state,log,verbosity);
Overrides:
printIndividualForHumans in class Individual

printIndividual

public void printIndividual(EvolutionState state,
                            int log,
                            int verbosity)
Description copied from class: Individual
Should print the individual in a way that can be read by computer, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitness(state,log,verbosity);
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.
Overrides:
printIndividual in class Individual

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.
Overrides:
equals in class Individual

getGenome

public java.lang.Object getGenome()
Description copied from class: VectorIndividual
Returns the gene array. If you know the type of the array, you can cast it and work on it directly. Otherwise, you can still manipulate it in general, because arrays (like all objects) respond to clone() and can be manipulated with arrayCopy without bothering with their type. This might be useful in creating special generalized crossover operators -- we apologize in advance for the fact that Java doesn't have a template system. :-( The default version returns null.
Overrides:
getGenome in class VectorIndividual

setGenome

public void setGenome(java.lang.Object gen)
Description copied from class: VectorIndividual
Sets the gene array. See getGenome(). The default version does nothing.
Overrides:
setGenome in class VectorIndividual
Following copied from class: ec.vector.VectorIndividual
See Also:
VectorIndividual.getGenome()

genomeLength

public long genomeLength()
Description copied from class: VectorIndividual
Returns the length of the gene array. By default, this method returns 0.
Overrides:
genomeLength in class VectorIndividual