eckity.genetic_operators.mutations.erc_mutation

 1from random import choice, gauss
 2
 3from eckity.event_based_operator import Operator
 4from eckity.genetic_operators.genetic_operator import GeneticOperator
 5
 6
 7class ERCMutation(GeneticOperator):
 8    def __init__(self, probability=1, arity=1, events=None):
 9        super().__init__(probability=probability, arity=arity, events=events)
10
11    def apply(self, individuals):
12        """
13        Perform ephemeral random constant (ERC) mutation: select an ERC node at random
14        and add Gaussian noise to it.
15
16        Returns
17        -------
18        None.
19        """
20        for j in range(len(individuals)):
21            erc_indexes = [i for i, node in enumerate(individuals[j].tree) if
22                           isinstance(node, (int, float)) and node not in individuals[j].terminal_set]
23            if len(erc_indexes) > 0:
24                m_point = choice(erc_indexes)
25                individuals[j].tree[m_point] = round(individuals[j].tree[m_point] + gauss(mu=0, sigma=1), 4)
26        self.applied_individuals = individuals
27        return individuals
 8class ERCMutation(GeneticOperator):
 9    def __init__(self, probability=1, arity=1, events=None):
10        super().__init__(probability=probability, arity=arity, events=events)
11
12    def apply(self, individuals):
13        """
14        Perform ephemeral random constant (ERC) mutation: select an ERC node at random
15        and add Gaussian noise to it.
16
17        Returns
18        -------
19        None.
20        """
21        for j in range(len(individuals)):
22            erc_indexes = [i for i, node in enumerate(individuals[j].tree) if
23                           isinstance(node, (int, float)) and node not in individuals[j].terminal_set]
24            if len(erc_indexes) > 0:
25                m_point = choice(erc_indexes)
26                individuals[j].tree[m_point] = round(individuals[j].tree[m_point] + gauss(mu=0, sigma=1), 4)
27        self.applied_individuals = individuals
28        return individuals
ERCMutation(probability=1, arity=1, events=None)
 9    def __init__(self, probability=1, arity=1, events=None):
10        super().__init__(probability=probability, arity=arity, events=events)
def apply(self, individuals):
12    def apply(self, individuals):
13        """
14        Perform ephemeral random constant (ERC) mutation: select an ERC node at random
15        and add Gaussian noise to it.
16
17        Returns
18        -------
19        None.
20        """
21        for j in range(len(individuals)):
22            erc_indexes = [i for i, node in enumerate(individuals[j].tree) if
23                           isinstance(node, (int, float)) and node not in individuals[j].terminal_set]
24            if len(erc_indexes) > 0:
25                m_point = choice(erc_indexes)
26                individuals[j].tree[m_point] = round(individuals[j].tree[m_point] + gauss(mu=0, sigma=1), 4)
27        self.applied_individuals = individuals
28        return individuals

Perform ephemeral random constant (ERC) mutation: select an ERC node at random and add Gaussian noise to it.

Returns
  • None.