Mutation Operators

Submodules

pygenalgo.operators.mutation.flip_mutator module

class pygenalgo.operators.mutation.flip_mutator.FlipMutator(mutate_probability: float = 0.1)[source]

Bases: MutationOperator

Description:

Flip mutator, mutates the chromosome by selecting randomly a position and flip its Gene value (0 -> 1, or 1 -> 0).

mutate(individual: Chromosome) None[source]

Perform the mutation operation by randomly flipping a gene.

Parameters:

individual – (Chromosome).

Returns:

None.

pygenalgo.operators.mutation.gaussian_mutator module

class pygenalgo.operators.mutation.gaussian_mutator.GaussianMutator(mutate_probability: float = 0.1, sigma: float = 1.0, lower_val: float | None = None, upper_val: float | None = None)[source]

Bases: MutationOperator

Description:

Gaussian mutator, mutates the chromosome by selecting randomly a position and perturbing it with a Gaussian random value to the current gene value.

mutate(individual: Chromosome) None[source]

Perform the mutation operation by randomly adding the Gaussian value to a randomly selected gene position.

Parameters:

individual – (Chromosome).

Returns:

None.

pygenalgo.operators.mutation.inverse_mutator module

class pygenalgo.operators.mutation.inverse_mutator.InverseMutator(mutate_probability: float = 0.1)[source]

Bases: MutationOperator

Description:

Inverse mutator mutates the chromosome by inverting the order of the gene values between two randomly selected gene end-positions.

mutate(individual: Chromosome) None[source]

Perform the mutation operation by inverting the genes between at two random positions.

Parameters:

individual – (Chromosome).

Returns:

None.

pygenalgo.operators.mutation.meta_mutator module

class pygenalgo.operators.mutation.meta_mutator.MetaMutator(mutate_probability: float = 0.1)[source]

Bases: MutationOperator

Description:

Meta-mutator, mutates the chromosome by applying randomly all other mutators (one at a time), with equal probability.

NOTE: In the future the equal probabilities can be amended.

property all_counters: dict

Accessor (getter) of the application counter from all the internal mutators. This is mostly to verify that everything is working as expected.

Returns:

a dictionary with the counter calls for all mutator methods.

mutate(individual: Chromosome) None[source]

Perform the mutation operation by randomly applying another mutator.

Parameters:

individual – (Chromosome).

Returns:

None.

reset_counter() None[source]

Sets ALL the counters to ‘zero’. We have to override the super().reset_counter() method, because we have to call explicitly the reset_counter on all the internal operators.

Returns:

None.

pygenalgo.operators.mutation.mutate_operator module

class pygenalgo.operators.mutation.mutate_operator.MutationOperator(mutation_probability: float)[source]

Bases: GeneticOperator

Description:

Provides the base class (interface) for a Mutation Operator.

mutate(individual: Chromosome) None[source]

Abstract method that “reminds” the user that if they want to create a Mutation Class that inherits from here they should implement a mutate method.

Parameters:

individual – the chromosome to be mutated.

Returns:

Nothing but raising an error.

pygenalgo.operators.mutation.random_mutator module

class pygenalgo.operators.mutation.random_mutator.RandomMutator(mutate_probability: float = 0.1)[source]

Bases: MutationOperator

Description:

Random mutator, mutates the chromosome by selecting randomly a position and replace the Gene with a new one that has been generated randomly (uniform probability).

mutate(individual: Chromosome) None[source]

Perform the mutation operation by randomly replacing a gene with a new one that has been generated randomly.

Parameters:

individual – (Chromosome).

Returns:

None.

pygenalgo.operators.mutation.shuffle_mutator module

class pygenalgo.operators.mutation.shuffle_mutator.ShuffleMutator(mutate_probability: float = 0.1)[source]

Bases: MutationOperator

Description:

Shuffle mutator mutates the chromosome by shuffling the gene values between two randomly selected gene end-positions.

mutate(individual: Chromosome) None[source]

Perform the mutation operation by shuffling the genes between at two random positions.

Parameters:

individual – (Chromosome).

Returns:

None.

pygenalgo.operators.mutation.swap_mutator module

class pygenalgo.operators.mutation.swap_mutator.SwapMutator(mutate_probability: float = 0.1)[source]

Bases: MutationOperator

Description:

Swap mutator mutates the chromosome by swapping the gene values between two randomly selected gene positions.

mutate(individual: Chromosome) None[source]

Perform the mutation operation by swapping the genes at two random positions.

Parameters:

individual – (Chromosome).

Returns:

None.

pygenalgo.operators.mutation.polynomial_mutator module

class pygenalgo.operators.mutation.polynomial_mutator.PolynomialMutator(mutate_probability: float = 0.1, eta_pm: float = 20.0, lower_val: float | None = None, upper_val: float | None = None)[source]

Bases: MutationOperator

Description:

Polynomial mutator (PM-eta), mutates the chromosome by adjusting the values of genes according to a polynomial distribution. This results in a more controlled and smoother alteration of values.

mutate(individual: Chromosome) None[source]

Perform the mutation operation by adjusting the values of genes according to a polynomial distribution.

Parameters:

individual – (Chromosome).

Returns:

None.

Module contents