RealChromosome (JEvolution)
Date: 2013-03-21

evSOLve.JEvolution.chromosomes

## Class RealChromosome

- java.lang.Object
- - evSOLve.JEvolution.chromosomes.Chromosome
  - - evSOLve.JEvolution.chromosomes.RealChromosome

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

      public class RealChromosome
      extends Chromosome

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `EACH` Object parameters are mutated with a strategy parameter (sigma) for each object parameter.
    `protected double` | `high` The largest real number for initialization.
    `protected double` | `low` The lowest real number for initialization.
    `static int` | `NONE` Object parameters are mutated with a constant mutation rate.
    `protected java.util.List<java.lang.Double>` | `objectBases` The genetic information carrier for the object parameters.
    `static int` | `SINGLE` Object parameters are mutated with a single strategy parameter (sigma).
    `protected int` | `strategy` The type of self-adaptation strategy.
    `protected java.util.List<java.lang.Double>` | `strategyBases` The genetic information carrier for the strategy parameters.
    `protected double` | `tau` The second parameter for mutation of strategy parameters.
    `protected double` | `tauPrime` The first parameter for mutation of strategy parameters.

    - ### Fields inherited from class evSOLve.JEvolution.chromosomes.Chromosome

      `BIASED, crossoverPoints, crossoverRate, LAPLACE, length, mutationRate, soupType`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RealChromosome()` Creates a default chromosome.
    `RealChromosome(Element c)` Creates a RealChromosome via XML.
    `RealChromosome(int length)` Constructs a chromosome of given length and default values for 'low' (0.0) and 'high' (1.0), and 'mutationRate' (0.05).

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Object` | `clone()` A proper clone, cloning the bases deeply by creating new objects.
    `void` | `doCrossover(Chromosome father)` Discrete recombination of two random parents.
    `void` | `doMutation()` Mutate by adding normal noise with constant, single, or specific standard deviation (strategy parameters).
    `boolean` | `equals(java.lang.Object o)` An efficient check for equality.
    `void` | `fromString(java.lang.String b)` Create bases from String.
    `java.lang.Object` | `getBases()` Return the genetic code for object parameters.
    `double` | `getHigh()` Gives upper bound of initial real values.
    `double` | `getLow()` Gives lower bound of initial real values.
    `int` | `getStrategy()` Gives strategy type.
    `java.lang.Object` | `getStrategyBases()` Return the genetic code for strategy parameters.
    `int` | `hashCode()` An efficient hash code.
    `void` | `mixSoup()` Initial creation of the alleles.
    `void` | `setHigh(double high)` Changes upper bound of initial real values.
    `void` | `setLow(double low)` Changes lower bound of initial real values.
    `void` | `setStrategy(int strategy)` Changes number of strategy parameters.
    `java.lang.String` | `toString()` Convert chromosome (object parameters) to string.
    `Element` | `toXml(Element parent)` Saves the current state to XML.

    - ### Methods inherited from class evSOLve.JEvolution.chromosomes.Chromosome

      `create, getCrossoverPoints, getCrossoverRate, getLength, getMutationRate, getSoupType, setCrossoverPoints, setCrossoverRate, setLength, setMutationRate, setSoupType`

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

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### NONE

          public static final int NONE

      Object parameters are mutated with a constant mutation rate.
      See Also:
        Constant Field Values

    - #### SINGLE

          public static final int SINGLE

      Object parameters are mutated with a single strategy parameter (sigma).
      See Also:
        Constant Field Values

    - #### EACH

          public static final int EACH

      Object parameters are mutated with a strategy parameter (sigma) for each object parameter.
      See Also:
        Constant Field Values

    - #### objectBases

          protected java.util.List<java.lang.Double> objectBases

      The genetic information carrier for the object parameters.

    - #### strategy

          protected int strategy

      The type of self-adaptation strategy.

    - #### strategyBases

          protected java.util.List<java.lang.Double> strategyBases

      The genetic information carrier for the strategy parameters.

    - #### low

          protected double low

      The lowest real number for initialization.

    - #### high

          protected double high

      The largest real number for initialization.

    - #### tauPrime

          protected double tauPrime

      The first parameter for mutation of strategy parameters.

    - #### tau

          protected double tau

      The second parameter for mutation of strategy parameters.

  - ### Constructor Detail

    - #### RealChromosome

          public RealChromosome()

      Creates a default chromosome.

    - #### RealChromosome

          public RealChromosome(int length)

      Constructs a chromosome of given length and default values for 'low' (0.0) and 'high' (1.0), and 'mutationRate' (0.05).
      Parameters:
        `length` - the number of bases

    - #### RealChromosome

          public RealChromosome(Element c)

      Creates a RealChromosome via XML.
      Parameters:
        `c` - an XML Chromosome element

  - ### Method Detail

    - #### clone

          public java.lang.Object clone()

      A proper clone, cloning the bases deeply by creating new objects.
      Overrides:
        `clone` in class `Chromosome`
      Returns:
        Object the cloned RealChromosome

    - #### equals

          public boolean equals(java.lang.Object o)

      An efficient check for equality. It only checks the bases, first, if the number of bases is equal, and then if the base values (object and strategy parameters) are the same.
      Specified by:
        `equals` in class `Chromosome`
      Returns:
        equal The equality of the passed object with this object.

    - #### hashCode

          public int hashCode()

      An efficient hash code. Uses Vector.hashCode(). It just uses the object bases for hashing, however, use of the fitness repository does not seem to make any sense, as no single real chromosome will be the same as any other.
      Specified by:
        `hashCode` in class `Chromosome`
      Returns:
        hashCode A more or less correct hash code.

    - #### doMutation

          public void doMutation()

      Mutate by adding normal noise with constant, single, or specific standard deviation (strategy parameters). First, the strategy parameter(s) are mutated as [sigma_i,new = sigma_i,old * exp(tau'N(0, 1) + tau N_i(0, 1))] (where N(0, 1) is the same for all i). Then the object parameters are mutated as [o_i,new = o_i,old + N(0, sigma_i,new)]. [tau = 1/sqrt(2 * sqrt(n))], [tau' = 1/sqrt(2n)], where n is the number of object parameters. If strategy is NONE, the length of the constant interval [low, high] scaled by the mutation rate is used as standard deviation.
      Specified by:
        `doMutation` in class `Chromosome`

    - #### doCrossover

          public void doCrossover(Chromosome father)

      Discrete recombination of two random parents. Obeying the crossover rate object parameters are exchanged with p = 0.5. In GA terms this is Uniform Crossover.
      Specified by:
        `doCrossover` in class `Chromosome`
      Parameters:
        `father` - A parent Chromosome.

    - #### mixSoup

          public void mixSoup()

      Initial creation of the alleles. Doubles for object parameters are randomly drawn from the user defined range with uniform distribution (eventually biased). The random values for the strategy parameter(s) are derived using 'mutationRate'. The mutation rate is the range of initial sigma value(s). The range is calculated as a percentage (=mutation rate) of the range high - low. The strategy parameters are then uniformly sampled from this initial range of sigma. If strategy == NONE, the mutation rate is never adapted.
      Specified by:
        `mixSoup` in class `Chromosome`

    - #### getLow

          public double getLow()

      Gives lower bound of initial real values.
      Returns:
        low lower bound

    - #### setLow

          public void setLow(double low)

      Changes lower bound of initial real values.
      Parameters:
        `low` - lower bound

    - #### getHigh

          public double getHigh()

      Gives upper bound of initial real values.
      Returns:
        high upper bound

    - #### setHigh

          public void setHigh(double high)

      Changes upper bound of initial real values.
      Parameters:
        `high` - upper bound

    - #### setStrategy

          public void setStrategy(int strategy)

      Changes number of strategy parameters.
      Parameters:
        `strategy` - NONE, SINGLE, or EACH object parameter is controlled by a strategy base

    - #### getStrategy

          public int getStrategy()

      Gives strategy type.
      Returns:
        strategy type of self-adaptation

    - #### getBases

          public java.lang.Object getBases()

      Return the genetic code for object parameters.
      Specified by:
        `getBases` in class `Chromosome`
      Returns:
        bases object parameters

    - #### getStrategyBases

          public java.lang.Object getStrategyBases()

      Return the genetic code for strategy parameters.
      Returns:
        bases strategy parameters

    - #### toString

          public java.lang.String toString()

      Convert chromosome (object parameters) to string. The first base (the leftmost) has index 0.
      Specified by:
        `toString` in class `Chromosome`

    - #### fromString

          public void fromString(java.lang.String b)

      Create bases from String. The syntax of the string must be like this: "1.3|2.4|3.5|4.34|", where the numbers are just examples, but the '|' character must be exactly at the given spots. Note that we only deal with object bases, the strategy bases are initialized using random numbers.
      Specified by:
        `fromString` in class `Chromosome`
      Parameters:
        `b` - a String describing the object bases

    - #### toXml

          public Element toXml(Element parent)

      Saves the current state to XML.
      Overrides:
        `toXml` in class `Chromosome`
      Parameters:
        `parent` - the JDOM parent element
      Returns:
        the Chromosome element