slim_gsgp.algorithms.SLIM_GSGP.operators

slim_gsgp.algorithms.SLIM_GSGP.operators.mutators

Mutation Functions for SLIM GSGP.

slim_gsgp.algorithms.SLIM_GSGP.operators.mutators.deflate_mutation(individual, reconstruct)[source]

Perform deflate mutation on a given Individual by removing a random ‘block’.

Parameters:
  • individual (Individual) – The Individual to be mutated.

  • reconstruct (bool) – Whether to store the Individual’s structure after mutation.

Returns:

The mutated individual

Return type:

Individual

slim_gsgp.algorithms.SLIM_GSGP.operators.mutators.inflate_mutation(FUNCTIONS, TERMINALS, CONSTANTS, two_trees=True, operator='sum', single_tree_sigmoid=False, sig=False)[source]

Generate an inflate mutation function.

Parameters:
  • FUNCTIONS (dict) – The dictionary of functions used in the mutation.

  • TERMINALS (dict) – The dictionary of terminals used in the mutation.

  • CONSTANTS (dict) – The dictionary of constants used in the mutation.

  • two_trees (bool) – Boolean indicating if two trees should be used.

  • operator (str) – The operator to be used in the mutation.

  • single_tree_sigmoid (bool) – Boolean indicating if sigmoid should be applied to a single tree.

  • sig (bool) – Boolean indicating if sigmoid should be applied.

Returns:

An inflate mutation function (inflate).

param individual:

The tree Individual to mutate.

type individual:

Individual

param ms:

Mutation step.

type ms:

float

param X:

Input data for calculating semantics.

type X:

torch.Tensor

param max_depth:

Maximum depth for generated trees (default: 8).

type max_depth:

int, optional

param p_c:

Probability of choosing constants (default: 0.1).

type p_c:

float, optional

param X_test:

Test data for calculating test semantics (default: None).

type X_test:

torch.Tensor, optional

param grow_probability:

Probability of growing trees during mutation (default: 1).

type grow_probability:

float, optional

param reconstruct:

Whether to reconstruct the Individual’s collection after mutation (default: True).

type reconstruct:

bool, optional

returns:

The mutated tree Individual.

rtype:

Individual

Return type:

Callable

Notes

The returned function performs inflate mutation on Individuals, using either one or two randomly generated trees and applying either delta mutation or sigmoid mutation based on the parameters.

slim_gsgp.algorithms.SLIM_GSGP.operators.mutators.one_tree_delta(operator='sum', sig=False)[source]

Generate a function for the one-tree delta mutation.

Parameters:
  • operator (str) – The operator to be used in the mutation (“sum” or other).

  • sig (bool) – Boolean indicating if sigmoid should be applied.

Returns:

A mutation function (ot_delta) for one-tree mutation.

param tr1:

The tree Individual.

type tr1:

Individual

param ms:

Mutation step.

type ms:

float

param testing:

Flag to indicate whether to use test or train semantics.

type testing:

bool

returns:

The mutated semantics.

rtype:

torch.Tensor

Return type:

Callable

Notes

The returned function (‘ot_delta_{operator}_{sig}’) takes as input one individual, the mutation step, a boolean representing whether to use the train or test semantics, and returns the mutated semantics.

slim_gsgp.algorithms.SLIM_GSGP.operators.mutators.two_trees_delta(operator='sum')[source]

Generate a function for the two-tree delta mutation.

Parameters:

operator (str) – The operator to be used in the mutation (“sum” or other).

Returns:

A mutation function (tt_delta) for two Individuals that returns the mutated semantics.

param tr1:

The first tree individual.

type tr1:

Individual

param tr2:

The second tree individual.

type tr2:

Individual

param ms:

Mutation step.

type ms:

float

param testing:

Flag to indicate whether to use test or train Individual semantics.

type testing:

bool

returns:

The mutated semantics.

rtype:

torch.Tensor

Return type:

Callable

Notes

The returned function (‘tt_delta_{operator}’) takes as input two individuals, the mutation step, a boolean representing whether to use the train or test semantics, and returns the calculated semantics of the new individual.