pg.evolution.Mutator¶
Accessible via pg.evolution.Mutator
.
- class Mutator[source]¶
Bases:
pg.evolution.DNAOperation
Base class for mutators.
A mutator performs a mutation, i.e. a random transformation that converts a parent DNA to a child DNA. Mutations should reach the full search space through composition and should prefer local transformations individually.
Methods:
mutate
(dna, global_state[, step])Mutates the DNA at a given step.
mutate_list
(dna_list, global_state[, step])Mutate the DNA in the input one by one and concatenate their outputs.
Attributes:
Returns a member method as operation.
- mutate(dna, global_state, step=0)[source]¶
Mutates the DNA at a given step.
User should override this method or mutate_list method with optional keyword arguments ‘global_state’ and ‘step’.
- Return type:
- Parameters:
dna – DNA to mutate.
global_state – An AttributeDict object as the container of global states.
step – Number of examples historically proposed, which can be used for determining a mutation schedule.
- Returns:
A new DNA or a DNA list as the result of the mutation.
- mutate_list(dna_list, global_state, step=0)[source]¶
Mutate the DNA in the input one by one and concatenate their outputs.
User should override this method instead of mutate if mutation depends on the list-wise information. Keyword arguments global_state and step are optional when override.
- Return type:
- Parameters:
dna_list – a list of DNA to mutate.
global_state – An AttributeDict object as the container of global states.
step – Number of examples historically proposed, which can be used for determining a mutation schedule.
- Returns:
a list of DNA as the result of the mutation.