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 class
ImmutableNeatSelection.Builder<T extends Comparable<T>>
Builds instances of typeImmutableNeatSelection
.private final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ImmutableNeatSelection<T>.InitShim
private final int
private final float
private final BiPredicate
<Individual<T>, Individual<T>> private final SelectionPolicy
private static final byte
private static final byte
private static final byte
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ImmutableNeatSelection
(float perSpeciesKeepRatio, int minSpeciesSize, BiPredicate<Individual<T>, Individual<T>> speciesPredicate, SelectionPolicy speciesSelection) private
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<T>>
ImmutableNeatSelection<T> copyOf
(NeatSelection<T> instance) Creates an immutable copy of aNeatSelection
value.boolean
This instance is equal to all instances ofImmutableNeatSelection
that have equal attribute values.private boolean
equalTo
(int synthetic, ImmutableNeatSelection<?> another) int
hashCode()
Computes a hash code from attributes:perSpeciesKeepRatio
,minSpeciesSize
,speciesPredicate
,speciesSelection
.int
Returns the minimum number of individuals required to maintain a species.float
Returns 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 valueNeatSelection
with 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 theminSpeciesSize
attribute.final ImmutableNeatSelection
<T> withPerSpeciesKeepRatio
(float value) Copy the current immutable object by setting a value for theperSpeciesKeepRatio
attribute.final ImmutableNeatSelection
<T> withSpeciesPredicate
(BiPredicate<Individual<T>, Individual<T>> value) Copy the current immutable object by setting a value for thespeciesPredicate
attribute.final ImmutableNeatSelection
<T> Copy the current immutable object by setting a value for thespeciesSelection
attribute.
-
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:
perSpeciesKeepRatio
in 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:
minSpeciesSize
in 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:
speciesPredicate
in 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:
speciesSelection
in classNeatSelection<T extends Comparable<T>>
- Returns:
- selection policy for within-species parent selection
-
withPerSpeciesKeepRatio
Copy the current immutable object by setting a value for theperSpeciesKeepRatio
attribute. 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 of the
this
object
-
withMinSpeciesSize
Copy the current immutable object by setting a value for theminSpeciesSize
attribute. 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 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 thespeciesPredicate
attribute. 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 of the
this
object
-
withSpeciesSelection
Copy the current immutable object by setting a value for thespeciesSelection
attribute. 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 of the
this
object
-
equals
This instance is equal to all instances ofImmutableNeatSelection
that have equal attribute values. -
equalTo
-
hashCode
public int hashCode()Computes a hash code from attributes:perSpeciesKeepRatio
,minSpeciesSize
,speciesPredicate
,speciesSelection
. -
toString
Prints the immutable valueNeatSelection
with attribute values. -
validate
private static <T extends Comparable<T>> ImmutableNeatSelection<T> validate(ImmutableNeatSelection<T> instance) -
copyOf
Creates an immutable copy of aNeatSelection
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
-