Class Species<T extends Comparable<T>>
- Type Parameters:
T
- the fitness value type (typically Double)
A Species groups together genetically similar individuals in the population, enabling fitness sharing and diversity preservation in NEAT evolution. Species are formed based on genetic compatibility distance, allowing individuals with similar network topologies to compete within their own niche rather than with the entire population.
Key characteristics:
- Genetic similarity: Members share similar network topologies and connection patterns
- Fitness sharing: Members compete primarily within their species for reproductive opportunities
- Diversity preservation: Protects innovative topologies from being eliminated by established forms
- Dynamic membership: Species composition changes as individuals evolve and compatibility shifts
NEAT speciation process:
- Compatibility measurement: Calculate genetic distance between individuals
- Species assignment: Assign individuals to species based on distance thresholds
- Representative selection: Choose species representatives for compatibility testing
- Fitness sharing: Adjust individual fitness based on species membership size
- Reproduction allocation: Allocate offspring based on species average fitness
Species lifecycle management:
- Formation: New species created when individuals exceed compatibility threshold
- Growth: Species gain members as similar individuals are assigned
- Stagnation: Species may stagnate if they fail to improve over generations
- Extinction: Species die out when they have no members or persistently poor performance
Common usage patterns:
// Create new species with founding ancestors
List<Individual<Double>> founders = List.of(individual1, individual2);
Species<Double> species = new Species<>(42, founders);
// Add members during population assignment
species.addMember(similarIndividual1);
species.addMember(similarIndividual2);
species.addAllMembers(batchOfSimilarIndividuals);
// Access species information
int speciesId = species.getId();
int memberCount = species.getNumMembers();
List<Individual<Double>> allMembers = species.getMembers();
// Species-based fitness sharing
for (Individual<Double> member : species.getMembers()) {
double sharedFitness = member.fitness() / species.getNumMembers();
// Use shared fitness for selection
}
Ancestor tracking:
- Species representatives: Ancestors serve as compatibility test references
- Historical continuity: Maintains connection to previous generations
- Stability: Prevents species boundaries from shifting too rapidly
- Representative selection: Best performers may become ancestors for next generation
Fitness sharing mechanism:
- Within-species competition: Members primarily compete with each other
- Diversity protection: Prevents single topology from dominating population
- Innovation preservation: Allows new topologies time to optimize
- Niche exploitation: Different species can specialize for different aspects of the problem
Integration with NEAT selection:
- Speciation: Used by NeatSelectionPolicyHandler for population organization
- Compatibility testing: Ancestors used as reference points for species assignment
- Reproduction allocation: Species size influences offspring distribution
- Population dynamics: Species creation, growth, and extinction drive population diversity
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<Individual<T>> private final int
private final List
<Individual<T>> -
Constructor Summary
ConstructorsConstructorDescriptionSpecies
(int _id, List<Individual<T>> _ancestors) Constructs a new species with the specified ID and founding ancestors. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAllMembers
(Collection<Individual<T>> individuals) Adds multiple individuals as members of this species.void
addAncestor
(Individual<T> individual) Adds an individual as an ancestor of this species.void
addMember
(Individual<T> individual) Adds an individual as a member of this species.boolean
List
<Individual<T>> Returns the list of ancestors for this species.int
getId()
Returns the unique identifier for this species.List
<Individual<T>> Returns the list of current members in this species.int
Returns the number of ancestors in this species.int
Returns the number of current members in this species.int
hashCode()
toString()
-
Field Details
-
id
private final int id -
ancestors
-
members
-
-
Constructor Details
-
Species
Constructs a new species with the specified ID and founding ancestors.The ancestors serve as reference points for compatibility testing and represent the genetic heritage of the species. New individuals are tested against these ancestors to determine species membership.
- Parameters:
_id
- unique identifier for this species_ancestors
- founding individuals that define the species genetic signature- Throws:
IllegalArgumentException
- if ancestors is null
-
-
Method Details
-
addAncestor
Adds an individual as an ancestor of this species.Ancestors serve as reference points for compatibility testing in subsequent generations. Typically, the best performers from a species may be promoted to ancestors to maintain species continuity.
- Parameters:
individual
- the individual to add as an ancestor- Throws:
IllegalArgumentException
- if individual is null
-
addMember
Adds an individual as a member of this species.Members are the current generation individuals that have been assigned to this species based on genetic compatibility. They participate in fitness sharing and species-based selection.
- Parameters:
individual
- the individual to add as a member- Throws:
IllegalArgumentException
- if individual is null
-
addAllMembers
Adds multiple individuals as members of this species.This is a convenience method for bulk assignment of compatible individuals to the species. All individuals in the collection will participate in fitness sharing within this species.
- Parameters:
individuals
- collection of individuals to add as members- Throws:
IllegalArgumentException
- if individuals is null
-
getNumAncestors
public int getNumAncestors()Returns the number of ancestors in this species.Ancestors serve as reference points for compatibility testing and represent the species genetic heritage from previous generations.
- Returns:
- the number of ancestors
-
getNumMembers
public int getNumMembers()Returns the number of current members in this species.The member count is used for fitness sharing calculations and reproduction allocation. Larger species will have their members' fitness values adjusted downward to prevent single species from dominating the population.
- Returns:
- the number of current members
-
getId
public int getId()Returns the unique identifier for this species.Species IDs are typically assigned by a SpeciesIdGenerator and remain constant throughout the species lifecycle.
- Returns:
- the species unique identifier
-
getAncestors
Returns the list of ancestors for this species.Ancestors are reference individuals used for compatibility testing when assigning new individuals to species. The returned list is mutable and modifications will affect the species behavior.
- Returns:
- mutable list of ancestor individuals
-
getMembers
Returns the list of current members in this species.Members are the current generation individuals that participate in fitness sharing and species-based selection. The returned list is mutable and modifications will affect species membership.
- Returns:
- mutable list of member individuals
-
hashCode
public int hashCode() -
equals
-
toString
-