Operators¶
deap_er.operators
¶
PolicyActionGuard(max_promotes_per_gen=1, max_tune_gen=5, min_exam_size=1, promote_cooldown=0, n_evals=None, nevals_used=0, generation=0, promotes_this_gen=0, last_promote_gen=None)
dataclass
¶
Hard caps for :func:~deap_er.algorithms.apply_policy_action.
Tracks per-generation promote counts, promote cooldown,
inner tune generation limits, minimum exam size, and an optional
evaluation budget. Call :meth:begin_generation at the start of
each outer generation so promote limits reset.
Attributes:
| Name | Type | Description |
|---|---|---|
max_promotes_per_gen |
int
|
Maximum |
max_tune_gen |
int
|
Maximum inner |
min_exam_size |
int
|
Minimum catalog size required for
|
promote_cooldown |
int
|
Generations that must pass after a promote before another promote is allowed. |
n_evals |
int | None
|
Optional evaluation budget. When set, actions whose estimated cost would exceed the remaining budget are rejected. |
nevals_used |
int
|
Evaluations already charged to this guard. |
generation |
int
|
Current outer generation index. |
promotes_this_gen |
int
|
Promotes applied in the current generation. |
last_promote_gen |
int | None
|
Generation index of the last promote, or
|
__post_init__()
¶
Reject invalid cap configuration at construction.
Source code in deap_er/private/operators/policy_action_guard.py
begin_generation(generation=None)
¶
Reset per-generation counters and optionally bump generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generation
|
int | None
|
When given, replaces :attr: |
None
|
Source code in deap_er/private/operators/policy_action_guard.py
allows(action, /, **kwargs)
¶
Return whether action may run under the current caps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Policy action token. |
required |
**kwargs
|
Any
|
Arguments that would be forwarded to
:func: |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in deap_er/private/operators/policy_action_guard.py
note_applied(action, /, *, evals=0)
¶
Record a successfully applied action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Policy action token that ran. |
required |
evals
|
int
|
Evaluations to charge against :attr: |
0
|
Source code in deap_er/private/operators/policy_action_guard.py
SelAGE2WithMemory()
¶
AGE-MOEA-II selection that remembers normalization anchors.
Instances can be registered into a Toolbox.
See the class docstring.
Source code in deap_er/private/operators/sel_age_moea_2.py
__call__(individuals, sel_count)
¶
Select individuals for the next generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_age_moea_2.py
SelMOEADWithMemory(weights, *, scalarization='tchebycheff', theta=5.0)
¶
MOEA/D selection that remembers the ideal point across generations.
Instances can be registered into a Toolbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
ndarray
|
Decomposition weight vectors. |
required |
scalarization
|
ScalarizationName | ScalarizationFn
|
|
'tchebycheff'
|
theta
|
float
|
PBI penalty parameter. |
5.0
|
See the class docstring.
Source code in deap_er/private/operators/sel_moead.py
__call__(individuals, sel_count)
¶
Select individuals for the next generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_moead.py
SelNSGA3WithMemory(ref_points)
¶
NSGA-III selection that remembers ideal, nadir, and extreme points.
Instances can be registered into a Toolbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref_points
|
ndarray
|
Reference points for selection. |
required |
See the class docstring.
Source code in deap_er/private/operators/sel_nsga_3.py
__call__(individuals, sel_count)
¶
Select individuals for the next generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_nsga_3.py
batch_case_matrix(matrix, subset, fit_weights, batch_size, reduction)
¶
Collapse shuffled case batches into one column per batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
|
required |
subset
|
list[int]
|
Case indices eligible for batching. |
required |
fit_weights
|
tuple[float, ...]
|
Per-case maximize/minimize signs from fitness. |
required |
batch_size
|
int
|
Maximum cases per batch. |
required |
reduction
|
CaseReduction
|
Maps a |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Reduced matrix with shape |
tuple[float, ...]
|
the weight copied from the first case in each batch. |
Source code in deap_er/private/operators/case_batch_reduce.py
partition_case_batches(subset, batch_size)
¶
Shuffle subset and split it into consecutive batches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subset
|
Sequence[int]
|
Fitness-case indices to batch. |
required |
batch_size
|
int
|
Maximum cases per batch. Must be at least |
required |
Returns:
| Type | Description |
|---|---|
list[list[int]]
|
Batches in shuffled order. The last batch may be shorter. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/case_batch_reduce.py
reduce_case_mean(block)
¶
Mean of case columns along axis 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
ndarray
|
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
One scalar per individual. |
Source code in deap_er/private/operators/case_batch_reduce.py
reduce_case_mse(block)
¶
Mean squared case values along axis 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block
|
ndarray
|
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
One scalar per individual. |
Source code in deap_er/private/operators/case_batch_reduce.py
guard_case_exams(exams, elites, *, matrix=None, trust_matrix=False, solved=None, held_out=None, min_cases=1, mode='unsolved', informed=True)
¶
Repair empty exams and all-solved collapse in place.
An empty exam is replaced by last_good, then held_out, then
an informed resample of min_cases when informed is true. A
collapsed exam (difficulty 0 under mode) unions
held_out and, if still collapsed and informed, bumps the
subset size through sample_informed_cases. Chronological splits
stay on the caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exams
|
ExamLike
|
Pool or sequence of exams to repair. |
required |
elites
|
list[Individual]
|
Evaluated individuals that supply the case pack. |
required |
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
solved
|
CaseSolved | None
|
Optional solve predicate. See :func: |
None
|
held_out
|
CaseExam | None
|
Caller-marked exam injected on collapse. A pool's
|
None
|
min_cases
|
int
|
Minimum catalog size after a repair. Combined with
a pool's |
1
|
mode
|
DifficultyMode
|
Difficulty used to detect collapse. |
'unsolved'
|
informed
|
bool
|
When |
True
|
Returns:
| Type | Description |
|---|---|
list[CaseExam]
|
The repaired exam list (the pool's live list when a pool is given). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/case_exam_guard.py
next_lexicase_cases(exams, elites, *, matrix=None, trust_matrix=False, solved=None, case_count=None, informed=True, mut_prob=0.2, mode='unsolved', held_out=None, min_cases=1, length=None)
¶
Vary exams and return the next sel_lexicase(..., cases=) subset.
Scores exams on elites, mutates ranges or mask runs, then guards
empty and collapsed exams. The mutated or guarded winner is the
cases= list. informed only enables
sample_informed_cases inside that guard — it does not overwrite
a healthy winner. The default path and informed=False both keep
variation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exams
|
ExamLike
|
Pool or sequence of exams. |
required |
elites
|
list[Individual]
|
Evaluated individuals that supply the case pack. |
required |
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
solved
|
CaseSolved | None
|
Optional solve predicate. See :func: |
None
|
case_count
|
int | None
|
Minimum catalog size forwarded to the guard when a
repair is needed. Defaults to |
None
|
informed
|
bool
|
When |
True
|
mut_prob
|
float
|
Per-range or per-run mutation probability. |
0.2
|
mode
|
DifficultyMode
|
Difficulty used to pick the exam that feeds lexicase and to detect collapse in the guard. |
'unsolved'
|
held_out
|
CaseExam | None
|
Caller-marked exam injected on collapse. |
None
|
min_cases
|
int
|
Minimum catalog size after a guard repair. |
1
|
length
|
int | None
|
Bound for range mutation. Defaults to each exam's
series span or |
None
|
Returns:
| Type | Description |
|---|---|
list[int]
|
Case indices for the next lexicase call. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/case_exam_step.py
score_case_exams(exams, elites, *, matrix=None, trust_matrix=False, solved=None, mode='unsolved')
¶
Score case subsets on elites by how many cases they still fool.
A case is solved when its value is within 1e-12 of zero, matching
sample_informed_cases. unsolved counts selected cases that no
elite solves. hamming counts unsolved elite-case pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exams
|
ExamLike
|
Exams, a :class: |
required |
elites
|
list[Individual]
|
Evaluated individuals that supply the case pack. |
required |
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
solved
|
CaseSolved | None
|
Optional |
None
|
mode
|
DifficultyMode
|
|
'unsolved'
|
Returns:
| Type | Description |
|---|---|
list[int]
|
One difficulty score per exam. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/case_exams.py
constraint_dominates(ind1, ind2, *, feasible=None, violation=None)
¶
Return whether ind1 constrained-dominates ind2.
Deb's NSGA-II rule (2002, §III-A): a feasible individual beats an
infeasible one; two feasibles use ordinary Pareto dominance on
fitness; two infeasibles prefer the smaller constraint
violation. Fitness values are not rewritten.
When only violation is given, <= 0 is feasible. When only
feasible is given, infeasibles do not dominate each other.
When both are given, the flag decides feasibility and the
violation is used only among infeasibles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
Candidate that may dominate. |
required |
ind2
|
Individual
|
Candidate that may be dominated. |
required |
feasible
|
Callable[[Individual], bool] | None
|
Predicate that reports whether an individual is
feasible. Optional if |
None
|
violation
|
Callable[[Individual], float] | None
|
Function returning a scalar constraint violation.
Optional if |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Raises:
| Type | Description |
|---|---|
TypeError
|
If both callables are omitted, a given argument is
not callable, or |
ValueError
|
If |
Source code in deap_er/private/operators/constraint_dominates.py
cx_heterogeneous(ind1, ind2, crossovers)
¶
Mate two mixed-encoding individuals with per-gene or per-slice operators.
Both individuals are modified in place. crossovers is either one
callable per gene or (slice, callable) pairs (tuple or list), not
a mix of the two. A single pair may be passed without wrapping it
in another sequence.
In the per-gene form each callable receives the pair of gene values
and must return the two replacements. In the per-slice form each
callable is an existing cx_* operator: it receives the extracted
units, may mutate them in place, and should return the two
replacements. Open slices such as slice(3, None) resolve against
the individual length. Uncovered genes are left unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
crossovers
|
Sequence[Any]
|
Per-gene |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the individuals have different lengths, the per-gene list length does not match, the two shapes are mixed, a slice is not contiguous or is inverted, slices overlap, a callable does not return a pair, or a slice operator changes the unit length. |
Source code in deap_er/private/operators/cx_hetero.py
cx_ordered(ind1, ind2)
¶
Execute an ordered crossover on two individuals.
Both individuals are modified in place. Alleles may be any hashable values that form a shared permutation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the individuals are not permutations of the same allele set. |
Source code in deap_er/private/operators/cx_permutation.py
cx_partially_matched(ind1, ind2)
¶
Execute a partially matched crossover on two individuals.
Both individuals are modified in place. Alleles may be any hashable values that form a shared permutation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the individuals are not permutations of the same allele set. |
Source code in deap_er/private/operators/cx_permutation.py
cx_uniform_partially_matched(ind1, ind2, cx_prob)
¶
Execute a uniform partially matched crossover on two individuals.
Both individuals are modified in place. Alleles may be any hashable values that form a shared permutation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
cx_prob
|
float
|
Probability of swapping any two traits. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the individuals are not permutations of the same allele set. |
Source code in deap_er/private/operators/cx_permutation.py
cx_es_two_point(ind1, ind2)
¶
Execute a two-point crossover on two individuals and their strategies.
Both individuals and their strategy vectors are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_point.py
cx_es_two_point_copy(ind1, ind2)
¶
Execute a two-point crossover on copies of two individuals and their strategies.
Use this instead of cx_es_two_point when the individuals are
based on numpy arrays, to avoid incorrect mating behavior due to
the specifics of the numpy array datatype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_point.py
cx_messy_one_point(ind1, ind2)
¶
Execute a messy one-point crossover on two individuals.
Cut points are chosen independently, so the individuals may change length. Both individuals are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_point.py
cx_one_point(ind1, ind2)
¶
Execute a one-point crossover on two individuals.
Both individuals are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_point.py
cx_two_point(ind1, ind2)
¶
Execute a two-point crossover on two individuals.
Both individuals are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_point.py
cx_two_point_copy(ind1, ind2)
¶
Execute a two-point crossover on copies of two individuals.
Use this instead of cx_two_point when the individuals are
based on numpy arrays, to avoid incorrect mating behavior due
to the specifics of the numpy array datatype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_point.py
cx_blend(ind1, ind2, alpha)
¶
Execute a blend crossover on two individuals.
Both individuals are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
alpha
|
float
|
Extent of the interval in which the new values can be drawn for each attribute on both sides of the parents' attributes. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_real.py
cx_blend_bounded(ind1, ind2, alpha, low, up)
¶
Execute a bounded blend crossover on two individuals.
Both individuals are modified in place. Each child gene is
clamped to [low, up] after the blend draw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
alpha
|
float
|
Extent of the interval in which the new values can be drawn for each attribute on both sides of the parents' attributes. |
required |
low
|
NumOrSeq
|
Lower bound of the search space. |
required |
up
|
NumOrSeq
|
Upper bound of the search space. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a bound sequence is shorter than the shorter individual. |
Source code in deap_er/private/operators/cx_real.py
cx_es_blend(ind1, ind2, alpha)
¶
Execute a blend crossover on two individuals and their strategies.
Both individuals and their strategy vectors are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
alpha
|
float
|
Extent of the interval in which the new values can be drawn for each attribute on both sides of the parents' attributes. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_real.py
cx_simulated_binary(ind1, ind2, eta)
¶
Execute a simulated binary crossover on two individuals.
Both individuals are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
eta
|
float
|
Crowding degree of the crossover. Higher values produce children more similar to their parents; smaller values produce children more divergent from their parents. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_real.py
cx_simulated_binary_bounded(ind1, ind2, eta, low, up)
¶
Execute a bounded simulated binary crossover on two individuals.
Both individuals are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
eta
|
float
|
Crowding degree of the crossover. Higher values produce children more similar to their parents; smaller values produce children more divergent from their parents. |
required |
low
|
NumOrSeq
|
Lower bound of the search space. |
required |
up
|
NumOrSeq
|
Upper bound of the search space. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/cx_real.py
cx_uniform(ind1, ind2, cx_prob)
¶
Execute a uniform crossover on two individuals.
Both individuals are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind1
|
Individual
|
The first individual. |
required |
ind2
|
Individual
|
The second individual. |
required |
cx_prob
|
float
|
Probability of swapping any two traits. |
required |
Returns:
| Type | Description |
|---|---|
Mates
|
The two individuals after crossover. |
Source code in deap_er/private/operators/cx_real.py
next_downsample_cases(individuals, case_count, generation, *, mode='random', cohort=None, cohorts=None, held_out=None, matrix=None, trust_matrix=False)
¶
Return the next cases= list for lexicase down-sampling.
Chronological meaning stays on the caller. This helper only picks catalog indices for one generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Evaluated population supplying fitness length. |
required |
case_count
|
int
|
Target subset size. Values above the catalog are
capped. |
required |
generation
|
int
|
Generation index used to rotate cohorts or held-out windows. |
required |
mode
|
DownsampleMode
|
|
'random'
|
cohort
|
Sequence[int] | None
|
Fixed case indices for |
None
|
cohorts
|
Sequence[Sequence[int]] | None
|
Rotating cohort lists for |
None
|
held_out
|
CaseExam | None
|
Caller-marked exam for |
None
|
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
list[int]
|
Distinct fitness-case indices for the next lexicase call. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/downsample_schedule.py
island_eval_keys(exams, *, n_cases, matrix=None, matrices=None)
¶
Return per-deme keys for step_islands(..., eval_keys=).
Keys compare equal when the exam subset and optional matrix
identity match, so migrants keep fitness only across demes that
evaluate on the same cases and packed matrix. Catalog exams —
masks or ranges that fit in n_cases — are canonicalized to a
painted boolean mask so equivalent subsets share a key even when
stored differently. Series exams keep normalized ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exams
|
Sequence[CaseExam]
|
One exam per deme. |
required |
n_cases
|
int
|
Fitness-case count from the current pack. |
required |
matrix
|
object | None
|
Optional matrix shared by every deme. |
None
|
matrices
|
Sequence[object] | None
|
Optional per-deme matrices. Must match |
None
|
Returns:
| Type | Description |
|---|---|
tuple[tuple[Any, ...], ...]
|
A tuple of hashable keys, one per exam. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
Source code in deap_er/private/operators/island_eval_keys.py
mig_fully_connected(populations, mig_count, selection, replacement=None)
¶
Move emigrants along every directed island edge.
For each ordered pair of distinct demes (src, dst), selection
picks mig_count emigrants from src and writes them into
dst using the same vacancy and cloning rules as mig_ring.
Emigrants are selected once per source, then cloned along each
outgoing edge so a destination update on another deme does not
change who leaves. Destinations claim distinct vacancy indices
across incoming edges so a later src does not overwrite an
earlier immigrant in the same slot. Edges run in (dst, src)
order; when replacement is omitted that order can still
matter for which home individuals are displaced. Cost is
O(n_demes² · mig_count) selection calls. Deme lengths are
unchanged. Populations are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
populations
|
list[list[Individual]]
|
Populations to migrate between. |
required |
mig_count
|
int
|
Number of individuals to migrate along each edge. |
required |
selection
|
Callable[..., Any]
|
Callable that selects emigrants from a population. |
required |
replacement
|
Callable[..., Any] | None
|
Callable that selects destination vacancies in the receiving deme. If omitted, the receiver's own emigrant slots are the vacancies. |
None
|
Source code in deap_er/private/operators/mig_ring.py
mig_random(populations, mig_count, selection, replacement=None)
¶
Move emigrants to a random destination deme per source.
Each source population sends mig_count emigrants to one
destination chosen uniformly among the other demes. When only one
deme exists, this is a no-op. Otherwise the placement rules match
mig_ring. Populations are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
populations
|
list[list[Individual]]
|
Populations to migrate between. |
required |
mig_count
|
int
|
Number of individuals to migrate from each population. |
required |
selection
|
Callable[..., Any]
|
Callable that selects emigrants from a population. |
required |
replacement
|
Callable[..., Any] | None
|
Callable that selects which destination individuals are replaced. If omitted, the destination's own emigrant slots are the vacancies. |
None
|
Source code in deap_er/private/operators/mig_ring.py
mig_ring(populations, mig_count, selection, replacement=None, mig_indices=None)
¶
Move emigrants between populations along a ring (or custom map).
From each population, selection picks mig_count emigrants.
Those individuals replace members of the destination population.
When a source sends more emigrants than the destination has
vacancies, or a deme is smaller than mig_count, only as
many individuals as both sides can hold are moved. Deme
lengths are unchanged. When replacement is omitted, an
emigrant whose home vacancy is not filled is cloned so the
same object is not left in two demes. A duplicate emigrant
already present in the destination is cloned so two dest
slots do not share one object. Populations are modified
in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
populations
|
list[list[Individual]]
|
Populations to migrate between. |
required |
mig_count
|
int
|
Number of individuals to migrate from each population. |
required |
selection
|
Callable[..., Any]
|
Callable that selects emigrants from a population. |
required |
replacement
|
Callable[..., Any] | None
|
Callable that selects which destination individuals are replaced. If omitted, the destination's own emigrants are the vacancies. |
None
|
mig_indices
|
list[int] | None
|
Destination index for each source population. If omitted, each population sends to the next and the last wraps to the first. |
None
|
Source code in deap_er/private/operators/mig_ring.py
mut_case_mask(mask, *, mut_prob)
¶
Flip contiguous True/False runs of a boolean mask in place.
Each run is flipped independently with probability mut_prob.
mut_prob <= 0 is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
ndarray
|
One-dimensional mutable boolean array. |
required |
mut_prob
|
float
|
Probability of flipping each contiguous run. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray]
|
A one-element tuple containing |
Source code in deap_er/private/operators/mut_case_exam.py
mut_case_ranges(ranges, *, length, mut_prob)
¶
Jitter half-open case ranges in place.
Each interval is mutated independently with probability mut_prob.
Endpoints stay inside [0, length] and are swapped if they cross.
mut_prob <= 0 is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranges
|
list[tuple[int, int]]
|
Mutable list of |
required |
length
|
int
|
Exclusive upper bound for |
required |
mut_prob
|
float
|
Probability of mutating each interval. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[tuple[int, int]]]
|
A one-element tuple containing |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/mut_case_exam.py
mut_de(individual, a, b, c, scale, cx_prob, *, low=None, up=None)
¶
Write a DE/rand/1/bin trial onto individual.
Genes selected by the binomial mask (rate cx_prob, at least
one gene forced) become a[i] + scale * (b[i] - c[i]). The
individual is modified in place. The caller supplies donors and
keeps the trial when it is better. Optional low / up
clamp written genes only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Trial vector to overwrite. Clone the parent first. |
required |
a
|
Individual
|
Base donor. |
required |
b
|
Individual
|
First difference donor. |
required |
c
|
Individual
|
Second difference donor. |
required |
scale
|
float
|
Difference weight |
required |
cx_prob
|
float
|
Per-gene crossover rate |
required |
low
|
NumOrSeq | None
|
Lower bound of the search space. Optional. |
None
|
up
|
NumOrSeq | None
|
Upper bound of the search space. Optional. |
None
|
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the trial individual. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a donor is shorter than the individual, if
only one of |
Source code in deap_er/private/operators/mut_de.py
mut_gaussian_bounded(individual, mu, sigma, low, up, mut_prob)
¶
Apply a Gaussian mutation and clamp each mutated gene into a box.
The individual is modified in place. The draw is the same
N(mu, sigma) add as mut_gaussian. mu, sigma,
low, and up may be scalars or per-gene sequences. An empty
interval (up <= low) is skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Individual to mutate. |
required |
mu
|
NumOrSeq
|
Mean of the Gaussian mutation. |
required |
sigma
|
NumOrSeq
|
Standard deviation of the Gaussian mutation. |
required |
low
|
NumOrSeq
|
Lower bound of the search space. |
required |
up
|
NumOrSeq
|
Upper bound of the search space. |
required |
mut_prob
|
float
|
Probability of mutating each attribute. |
required |
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the mutated individual. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/mut_gaussian_bounded.py
mut_heterogeneous(individual, mutators, mut_prob)
¶
Mutate each gene with its own callable.
The individual is modified in place. mutators[i] receives the
current value of gene i and must return the replacement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Individual to mutate. |
required |
mutators
|
Sequence[Callable[[Any], Any]]
|
One gene mutator per attribute. |
required |
mut_prob
|
float
|
Probability of mutating each attribute. |
required |
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the mutated individual. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/mut_hetero.py
iso_line_bit(parent, donor, iso, sigma)
¶
Move toward donor along the line, then apply isotropic flips.
t maps to a Bernoulli draw toward donor. sigma is the
probability of flipping the chosen bit afterward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
bool
|
Current gene value. |
required |
donor
|
bool
|
Elite donor value. |
required |
iso
|
float
|
Line extension for |
required |
sigma
|
float
|
Flip probability after the line draw. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The mutated boolean gene. |
Source code in deap_er/private/operators/mut_iso_line.py
iso_line_float(parent, donor, iso, sigma, *, low=None, up=None)
¶
Interpolate toward donor and add isotropic Gaussian noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
float
|
Current gene value. |
required |
donor
|
float
|
Elite donor value. |
required |
iso
|
float
|
Line extension for |
required |
sigma
|
float
|
Standard deviation of the isotropic perturbation. |
required |
low
|
float | None
|
Optional lower bound applied after the draw. |
None
|
up
|
float | None
|
Optional upper bound applied after the draw. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The mutated gene value. |
Source code in deap_er/private/operators/mut_iso_line.py
iso_line_int(parent, donor, iso, sigma, *, low, up)
¶
Interpolate toward donor, add noise, round, and clamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
int
|
Current gene value. |
required |
donor
|
int
|
Elite donor value. |
required |
iso
|
float
|
Line extension for |
required |
sigma
|
float
|
Standard deviation of the isotropic perturbation. |
required |
low
|
int
|
Inclusive lower bound. |
required |
up
|
int
|
Inclusive upper bound. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The mutated integer gene. |
Source code in deap_er/private/operators/mut_iso_line.py
mut_iso_line(individual, donor, iso, sigma, *, low=None, up=None)
¶
Apply iso+line mutation toward an archive elite donor.
Each gene becomes parent + t * (donor - parent) + N(0, sigma)
with t ~ Uniform(-iso, 1 + iso). Booleans use iso_line_bit;
integers (that are not bool) round and clamp when bounds are given;
other numeric genes clamp when bounds are given. The individual is
modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Parent to overwrite. Clone first when needed. |
required |
donor
|
Individual
|
Elite donor from |
required |
iso
|
float
|
Line extension parameter. |
required |
sigma
|
float
|
Isotropic noise standard deviation (flip rate for bool). |
required |
low
|
NumOrSeq | None
|
Lower search bound. Optional. |
None
|
up
|
NumOrSeq | None
|
Upper search bound. Optional. |
None
|
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the mutated individual. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/mut_iso_line.py
mut_es_log_normal(individual, learn_rate, mut_prob)
¶
Mutate an evolution strategy according to its strategy attribute.
The individual is modified in place. Genes are updated only when
the individual has a strategy attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Individual to mutate. |
required |
learn_rate
|
float
|
Learning rate of the evolution strategy. For an evolution strategy of (10, 100) the recommended value is 1. |
required |
mut_prob
|
float
|
Probability of mutating each attribute. |
required |
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the mutated individual. |
Source code in deap_er/private/operators/mut_various.py
mut_flip_bit(individual, mut_prob)
¶
Flip the values of random attributes of the individual.
The individual is modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Individual to mutate. |
required |
mut_prob
|
float
|
Probability of mutating each attribute. |
required |
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the mutated individual. |
Source code in deap_er/private/operators/mut_various.py
mut_gaussian(individual, mu, sigma, mut_prob)
¶
Apply a Gaussian mutation of mean mu and standard deviation sigma.
The individual is modified in place. mu and sigma may be
scalars or per-gene sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Individual to mutate. |
required |
mu
|
NumOrSeq
|
Mean of the Gaussian mutation. |
required |
sigma
|
NumOrSeq
|
Standard deviation of the Gaussian mutation. |
required |
mut_prob
|
float
|
Probability of mutating each attribute. |
required |
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the mutated individual. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/mut_various.py
mut_polynomial_bounded(individual, eta, low, up, mut_prob)
¶
Apply a bounded polynomial mutation with crowding degree eta.
The individual is modified in place. low and up may be
scalars or per-gene sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Individual to mutate. |
required |
eta
|
float
|
Crowding degree of the mutation. Higher values produce children more similar to their parents; smaller values produce children more divergent from their parents. |
required |
low
|
NumOrSeq
|
Lower bound of the search space. |
required |
up
|
NumOrSeq
|
Upper bound of the search space. |
required |
mut_prob
|
float
|
Probability of mutating each attribute. |
required |
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the mutated individual. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/mut_various.py
mut_shuffle_indexes(individual, mut_prob)
¶
Shuffle attributes of the individual.
The individual is modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Individual to mutate. |
required |
mut_prob
|
float
|
Probability of mutating each attribute. |
required |
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the mutated individual. |
Source code in deap_er/private/operators/mut_various.py
mut_uniform_int(individual, low, up, mut_prob)
¶
Replace attributes with integers drawn uniformly from [low, up].
The individual is modified in place. Bounds are inclusive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Individual to mutate. |
required |
low
|
int
|
Lower bound of the search space. |
required |
up
|
int
|
Upper bound of the search space. |
required |
mut_prob
|
float
|
Probability of mutating each attribute. |
required |
Returns:
| Type | Description |
|---|---|
Mutant
|
A one-element tuple containing the mutated individual. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/mut_various.py
estimate_policy_action_evals(action, /, **kwargs)
¶
Estimate how many evaluations an action would spend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Policy action token. |
required |
**kwargs
|
Any
|
Arguments that would be forwarded to
:func: |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
A conservative evaluation count used for budget checks. |
Source code in deap_er/private/operators/policy_action_guard.py
guard_policy_action(action, guard, /, **kwargs)
¶
Return whether action is allowed under guard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Policy action token. |
required |
guard
|
PolicyActionGuard
|
Guard state and caps. |
required |
**kwargs
|
Any
|
Arguments that would be forwarded to
:func: |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in deap_er/private/operators/policy_action_guard.py
guard_policy_fitness_exam(fitness_exam, *, held_out, n_cases, train_exams=None, mutated_exam=None)
¶
Refuse policy fitness that targets a train or mutated exam.
Policy individuals must be scored only on held_out. Train-exam
quality belongs in :func:~deap_er.tools.policy_observe, not in
fitness assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fitness_exam
|
CaseExam
|
Exam the caller would score for policy fitness. |
required |
held_out
|
CaseExam
|
Caller-marked held-out exam. |
required |
n_cases
|
int
|
Catalog length from the current elite pack. |
required |
train_exams
|
list[CaseExam] | None
|
Optional train exams that must not become the fitness target. |
None
|
mutated_exam
|
CaseExam | None
|
Optional exam the policy action just varied. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/policy_fitness.py
policy_held_out_fitness(elites, exams, *, held_out=None, fitness_exam=None, train_exams=None, mutated_exam=None, matrix=None, trust_matrix=False, solved=None, mode='unsolved')
¶
Score policy individuals only on the held-out exam.
Train-exam difficulty is not part of the objective. Pair with
:func:~deap_er.tools.policy_exam_scores and
:func:~deap_er.records.policy_generalization_gap for
observations and logbook chapters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elites
|
list[Individual]
|
Evaluated tape individuals that supply the case pack. |
required |
exams
|
ExamLike
|
Train exams or a pool with a caller-marked |
required |
held_out
|
CaseExam | None
|
Optional held-out exam that overrides a pool marker. |
None
|
fitness_exam
|
CaseExam | None
|
Optional exam the caller would assign fitness on.
When set, it must match |
None
|
train_exams
|
list[CaseExam] | None
|
Optional train exams checked by
:func: |
None
|
mutated_exam
|
CaseExam | None
|
Optional exam varied by the last policy action. |
None
|
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
solved
|
CaseSolved | None
|
Optional solve predicate. See :func: |
None
|
mode
|
DifficultyMode
|
|
'unsolved'
|
Returns:
| Type | Description |
|---|---|
float
|
Held-out exam difficulty as the policy fitness scalar. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no held-out exam is marked or a guard refuses the requested fitness exam. |
Source code in deap_er/private/operators/policy_fitness.py
resolve_policy_held_out(exams, *, held_out=None)
¶
Return the caller-marked held-out exam for policy fitness.
Train exams in a :class:~deap_er.records.CaseExamPool are never
returned. Chronological meaning and marking stay on the caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exams
|
ExamLike
|
Train exams, a pool, or a single exam sequence. |
required |
held_out
|
CaseExam | None
|
Optional held-out exam that overrides a pool marker. |
None
|
Returns:
| Type | Description |
|---|---|
CaseExam
|
The resolved held-out exam. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no held-out exam is marked. |
Source code in deap_er/private/operators/policy_fitness.py
sample_informed_cases(individuals, case_count, *, solved=None, matrix=None, trust_matrix=False)
¶
Build a down-sample that prefers distinct fitness cases.
Two cases are synonymous when the same individuals solve them. Distance is the Hamming distance of those solve vectors. A random first case is kept, then farthest-first traversal adds the case farthest from the nearest already-chosen case. Ties, including a tail of zero distances, are broken at random.
A case is solved when fitness.values[case] is within 1e-12
of zero. Maximize-only scores and larger residuals need
solved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Population whose fitness vectors supply solve bits. Pass a fully scored parent sample if evaluation is sparse. |
required |
case_count
|
int
|
Number of case indices to return. Values above the
number of cases are capped. |
required |
solved
|
CaseSolved | None
|
Predicate |
None
|
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
list[int]
|
Distinct fitness-case indices, in the order they were picked. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If an individual has a missing or mismatched fitness length. |
Source code in deap_er/private/operators/sample_informed_cases.py
sel_age_moea_2(individuals, sel_count, *, best_point=None, worst_point=None, extreme_points=None, nr_tol=0.001, nr_max_iter=100, _memory=None)
¶
Select the next generation with AGE-MOEA-II.
Follows the environmental-selection loop of Panichella (GECCO 2022, Algorithm 2): non-dominated fronts are processed in order; when a front does not fit entirely, survivors are chosen by geometry-aware scores. The first front uses Newton-Raphson curvature and geodesic diversity; later fronts reuse the first front normalization and rank by inverse Minkowski distance to the ideal point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
best_point
|
ndarray | None
|
Ideal point of the previous generation. If omitted, it is taken from the current individuals. |
None
|
worst_point
|
ndarray | None
|
Nadir point of the previous generation. If omitted, it is taken from the current individuals. |
None
|
extreme_points
|
ndarray | None
|
Extreme points of the previous generation. If omitted, they are taken from the current individuals. |
None
|
nr_tol
|
float
|
Newton-Raphson stopping tolerance for curvature. |
0.001
|
nr_max_iter
|
int
|
Maximum Newton-Raphson iterations. |
100
|
_memory
|
SelAGE2WithMemory | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_age_moea_2.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
sel_batch_epsilon_lexicase(individuals, sel_count, batch_size, epsilon=None, *, cases=None, matrix=None, trust_matrix=False, fit_weights=None, reduction=None)
¶
Select individuals by epsilon-lexicase on batched case reductions.
Cases are shuffled and grouped into batches of at most
batch_size. Each batch is reduced to one pseudo-case (mean
squared error by default), then the usual epsilon-lexicase filter
runs on the shorter matrix. A fresh shuffle and partition are
drawn for every selected individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
batch_size
|
int
|
Maximum cases per batch. |
required |
epsilon
|
float | None
|
Slack around the best batch value. If omitted, it is computed from the median absolute deviation of each batch column separately. |
None
|
cases
|
Sequence[int] | None
|
Fitness-case indices to filter on. All cases are used when omitted. |
None
|
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
fit_weights
|
Sequence[float] | None
|
Optional per-column maximize/minimize signs.
Required when |
None
|
reduction
|
CaseReduction | None
|
Maps a |
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the population is empty or a case index is outside the fitness length. |
ValueError
|
If |
Source code in deap_er/private/operators/sel_batch_epsilon_lexicase.py
assign_crowding_dist(individuals, *, use_weights=False)
¶
Assign a crowding distance to each individual's fitness.
The distance is stored on the crowding_dist attribute of each
individual's fitness. The individuals are modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals with Fitness attributes. |
required |
use_weights
|
bool
|
If True, crowd on |
False
|
Source code in deap_er/private/operators/sel_helpers.py
uniform_reference_points(objectives, ref_ppo=4, scaling=None)
¶
Generate reference points uniformly on the unit simplex.
Points lie on the hyperplane that intersects each axis at 1.
scaling shrinks that layer toward the simplex center so
several layers can be combined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objectives
|
int
|
Number of objectives. |
required |
ref_ppo
|
int
|
Number of reference points per objective. |
4
|
scaling
|
float | None
|
Optional scaling factor for combining layers. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Uniform reference points. |
Source code in deap_er/private/operators/sel_helpers.py
sel_epsilon_lexicase(individuals, sel_count, epsilon=None, *, mode=None, cases=None, matrix=None, trust_matrix=False, fit_weights=None)
¶
Select individuals by epsilon-lexicase filtering of fitness cases.
Each selected individual is the last remaining candidate after
fitness cases are considered one at a time in random order.
Candidates within epsilon of the best case value are kept.
Pass cases to restrict the filter to a per-generation subset.
Pass matrix when a packed case matrix is already available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
epsilon
|
float | None
|
Slack around the best case value. If omitted, it is computed from the median absolute deviation of the case values, separately for every case. |
None
|
mode
|
LexicaseMode | None
|
Epsilon variant when |
None
|
cases
|
Sequence[int] | None
|
Fitness-case indices to filter on. All cases are used when omitted. Rebuild the subset each generation; do not freeze it on the toolbox. |
None
|
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
fit_weights
|
Sequence[float] | None
|
Optional per-column maximize/minimize signs.
Required when |
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the population is empty or a case index is outside the fitness length. |
ValueError
|
If |
Source code in deap_er/private/operators/sel_lexicase.py
sel_lexicase(individuals, sel_count, *, cases=None, matrix=None, trust_matrix=False, fit_weights=None)
¶
Select individuals by lexicase filtering of fitness cases.
Each selected individual is the last remaining candidate after
fitness cases are considered one at a time in random order.
Pass cases to restrict the filter to a per-generation subset.
Pass matrix when a packed case matrix is already available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
cases
|
Sequence[int] | None
|
Fitness-case indices to filter on. All cases are used when omitted. Rebuild the subset each generation; do not freeze it on the toolbox. |
None
|
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
fit_weights
|
Sequence[float] | None
|
Optional per-column maximize/minimize signs.
Required when |
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the population is empty or a case index is outside the fitness length. |
ValueError
|
If |
Source code in deap_er/private/operators/sel_lexicase.py
fitness_case_matrix(individuals)
¶
Pack fitness.values into a dense (n_individuals, n_cases) matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Evaluated population. Zero-case fitness is packed
as |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Case values with one row per individual. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/sel_lexicase_matrix.py
sel_moead(individuals, sel_count, weights, *, scalarization='tchebycheff', theta=5.0, ideal_point=None, _memory=None)
¶
Select the next generation with MOEA/D decomposition.
Each weight vector defines a scalar subproblem. weights is
typically uniform_reference_points. Subproblem winners
prefer lower Pareto ranks; remaining slots are filled from
complete lower fronts, then crowding distance on the last
partial front of the leftover pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
weights
|
ndarray
|
Decomposition weight vectors with shape |
required |
scalarization
|
ScalarizationName | ScalarizationFn
|
|
'tchebycheff'
|
theta
|
float
|
PBI penalty parameter. |
5.0
|
ideal_point
|
ndarray | None
|
Ideal point from a previous generation. If omitted, it is taken from the current individuals. |
None
|
_memory
|
SelMOEADWithMemory | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_moead.py
moead_neighborhood(weights, n_neighbors)
¶
Return sorted neighbor indices for each weight vector.
Each row lists the n_neighbors closest weight vectors by
Euclidean distance, including the index itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
ndarray
|
Weight matrix with shape |
required |
n_neighbors
|
int
|
Number of neighbors per weight vector. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Integer matrix with shape |
Source code in deap_er/private/operators/sel_moead_helpers.py
scalarization_pbi(fitness, weights, ideal_point, theta=5.0, eps=1e-16)
¶
Return PBI scalarized values for each individual and weight.
Lower values are better. fitness and ideal_point are in
minimize space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fitness
|
ndarray
|
Objective matrix with shape |
required |
weights
|
ndarray
|
Weight matrix with shape |
required |
ideal_point
|
ndarray
|
Ideal point with shape |
required |
theta
|
float
|
Penalty parameter balancing convergence and diversity. |
5.0
|
eps
|
float
|
Small constant added to zero weights. |
1e-16
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Scalarized matrix with shape |
Source code in deap_er/private/operators/sel_moead_helpers.py
scalarization_tchebycheff(fitness, weights, ideal_point, eps=1e-16)
¶
Return Tchebycheff scalarized values for each individual and weight.
Lower values are better. fitness and ideal_point are in
minimize space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fitness
|
ndarray
|
Objective matrix with shape |
required |
weights
|
ndarray
|
Weight matrix with shape |
required |
ideal_point
|
ndarray
|
Ideal point with shape |
required |
eps
|
float
|
Small constant added to zero weights. |
1e-16
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Scalarized matrix with shape |
Source code in deap_er/private/operators/sel_moead_helpers.py
sel_novelty(individuals, sel_count, archive, descriptor_fn, *, k=15, metric='euclidean', valid=None)
¶
Select individuals with the highest average distance to archive elites.
Novelty is the mean distance to the k nearest stored behavior
descriptors. ind.fitness is not rewritten; only the ranking key
changes. An empty archive falls back to uniform random selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to return. Non-positive values return an empty list. |
required |
archive
|
MapElitesArchive
|
MAP-Elites archive whose behavior coordinates define
the reference set. Uses |
required |
descriptor_fn
|
Callable[[Individual], Sequence[float]]
|
Maps a pool member to its behavior coordinates. |
required |
k
|
int
|
Number of nearest archive neighbors averaged into the score. |
15
|
metric
|
SemanticMetric
|
|
'euclidean'
|
valid
|
ndarray | None
|
Optional per-dimension warmup mask passed to
|
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The most novel individuals. Ties keep the lowest pool index. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/sel_novelty.py
sel_nsga_2(individuals, sel_count, *, feasible=None, violation=None)
¶
Select the next generation with NSGA-II.
The pool is usually larger than sel_count. If the two sizes
are equal, the population is sorted by Pareto front.
Optional feasible / violation switch ranking to Deb's
constrained-domination rule: feasible individuals beat infeasible
ones, two feasibles use ordinary Pareto and crowding, and two
infeasibles prefer the smaller constraint violation. Omitted
kwargs keep unconstrained NSGA-II. Fitness values are not
rewritten.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
feasible
|
Callable[[Individual], bool] | None
|
Predicate that reports whether an individual is
feasible. Optional if |
None
|
violation
|
Callable[[Individual], float] | None
|
Function returning a scalar constraint violation.
Optional if |
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a given constraint argument is not callable, or
|
ValueError
|
If |
Source code in deap_er/private/operators/sel_nsga_2.py
sel_nsga_3(individuals, sel_count, ref_points, best_point=None, worst_point=None, extreme_points=None, _memory=None)
¶
Select the next generation with NSGA-III.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
ref_points
|
ndarray
|
Reference points used for niche selection. |
required |
best_point
|
ndarray | None
|
Ideal point of the previous generation. If omitted, it is taken from the current individuals. |
None
|
worst_point
|
ndarray | None
|
Nadir point of the previous generation. If omitted, it is taken from the current individuals. |
None
|
extreme_points
|
ndarray | None
|
Extreme points of the previous generation. If omitted, they are taken from the current individuals. |
None
|
_memory
|
SelNSGA3WithMemory | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_nsga_3.py
sel_sms_emoa(individuals, sel_count, ref_point=None)
¶
Select the next generation with SMS-EMOA.
Non-dominated sorting ranks the pool. Complete fronts are kept.
When the next front would exceed sel_count, individuals with
the smallest hypervolume contribution on that critical front are
removed one at a time until the quota is met. This is the Reduce
operator from Beume, Naujoks, and Emmerich (2007).
Use on parents + offspring for generational search, or on
parents + [child] for steady-state (mu + 1) selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Evaluated individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to keep. |
required |
ref_point
|
list[float] | ndarray | None
|
Reference point in minimization space (the same
convention as |
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. Complete Pareto fronts appear first; |
list[Individual]
|
survivors from the truncated critical front keep their relative |
list[Individual]
|
list order after greedy removal (unlike |
list[Individual]
|
are not crowding-sorted within the front). |
Source code in deap_er/private/operators/sel_sms_emoa.py
sel_spea_2(individuals, sel_count)
¶
Select the next generation with SPEA-II.
The pool is usually larger than sel_count. If the two sizes
are equal, the population is sorted by Pareto front.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_spea_2.py
sel_team(individuals, sel_count, *, cases=None, matrix=None, trust_matrix=False)
¶
Select a team by greedy maximum coverage of solved fitness cases.
A case is solved when its value is within 1e-12 of zero. Each
added member is an unused pool individual that covers the most
still-uncovered cases. Ties are broken at random. Member
fitness is not rewritten; score the team on the caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Team size. Values above the pool length return the
whole pool. |
required |
cases
|
Sequence[int] | None
|
Fitness-case indices to cover. All distinct cases are used when omitted. Duplicate indices are covered once. |
None
|
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
Distinct pool members in greedy-add order. |
list[Individual]
|
is the individual that solves the most selected cases. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the population is empty or a case index is outside the fitness length. |
ValueError
|
If |
Source code in deap_er/private/operators/sel_team.py
sel_team_archive(archive, sel_count, *, cases=None, matrix=None, trust_matrix=False)
¶
Select a team from occupied MAP-Elites archive cells.
The pool is list(archive) — live elites from filled cells, not
random_elites copies. Delegates to :func:sel_team. Member
fitness is not rewritten; score the team on the caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
MapElitesArchive
|
MAP-Elites archive with |
required |
sel_count
|
int
|
Team size. Same semantics as :func: |
required |
cases
|
Sequence[int] | None
|
Fitness-case indices to cover. Passed through to
:func: |
None
|
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
Distinct archive elites in greedy-add order. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the archive is empty or a case index is outside the fitness length. |
ValueError
|
If |
Source code in deap_er/private/operators/sel_team.py
sel_double_tournament(individuals, rounds, fitness_size, parsimony_size, fitness_first, fit_attr='fitness')
¶
Select with a fitness tournament and a size tournament.
The size contest can be used in genetic programming as a bloat control technique.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
rounds
|
int
|
Number of tournament rounds. |
required |
fitness_size
|
int
|
Number of individuals in each fitness tournament. |
required |
parsimony_size
|
float
|
Number of individuals in each size tournament.
Must be in |
required |
fitness_first
|
bool
|
If True, run the fitness tournament first. |
required |
fit_attr
|
str
|
Attribute used as the fitness selection criterion. |
'fitness'
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. An empty pool or |
list[Individual]
|
returns an empty list. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/sel_tournament.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
sel_tournament(individuals, rounds, contestants, fit_attr='fitness')
¶
Select the best of contestants random individuals, rounds times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
rounds
|
int
|
Number of tournament rounds. |
required |
contestants
|
int
|
Number of individuals in each round. |
required |
fit_attr
|
str
|
Attribute used as the selection criterion. |
'fitness'
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_tournament.py
sel_tournament_cases(individuals, rounds, contestants, *, cases=None, case_count=None, matrix=None, trust_matrix=False, reduction=None)
¶
Tournament selection on a down-sampled case aggregate.
Each individual is scored by reducing a case subset to one scalar
(column mean by default), then standard tournament selection runs
on those scores. The aggregate ranking uses the maximize/minimize
sign of the first case index in the resolved subset; mixed
per-case weights are not applied column-wise. When cases=[] or
case_count <= 0, every individual ties on score zero and
tournament rounds draw uniformly from the pool. Informed
down-sampling stays on
:func:~deap_er.tools.sample_informed_cases; pass its result as
cases=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
rounds
|
int
|
Number of tournament rounds. |
required |
contestants
|
int
|
Number of individuals in each round. |
required |
cases
|
Sequence[int] | None
|
Fitness-case indices to score. All cases are used when
omitted and |
None
|
case_count
|
int | None
|
When |
None
|
matrix
|
ndarray | None
|
Optional |
None
|
trust_matrix
|
bool
|
When |
False
|
reduction
|
CaseReduction | None
|
Maps a |
None
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the population is empty. |
ValueError
|
If |
Source code in deap_er/private/operators/sel_tournament_cases.py
sel_tournament_dcd(individuals, sel_count)
¶
Select by pairwise dominance, breaking ties with crowding distance.
When sel_count is a multiple of four the original paired
shuffle is used. Other counts run pairwise contests until enough
winners are collected. Each individual must already have a
crowding_dist attribute, which assign_crowding_dist can
set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/operators/sel_tournament_dcd.py
sel_best(individuals, sel_count, fit_attr='fitness')
¶
Select the sel_count best individuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
fit_attr
|
str
|
Attribute used as the selection criterion. |
'fitness'
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_various.py
sel_random(individuals, sel_count)
¶
Select sel_count individuals uniformly at random.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. An empty pool or |
list[Individual]
|
returns an empty list. |
Source code in deap_er/private/operators/sel_various.py
sel_roulette(individuals, sel_count, fit_attr='fitness')
¶
Select sel_count individuals by roulette-wheel sampling.
Each draw uses only the first weighted objective of fit_attr.
The returned list holds references to the input individuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
fit_attr
|
str
|
Attribute used as the selection criterion. |
'fitness'
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_various.py
sel_stochastic_universal_sampling(individuals, sel_count, fit_attr='fitness')
¶
Select sel_count individuals by stochastic universal sampling.
A single random offset samples the wheel at evenly spaced
intervals. Only the first weighted objective of fit_attr is
used. The returned list holds references to the input individuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
fit_attr
|
str
|
Attribute used as the selection criterion. |
'fitness'
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_various.py
sel_worst(individuals, sel_count, fit_attr='fitness')
¶
Select the sel_count worst individuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to select from. |
required |
sel_count
|
int
|
Number of individuals to select. |
required |
fit_attr
|
str
|
Attribute used as the selection criterion. |
'fitness'
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The selected individuals. |
Source code in deap_er/private/operators/sel_various.py
estimate_tune_ephemerals_evals(strategy, n_gen)
¶
Estimate how many evaluations a memetic tune would spend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
Any
|
|
required |
n_gen
|
int
|
Inner CMA generations. |
required |
Returns:
| Type | Description |
|---|---|
int
|
|
Source code in deap_er/private/programming/memetic_defaults.py
structural_meta_case_columns(individuals, *, prim_set=None, predicted=None, columns=None)
¶
Return cheap structural meta-case columns for a population.
Shape (len(individuals), len(columns)). Tree metrics need no
predicted. non_finite_fraction needs one row per
individual in predicted ((n_ind, n_rows) or a sequence of
1-D series). When predicted is missing, that column is filled
with numpy.nan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
Sequence[Any]
|
Population whose genomes are |
required |
prim_set
|
PrimitiveSetTyped | None
|
Primitive set for |
None
|
predicted
|
ndarray | Sequence[Sequence[float]] | None
|
Optional per-individual output series. |
None
|
columns
|
Sequence[str] | None
|
Subset of :data: |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Structural scalars with one row per individual. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/various/structural_meta_case.py
structural_meta_case_weights(columns=None)
¶
Return default lexicase signs for structural meta-case columns.
Bloat metrics default to minimize (-1). non_finite_fraction
defaults to maximize (+1) so lexicase prefers programs that are
not finite on every bar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
Sequence[str] | None
|
Subset of :data: |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, ...]
|
One maximize/minimize sign per column. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a column name is unknown. |