algogen module

This module contains the whole implementation of Felon Finder’s genetic algorithm. This is truly part of the heart of Felon Finder.

algogen.gaussian_noise_1(parent, mean, std, n)[source]

Applies Gaussian noise to randomly selected points on both parent arrays.

Parameters:
  • parent (np.ndarray) – Array representing the parent.

  • mean (float) – Mean of the Gaussian noise distribution.

  • std (float) – Standard deviation of the Gaussian noise distribution.

  • n (int) – Number of points to be randomly selected on each parent array.

Returns:

Array representing the first child.

Return type:

np.ndarray

algogen.mean_parents(parent1, parent2)[source]

Compute the mean of the values of two parent arrays.

Args:

parent1 (np.ndarray): The first parent array. parent2 (np.ndarray): The second parent array.

Returns:
np.ndarray: An array representing the child with values equal to the mean of the values

of the corresponding parents.

algogen.mean_parents1(*parents)[source]

Compute the mean of the values of the parents arrays.

Parameters:

*parents – Variable number of parent arrays.

Returns:

An array representing the child with values equal to the mean of the values

of the corresponding parents.

Return type:

np.ndarray

algogen.multiple_selections(*parents)[source]

Introduces genetic operations to multiple selected parents for decoding.

Applies several genetic operations, including crossover and mutation, to pairs of selected parents. From each pair of parents, four outputs are generated using different genetic operations. Then, three outputs are randomly selected from all generated outputs, and the mean of all parents is calculated. The selected outputs and the mean of parents are stacked together for decoding.

Parameters:

*parents – Variable number of parent arrays.

Returns:

A stack of selected output tensors and the mean of all parent tensors.

Return type:

tf.Tensor

Note

This function assumes that all ‘parents’ are TensorFlow tensors.

algogen.one_point_crossover(parent1, parent2)[source]

Applies one-point crossover to two parent arrays.

A single crossover point is randomly selected on both parent arrays. Data beyond this crossover point is swapped between the parents to create two children.

Parameters:
  • parent1 (array-like) – The first parent array.

  • parent2 (array-like) – The second parent array.

Returns:

An array representing the first child.

Return type:

numpy.ndarray

algogen.one_selection(parent, std, m)[source]

Introduces Gaussian noise to the selected parent vector for decoding.

Args:

parent (np.ndarray): The encoded vector of the selected parent. std (float): Standard deviation of the Gaussian noise. m (float): Mean of the Gaussian noise.

Returns:

np.ndarray: A stack of 4 output vectors, each containing Gaussian noise introduced for decoding.

Note:

algogen.several_points_crossover(parent1, parent2, number_points)[source]

Applies several points crossover to two parent arrays.

Multiple crossover points are randomly selected on both parent arrays. Data beyond each crossover point is swapped between the parents to create two children.

Parameters:
  • parent1 (array-like) – The first parent array.

  • parent2 (array-like) – The second parent array.

  • number_points (int) – The number of crossover points.

Returns:

An array representing the first child.

Return type:

numpy.ndarray

algogen.several_points_crossover_v2(parent1, parent2)[source]

Applies several points crossover to two parent arrays.

For each index in the parent arrays, a random choice is made between the corresponding elements of the parents based on a randomly generated sequence of 1s and 2s.

Parameters:
  • parent1 (tf.Tensor) – The first parent array.

  • parent2 (tf.Tensor) – The second parent array.

Returns:

A list representing the child array generated from crossover.

Return type:

list

algogen.two_selections(parent1, parent2)[source]

Introduces genetic operations to two selected parents for decoding.

Parameters:
  • parent1 (tf.Tensor) – The first parent array.

  • parent2 (tf.Tensor) – The second parent array.

Returns:

A stack of 4 output tensors, each representing a genetic operation applied to the parents.

Return type:

tf.Tensor