Class FloatChromosome
java.lang.Object
net.bmahe.genetics4j.core.chromosomes.FloatChromosome
- All Implemented Interfaces:
Chromosome
A chromosome implementation that represents genetic information as an array of single-precision floating-point values.
FloatChromosome provides a memory-efficient alternative to DoubleChromosome for continuous optimization problems where single precision (32-bit) is sufficient. This chromosome type offers good performance for real-valued optimization while using approximately half the memory of double-precision alternatives.
This chromosome type is particularly suitable for:
- Large-scale optimization: Problems with thousands of parameters where memory efficiency matters
- Neural network evolution: Evolving weights when single precision is adequate
- Graphics and gaming: Position, rotation, and scaling parameters
- Signal processing: Audio and image processing parameter optimization
- Embedded systems: Resource-constrained environments with limited memory
- Real-time applications: Where performance is more critical than precision
Key characteristics:
- Memory efficient: 32-bit floating-point representation reduces memory usage
- Bounded values: All floats 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
Performance considerations:
- Memory usage: Approximately 50% less memory than DoubleChromosome
- Cache efficiency: Better cache utilization due to smaller data size
- Precision trade-off: ~7 decimal digits vs ~15 for double precision
- Range limitations: Smaller representable range than double precision
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
When to choose FloatChromosome vs DoubleChromosome:
- Use FloatChromosome: Large populations, memory constraints, adequate precision
- Use DoubleChromosome: High precision requirements, scientific computing
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFloatChromosome
(int _size, float _minValue, float _maxValue, float[] _values) Creates a new float chromosome with the specified parameters and values. -
Method Summary
Modifier and TypeMethodDescriptionboolean
float
getAllele
(int index) Returns the float value at the specified index.float
Returns the maximum allowed value for floats in this chromosome.float
Returns the minimum allowed value for floats in this chromosome.int
Returns the number of alleles (genetic units) in this chromosome.int
getSize()
Returns the number of float values in this chromosome.float[]
Returns a copy of the float values in this chromosome.int
hashCode()
toString()
-
Field Details
-
size
private final int size -
minValue
private final float minValue -
maxValue
private final float maxValue -
values
private final float[] values
-
-
Constructor Details
-
FloatChromosome
public FloatChromosome(int _size, float _minValue, float _maxValue, float[] _values) Creates a new float chromosome with the specified parameters and values.- Parameters:
_size
- the number of float values in this chromosome_minValue
- the minimum allowed value for any float in this chromosome_maxValue
- the maximum allowed value for any float in this chromosome_values
- the array of float 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 interfaceChromosome
- Returns:
- the number of alleles in this chromosome, always positive
-
getAllele
public float getAllele(int index) Returns the float value at the specified index.- Parameters:
index
- the index of the allele to retrieve (0-based)- Returns:
- the float 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 float values in this chromosome.- Returns:
- the chromosome size
-
getMinValue
public float getMinValue()Returns the minimum allowed value for floats in this chromosome.- Returns:
- the minimum value constraint
-
getMaxValue
public float getMaxValue()Returns the maximum allowed value for floats in this chromosome.- Returns:
- the maximum value constraint
-
getValues
public float[] getValues()Returns a copy of the float values in this chromosome.The returned array is a defensive copy; modifications to it will not affect this chromosome.
- Returns:
- a copy of the float values array
-
hashCode
public int hashCode() -
equals
-
toString
-