Class ImmutableNeatSelection<T extends Comparable<T>>
- All Implemented Interfaces:
SelectionPolicy
NeatSelection.
Use the builder to create immutable instances:
new NeatSelection.Builder().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImmutableNeatSelection.Builder<T extends Comparable<T>>Builds instances of typeNeatSelection.private final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ImmutableNeatSelection<T>.InitShimprivate final intprivate final floatprivate final BiPredicate<Individual<T>, Individual<T>> private final SelectionPolicyprivate static final byteprivate static final byteprivate static final byte -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateImmutableNeatSelection(float perSpeciesKeepRatio, int minSpeciesSize, BiPredicate<Individual<T>, Individual<T>> speciesPredicate, SelectionPolicy speciesSelection) private -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<T>>
NeatSelection<T> copyOf(NeatSelection<T> instance) Creates an immutable copy of aNeatSelectionvalue.booleanThis instance is equal to all instances ofImmutableNeatSelectionthat have equal attribute values.private booleanequalsByValue(ImmutableNeatSelection<?> another) inthashCode()Computes a hash code from attributes:perSpeciesKeepRatio,minSpeciesSize,speciesPredicate,speciesSelection.intReturns the minimum number of individuals required to maintain a species.floatReturns the proportion of each species to preserve for reproduction.Returns the predicate used to determine species membership.Returns the selection policy used within each species.toString()Prints the immutable valueNeatSelectionwith attribute values.private static <T extends Comparable<T>>
ImmutableNeatSelection<T> validate(ImmutableNeatSelection<T> instance) final ImmutableNeatSelection<T> withMinSpeciesSize(int value) Copy the current immutable object by setting a value for theminSpeciesSizeattribute.final ImmutableNeatSelection<T> withPerSpeciesKeepRatio(float value) Copy the current immutable object by setting a value for theperSpeciesKeepRatioattribute.final ImmutableNeatSelection<T> withSpeciesPredicate(BiPredicate<Individual<T>, Individual<T>> value) Copy the current immutable object by setting a value for thespeciesPredicateattribute.final ImmutableNeatSelection<T> Copy the current immutable object by setting a value for thespeciesSelectionattribute.
-
Field Details
-
perSpeciesKeepRatio
private final float perSpeciesKeepRatio -
minSpeciesSize
private final int minSpeciesSize -
speciesPredicate
private final BiPredicate<Individual<T extends Comparable<T>>,Individual<T extends Comparable<T>>> speciesPredicate -
speciesSelection
-
STAGE_INITIALIZING
private static final byte STAGE_INITIALIZING- See Also:
-
STAGE_UNINITIALIZED
private static final byte STAGE_UNINITIALIZED- See Also:
-
STAGE_INITIALIZED
private static final byte STAGE_INITIALIZED- See Also:
-
initShim
-
-
Constructor Details
-
ImmutableNeatSelection
-
ImmutableNeatSelection
private ImmutableNeatSelection(float perSpeciesKeepRatio, int minSpeciesSize, BiPredicate<Individual<T>, Individual<T>> speciesPredicate, SelectionPolicy speciesSelection)
-
-
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:
perSpeciesKeepRatioin classNeatSelection<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:
minSpeciesSizein classNeatSelection<T extends Comparable<T>>- Returns:
- minimum species size (must be positive)
-
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:
speciesPredicatein classNeatSelection<T extends Comparable<T>>- Returns:
- bi-predicate for determining species membership
-
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:
speciesSelectionin classNeatSelection<T extends Comparable<T>>- Returns:
- selection policy for within-species parent selection
-
withPerSpeciesKeepRatio
Copy the current immutable object by setting a value for theperSpeciesKeepRatioattribute. A value strict bits equality used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for perSpeciesKeepRatio- Returns:
- A modified copy or the
thisobject
-
withMinSpeciesSize
Copy the current immutable object by setting a value for theminSpeciesSizeattribute. A value equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for minSpeciesSize- Returns:
- A modified copy or the
thisobject
-
withSpeciesPredicate
public final ImmutableNeatSelection<T> withSpeciesPredicate(BiPredicate<Individual<T>, Individual<T>> value) Copy the current immutable object by setting a value for thespeciesPredicateattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for speciesPredicate- Returns:
- A modified copy or the
thisobject
-
withSpeciesSelection
Copy the current immutable object by setting a value for thespeciesSelectionattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for speciesSelection- Returns:
- A modified copy or the
thisobject
-
equals
This instance is equal to all instances ofImmutableNeatSelectionthat have equal attribute values. -
equalsByValue
-
hashCode
public int hashCode()Computes a hash code from attributes:perSpeciesKeepRatio,minSpeciesSize,speciesPredicate,speciesSelection. -
toString
Prints the immutable valueNeatSelectionwith attribute values. -
validate
private static <T extends Comparable<T>> ImmutableNeatSelection<T> validate(ImmutableNeatSelection<T> instance) -
copyOf
Creates an immutable copy of aNeatSelectionvalue. 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
-