Class Particle
- All Implemented Interfaces:
Prototype,Setup,Serializable,Cloneable,Comparable<Individual>
Particle updates its location in two steps. First, it gathers current neighborhood and personal best statistics via the update(...) method. Then it updates the particle's velocity and location (genome) according to these statistics in the tweak(...) method. Notice that neither of these methods is the defaultMutate(...) method used in DoubleVectorIndividual: this means that in *theory* you could rig up Particles to also be mutated if you thought that was a good reason.
Many of the parameters passed into the tweak(...) method are based on weights determined by the PSOBreeder.
- See Also:
-
Field Summary
FieldsFields inherited from class ec.vector.DoubleVectorIndividual
genome, MAXIMUM_INTEGER_IN_DOUBLE, P_DOUBLEVECTORINDIVIDUALFields inherited from class ec.Individual
evaluated, EVALUATED_PREAMBLE, fitness, P_INDIVIDUAL, species -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.booleanReturns true if I am genetically "equal" to ind.inthashCode()Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.voidJoins the n pieces and sets the genome to their concatenation.voidprintIndividual(EvolutionState state, int log) Should print the individual in a way that can be read by computer, including its fitness, with a verbosity of Output.V_NO_GENERAL.voidprintIndividual(EvolutionState state, PrintWriter writer) Should print the individual in a way that can be read by computer, including its fitness.voidreadIndividual(EvolutionState state, DataInput dataInput) Reads the binary form of an individual from a DataInput, erasing the previous information stored in this Individual.voidreadIndividual(EvolutionState state, LineNumberReader reader) Reads in the individual from a form printed by printIndividual(), erasing the previous information stored in this Individual.voidreset(EvolutionState state, int thread) Initializes the individual by randomly choosing doubles uniformly from mingene to maxgene.voidSets the gene array.voidsetGenomeLength(int len) Sets the genome length.voidsetup(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.voidtweak(EvolutionState state, double[] globalBest, double velocityCoeff, double personalCoeff, double informantCoeff, double globalCoeff, int thread) voidupdate(EvolutionState state, int subpop, int myindex, int thread) voidwriteIndividual(EvolutionState state, DataOutput dataOutput) Writes the binary form of an individual out to a DataOutput.Methods inherited from class ec.vector.DoubleVectorIndividual
clamp, defaultBase, defaultCrossover, defaultMutate, distanceTo, genomeLength, genotypeToString, genotypeToStringForHumans, getGenome, isInRange, parseGenotype, polynomialMutate, readGenotype, simulatedBinaryCrossover, split, writeGenotypeMethods inherited from class ec.vector.VectorIndividual
cloneGenes, reset, sizeMethods inherited from class ec.Individual
compareTo, merge, printIndividual, printIndividualForHumans, printIndividualForHumans, toString
-
Field Details
-
AUXILLARY_PREAMBLE
- See Also:
-
velocity
public double[] velocity -
neighborhood
public int[] neighborhood -
neighborhoodBestGenome
public double[] neighborhoodBestGenome -
neighborhoodBestFitness
-
personalBestGenome
public double[] personalBestGenome -
personalBestFitness
-
-
Constructor Details
-
Particle
public Particle()
-
-
Method Details
-
hashCode
public int hashCode()Description copied from class:IndividualReturns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.- Overrides:
hashCodein classDoubleVectorIndividual
-
equals
Description copied from class:IndividualReturns 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:
equalsin classDoubleVectorIndividual
-
setup
Description copied from class:IndividualThis 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. -
clone
Description copied from interface:PrototypeCreates 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 Populations, or Subpopulation.
- 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:
clonein interfacePrototype- Overrides:
clonein classDoubleVectorIndividual
-
update
-
tweak
public void tweak(EvolutionState state, double[] globalBest, double velocityCoeff, double personalCoeff, double informantCoeff, double globalCoeff, int thread) -
reset
Description copied from class:DoubleVectorIndividualInitializes the individual by randomly choosing doubles uniformly from mingene to maxgene.- Overrides:
resetin classDoubleVectorIndividual
-
setGenomeLength
public void setGenomeLength(int len) Description copied from class:VectorIndividualSets the genome length. If the length is longer, then it is filled with a default value (likely 0 or false). This may or may not be a valid value -- you will need to set appropriate values here. The default implementation does nothing; but all subclasses in ECJ implement a subset of this.- Overrides:
setGenomeLengthin classDoubleVectorIndividual
-
setGenome
Description copied from class:VectorIndividualSets the gene array. See getGenome(). The default version does nothing.- Overrides:
setGenomein classDoubleVectorIndividual
-
join
Description copied from class:DoubleVectorIndividualJoins the n pieces and sets the genome to their concatenation.- Overrides:
joinin classDoubleVectorIndividual
-
printIndividual
Description copied from class:IndividualShould print the individual in a way that can be read by computer, including its fitness, with a verbosity of Output.V_NO_GENERAL.- Overrides:
printIndividualin classIndividual
-
printIndividual
Description copied from class:IndividualShould 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:
printIndividualin classIndividual
-
readIndividual
Description copied from class:IndividualReads in the individual from a form printed by printIndividual(), erasing the previous information stored in this Individual. If you are trying to create an Individual from information read in from a stream or DataInput, see the various newIndividual() methods in Species. The default form of this method simply reads in evaluation information, then fitness information, and then calls parseGenotype() (which you should implement). The Species is not changed or attached, so you may need to do that elsewhere. Feel free to override this method to produce more sophisticated behavior, though it is rare to need to -- instead you could just override parseGenotype().- Overrides:
readIndividualin classIndividual- Throws:
IOException
-
writeIndividual
Description copied from class:IndividualWrites 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 Species will be reattached later, and you should not write it. The default version of this method writes the evaluated and fitness information, then calls writeGenotype() to write the genotype information. Feel free to override this method to produce more sophisticated behavior, though it is rare to need to -- instead you could just override writeGenotype().- Overrides:
writeIndividualin classIndividual- Throws:
IOException
-
readIndividual
Description copied from class:IndividualReads the binary form of an individual from a DataInput, erasing the previous information stored in this Individual. This is not for serialization: the object should only read in the data written out via printIndividual(state,dataInput). If you are trying to create an Individual from information read in from a stream or DataInput, see the various newIndividual() methods in Species. The default form of this method simply reads in evaluation information, then fitness information, and then calls readGenotype() (which you will need to override -- its default form simply throws an error). The Species is not changed or attached, so you may need to do that elsewhere. Feel free to override this method to produce more sophisticated behavior, though it is rare to need to -- instead you could just override readGenotype().- Overrides:
readIndividualin classIndividual- Throws:
IOException
-