GP Mutation

mut_uniform(individual, expr, prim_set)

Mutates an individual by replacing a random subtree with an expression generated from the given expr.

Parameters
  • individual (GPIndividual) – The GP tree to be mutated.

  • expr (Callable) – A callable that, when called, returns a random GP subtree.

  • prim_set (PrimitiveSetTyped) – The PrimitiveSet to be used for the mutation.

Returns

The mutated individual.

Return type

GPMutant

mut_node_replacement(individual, prim_set)

Mutates an individual by replacing a random primitive with a random primitive from the given p_set.

Parameters
Returns

The mutated individual.

Return type

GPMutant

mut_ephemeral(individual, mode='all')

Mutates an individual by replacing either one random or all ephemeral constants.

Parameters
  • individual (GPIndividual) – The GP tree to be mutated.

  • mode (str) – The mode of mutation. Either ‘one’ or ‘all’.

Returns

The mutated individual.

Return type

GPMutant

mut_insert(individual, prim_set)

Inserts a new branch at a random position in the tree.

Parameters
Returns

The mutated individual.

Return type

GPMutant

mut_shrink(individual)

Shrinks a tree by removing a random branch, replacing it with a random argument of the branch.

Parameters

individual (GPIndividual) – The GP tree to be mutated.

Returns

The mutated individual.

Return type

GPMutant

mut_semantic(individual, prim_set, min_depth=2, max_depth=6, gen_func=None, mut_step=None)

Perform a semantic mutation on the given individual.

Parameters
  • individual (list) – The individual to be mutated.

  • prim_set (PrimitiveSetTyped) – Primitive set from which primitives are selected.

  • gen_func (Optional[Callable]) – The function which generates the random tree.

  • mut_step (Optional[float]) – The mutation step.

  • min_depth (int) – Minimum depth of the random tree.

  • max_depth (int) – Maximum depth of the random tree.

Returns

The mutated individual.

Return type

tuple[list]