pg.evolution.recombinators.Sample¶
Accessible via pg.evolution.recombinators.Sample
.
- class Sample(weights, where=All(), seed=None)[source]¶
Bases:
pg.evolution.recombinators.PointWise
Point-wise crossover that sample values from parents by weights.
The Sample recombinator works similarly as the Uniform recombinator, except that it takes a user function to compute the weights, based on which each parent’s decision will be sampled. Uniform can be represented as Sample(lambda xs: [1] * len(xs)), whose weights function generates the sampling weights in uniform distribution.
Methods:
merge
(decision_point, parent_decisions)Implementation of point-wise decision making.
- merge(decision_point, parent_decisions)[source]¶
Implementation of point-wise decision making.
- Return type:
- Parameters:
decision_point – Decision point for recombination.
parent_decisions – A list of parent’s decisions. Each item should be an int as an active single-choice decision, a list of int as active multi- choice decisions, a float as an active float decision, or None for inactive decision point (whose parent space is not chosen).
global_state – An optional keyword argument as the global state. Subclass can omit.
step – An optional keyword argument as the current step. Subclass can omit.
- Returns:
An int, list of int or float as the decision made for the decision point.