Class ImmutableNeatSelection<T extends Comparable<T>>

java.lang.Object
net.bmahe.genetics4j.neat.spec.selection.NeatSelection<T>
net.bmahe.genetics4j.neat.spec.selection.ImmutableNeatSelection<T>
All Implemented Interfaces:
SelectionPolicy

@Generated("org.immutables.processor.ProxyProcessor") public final class ImmutableNeatSelection<T extends Comparable<T>> extends NeatSelection<T>
Immutable implementation of NeatSelection.

Use the builder to create immutable instances: new NeatSelection.Builder().

  • Field Details

  • Constructor Details

  • Method Details

    • perSpeciesKeepRatio

      public float perSpeciesKeepRatio()
      Returns the proportion of each species to preserve for reproduction.

      This ratio determines what fraction of each species will be retained after fitness-based culling. Higher values preserve more diversity within species but may slow convergence, while lower values increase selection pressure but may lose beneficial genetic variations.

      Typical values:

      • 0.9 (default): Preserve top 90% of each species
      • 0.8-0.95: Balanced diversity preservation
      • < 0.8: Aggressive selection pressure
      • > 0.95: Minimal selection pressure, maximum diversity
      Overrides:
      perSpeciesKeepRatio in class NeatSelection<T extends Comparable<T>>
      Returns:
      keep ratio between 0.0 and 1.0 (exclusive of 0.0, inclusive of 1.0)
    • minSpeciesSize

      public int minSpeciesSize()
      Returns the minimum number of individuals required to maintain a species.

      Species with fewer members than this threshold will be eliminated to prevent resource waste on non-viable populations. This helps focus evolutionary resources on species with sufficient genetic diversity to explore their local fitness landscape effectively.

      Typical values:

      • 5 (default): Balanced viability threshold
      • 3-10: Reasonable range for most problems
      • < 3: Very permissive, allows small species to survive
      • > 10: Strict threshold, eliminates marginal species
      Overrides:
      minSpeciesSize in class NeatSelection<T extends Comparable<T>>
      Returns:
      minimum species size (must be positive)
    • speciesPredicate

      public BiPredicate<Individual<T>,Individual<T>> speciesPredicate()
      Returns the predicate used to determine species membership.

      This bi-predicate takes two individuals and returns true if they should belong to the same species based on their genetic compatibility. Typically implemented using NEAT compatibility distance with a threshold value.

      Common implementations:

      • Compatibility distance: Based on matching, disjoint, excess genes and weight differences
      • Topological similarity: Based on network structure similarity
      • Behavioral similarity: Based on network output patterns
      • Custom metrics: Domain-specific similarity measures
      Specified by:
      speciesPredicate in class NeatSelection<T extends Comparable<T>>
      Returns:
      bi-predicate for determining species membership
    • speciesSelection

      public SelectionPolicy speciesSelection()
      Returns the selection policy used within each species.

      After individuals are organized into species, this policy determines how parents are selected within each species for reproduction. Common choices include tournament selection, proportional selection, or rank-based selection.

      Selection policy considerations:

      • Tournament selection: Good balance of selection pressure and diversity
      • Proportional selection: Fitness-proportionate selection within species
      • Rank selection: Rank-based selection to avoid fitness scaling issues
      • Elite selection: Always select best individuals within species
      Specified by:
      speciesSelection in class NeatSelection<T extends Comparable<T>>
      Returns:
      selection policy for within-species parent selection
    • withPerSpeciesKeepRatio

      public final ImmutableNeatSelection<T> withPerSpeciesKeepRatio(float value)
      Copy the current immutable object by setting a value for the perSpeciesKeepRatio attribute. A value strict bits equality used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for perSpeciesKeepRatio
      Returns:
      A modified copy of the this object
    • withMinSpeciesSize

      public final ImmutableNeatSelection<T> withMinSpeciesSize(int value)
      Copy the current immutable object by setting a value for the minSpeciesSize attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for minSpeciesSize
      Returns:
      A modified copy of the this object
    • withSpeciesPredicate

      public final ImmutableNeatSelection<T> withSpeciesPredicate(BiPredicate<Individual<T>,Individual<T>> value)
      Copy the current immutable object by setting a value for the speciesPredicate attribute. A shallow reference equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for speciesPredicate
      Returns:
      A modified copy of the this object
    • withSpeciesSelection

      public final ImmutableNeatSelection<T> withSpeciesSelection(SelectionPolicy value)
      Copy the current immutable object by setting a value for the speciesSelection attribute. A shallow reference equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for speciesSelection
      Returns:
      A modified copy of the this object
    • equals

      public boolean equals(Object another)
      This instance is equal to all instances of ImmutableNeatSelection that have equal attribute values.
      Overrides:
      equals in class Object
      Returns:
      true if this is equal to another instance
    • equalTo

      private boolean equalTo(int synthetic, ImmutableNeatSelection<?> another)
    • hashCode

      public int hashCode()
      Computes a hash code from attributes: perSpeciesKeepRatio, minSpeciesSize, speciesPredicate, speciesSelection.
      Overrides:
      hashCode in class Object
      Returns:
      hashCode value
    • toString

      public String toString()
      Prints the immutable value NeatSelection with attribute values.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the value
    • validate

      private static <T extends Comparable<T>> ImmutableNeatSelection<T> validate(ImmutableNeatSelection<T> instance)
    • copyOf

      public static <T extends Comparable<T>> ImmutableNeatSelection<T> copyOf(NeatSelection<T> instance)
      Creates an immutable copy of a NeatSelection value. Uses accessors to get values to initialize the new immutable instance. If an instance is already immutable, it is returned as is.
      Type Parameters:
      T - generic parameter T
      Parameters:
      instance - The instance to copy
      Returns:
      A copied immutable NeatSelection instance