evolvepy.generator.mutation package
Submodules
evolvepy.generator.mutation.binary_mutation module
- evolvepy.generator.mutation.binary_mutation.bit_mutation(chromosome: int | float | complex | str | bytes | generic | Sequence[int | float | complex | str | bytes | generic] | Sequence[Sequence[Any]] | _SupportsArray, existence_rate: float, gene_rate: float)[source]
- It takes a number n of genes and randomicaly change n gene bits in a chromosome.
If gene_rate = 1 this mutaions behaves like a flipbit mutation, else it is a bitstring mutaion.
- Parameters:
chromosome (np.ArrayLike) – list of chromosomes of an individual
existentce_rate (float) – maximum number of genes modified
gene_rate (float) – probability of gene mutation
- Returns:
new mutated individual
- Return type:
new_cromosome (np.ArrayLike)
evolvepy.generator.mutation.mutation module
- class evolvepy.generator.mutation.mutation.BinaryMutationLayer(mutation_function: Callable, existence_rate: float, gene_rate: float, name: str | None = None, chromosome_names: List[str] | str | None = None)[source]
Bases:
ChromosomeOperator
Layer destinated to apply the Binary chromosome operations.
- __init__(mutation_function: Callable, existence_rate: float, gene_rate: float, name: str | None = None, chromosome_names: List[str] | str | None = None)[source]
Generic caller to a mutation function passed as parameters.
- Parameters:
mutation_function (class Callable) – Define the function which will be used
existence_rate (float) – Probability of first mutation
gene_rate (float) – Probability of another gene mutation
name (string) – Name for the layer
chromosome_names (Union[str, List[str], None]) – Array of chromosomes names (optional)
- call_chromosomes(chromosomes: ndarray, fitness: ndarray, context: Context, name: str | None) ndarray [source]
Apply the mutation on the chromosomes
- Parameters:
chromosomes (np.ArrayLike) – Array of chromosomes
fitness (np.array) – Probability of first mutation
context (class Context) – Probability of another gene mutation
name (string) – Define the function which will be
- Returns:
mutation function
- Return type:
BinaryMutationLayer.mutate
- static mutate(chromosomes: ndarray, mutation_function: Callable, existence_rate: float, gene_rate: float)[source]
Generic caller to a mutation function passed as parameters.
- Parameters:
chromosomes (np.ArrayLike) – array of chromosomes
existence_rate (float) – probability of first mutation
gene_rate (float) – probability of another gene mutation
mutation_function (class Callable) – Define the function which will be used
- Returns:
return a new mutated population
- Return type:
result (np.ArrayLike)
- class evolvepy.generator.mutation.mutation.NumericMutationLayer(mutation_function: Callable, existence_rate: float, gene_rate: float, mutation_range: Tuple[float, float], name: str | None = None, chromosome_names: List[str] | str | None = None)[source]
Bases:
ChromosomeOperator
Layer destinated to apply the Numeric chromosome operations.
- __init__(mutation_function: Callable, existence_rate: float, gene_rate: float, mutation_range: Tuple[float, float], name: str | None = None, chromosome_names: List[str] | str | None = None)[source]
Generic caller to a mutation function passed as parameters.
- Parameters:
mutation_function (class Callable) – Define the function which will be used
existence_rate (float) – Probability of first mutation
gene_rate (float) – Probability of another gene mutation
name (string) – Name for the layer
chromosome_names (Union[str, List[str], None]) – Array of chromosomes names (optional)
- call_chromosomes(chromosomes: ndarray, fitness: ndarray, context: Context, name: str | None) ndarray [source]
- static mutate(chromosomes: ndarray, mutation_function: Callable, existence_rate: float, gene_rate: float, mutation_range: Tuple[float, float])[source]
Generic caller to a mutation function passed as parameters.
- Parameters:
chromosomes (np.ArrayLike) – Array of chromosomes
existence_rate (float) – Probability of first mutation
gene_rate (float) – Probability of another gene mutation
mutation_function (class Callable) – Define the function which will be used
- Returns:
return a new mutated population
- Return type:
result (np.ArrayLike)
evolvepy.generator.mutation.numeric_mutation module
- evolvepy.generator.mutation.numeric_mutation.mul_mutation(chromosome: int | float | complex | str | bytes | generic | Sequence[int | float | complex | str | bytes | generic] | Sequence[Sequence[Any]] | _SupportsArray, existence_rate: float, gene_rate: float, mutation_range: Tuple[float, float])[source]
It takes a chromosome and multiply a random value between the mutation range to its gene, then repeats the process with the given probability.
- Parameters:
chromosome (np.ArrayLike) – array of chromosomes
existence_rate (float) – probability of first mutation
gene_rate (float) – probability of another gene mutation
mutation_range (Tuple[float, float]) –
- Returns:
new mutated individual
- Return type:
new_cromosome (np.ArrayLike)
- evolvepy.generator.mutation.numeric_mutation.sum_mutation(chromosome: int | float | complex | str | bytes | generic | Sequence[int | float | complex | str | bytes | generic] | Sequence[Sequence[Any]] | _SupportsArray, existence_rate: float, gene_rate: float, mutation_range: Tuple[float, float])[source]
It takes a chromosome and add a random value between the mutation range to its gene, then repeats the process with the given probability.
- Parameters:
chromosome (np.ArrayLike) – array of chromosomes
existence_rate (float) – probability of first mutation
gene_rate (float) – probability of another gene mutation
mutation_range (Tuple[float, float]) –
- Returns:
new mutated individual
- Return type:
new_cromosome (np.ArrayLike)
Module contents
EvolvePy’s mutations. Objects that can be called upon during evolution to mutate the individual chromosome.