Class DoubleChromosome

java.lang.Object
net.bmahe.genetics4j.core.chromosomes.DoubleChromosome
All Implemented Interfaces:
Chromosome

public class DoubleChromosome extends Object implements Chromosome
A chromosome implementation that represents genetic information as an array of double-precision floating-point values.

DoubleChromosome is ideal for continuous optimization problems where solutions can be encoded as real-valued vectors. This chromosome type provides high precision for numerical optimization tasks and is commonly used in function optimization, neural network weight evolution, and parameter tuning.

This chromosome type is particularly suitable for:

  • Continuous optimization: Function minimization/maximization with real-valued parameters
  • Neural network evolution: Evolving connection weights and biases
  • Engineering optimization: Design parameters with continuous constraints
  • Scientific computing: Model parameter estimation and calibration
  • Financial modeling: Portfolio optimization and risk parameter tuning
  • Machine learning: Hyperparameter optimization for continuous parameters

Key characteristics:

  • High precision: 64-bit floating-point representation for accurate computations
  • Bounded values: All doubles are constrained to [minValue, maxValue]
  • Fixed length: Chromosome size is determined at creation time
  • Immutable: Values cannot be changed after construction
  • IEEE 754 compliant: Standard floating-point arithmetic and comparisons

The chromosome maintains bounds information which is used by genetic operators such as:

  • Arithmetic crossover: Weighted averaging of parent values
  • Gaussian mutation: Adding normally distributed noise
  • Uniform mutation: Random replacement within bounds
  • Creep mutation: Small incremental changes

Special considerations for floating-point chromosomes:

  • Precision handling: Be aware of floating-point precision limits
  • Boundary conditions: Handle edge cases at min/max values
  • Convergence: May require epsilon-based convergence criteria
  • Scaling: Consider normalizing parameters for better performance
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final double
     
    private final double
     
    private final int
     
    private final double[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DoubleChromosome(int _size, double _minValue, double _maxValue, double[] _values)
    Creates a new double chromosome with the specified parameters and values.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    double
    getAllele(int index)
    Returns the double value at the specified index.
    double
    Returns the maximum allowed value for doubles in this chromosome.
    double
    Returns the minimum allowed value for doubles in this chromosome.
    int
    Returns the number of alleles (genetic units) in this chromosome.
    int
    Returns the number of double values in this chromosome.
    double[]
    Returns a copy of the double values in this chromosome.
    int
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • size

      private final int size
    • minValue

      private final double minValue
    • maxValue

      private final double maxValue
    • values

      private final double[] values
  • Constructor Details

    • DoubleChromosome

      public DoubleChromosome(int _size, double _minValue, double _maxValue, double[] _values)
      Creates a new double chromosome with the specified parameters and values.
      Parameters:
      _size - the number of double values in this chromosome
      _minValue - the minimum allowed value for any double in this chromosome
      _maxValue - the maximum allowed value for any double in this chromosome
      _values - the array of double values for this chromosome
      Throws:
      IllegalArgumentException - if size is not positive, if minValue > maxValue, if values array is null, or if the array length doesn't match the specified size
  • Method Details

    • getNumAlleles

      public int getNumAlleles()
      Description copied from interface: Chromosome
      Returns the number of alleles (genetic units) in this chromosome.

      The interpretation of an allele depends on the specific chromosome type:

      • For bit chromosomes: the number of bits
      • For numeric chromosomes: the number of numeric values
      • For tree chromosomes: the number of nodes in the tree
      Specified by:
      getNumAlleles in interface Chromosome
      Returns:
      the number of alleles in this chromosome, always positive
    • getAllele

      public double getAllele(int index)
      Returns the double value at the specified index.
      Parameters:
      index - the index of the allele to retrieve (0-based)
      Returns:
      the double value at the specified position
      Throws:
      IllegalArgumentException - if index is negative or greater than or equal to the chromosome size
    • getSize

      public int getSize()
      Returns the number of double values in this chromosome.
      Returns:
      the chromosome size
    • getMinValue

      public double getMinValue()
      Returns the minimum allowed value for doubles in this chromosome.
      Returns:
      the minimum value constraint
    • getMaxValue

      public double getMaxValue()
      Returns the maximum allowed value for doubles in this chromosome.
      Returns:
      the maximum value constraint
    • getValues

      public double[] getValues()
      Returns a copy of the double values in this chromosome.

      The returned array is a defensive copy; modifications to it will not affect this chromosome.

      Returns:
      a copy of the double values array
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object