eckity.genetic_operators.mutations.vector_random_mutation

  1from random import random
  2
  3from eckity.genetic_operators.mutations.vector_n_point_mutation import VectorNPointMutation
  4from eckity.genetic_encodings.ga.vector_individual import Vector
  5
  6
  7class FloatVectorUniformOnePointMutation(VectorNPointMutation):
  8    """
  9    Uniform One Point Float Mutation
 10    """
 11    def __init__(self, probability=1.0, arity=1, events=None):
 12        super().__init__(n=1,
 13                         probability=probability,
 14                         arity=arity,
 15                         mut_val_getter=lambda vec, index: vec.get_random_number_in_bounds(index),
 16                         events=events)
 17
 18
 19class FloatVectorUniformNPointMutation(VectorNPointMutation):
 20    """
 21    Uniform N Point Float Mutation
 22    """
 23    def __init__(self, n=1, probability=1.0, arity=1, events=None):
 24        super().__init__(n=n,
 25                         probability=probability,
 26                         arity=arity,
 27                         mut_val_getter=lambda vec, index: vec.get_random_number_in_bounds(index),
 28                         events=events)
 29
 30
 31class FloatVectorGaussOnePointMutation(VectorNPointMutation):
 32    """
 33    Gaussian One Point Float Mutation
 34    """
 35    def __init__(self, probability=1.0, arity=1, mu=0.0, sigma=1.0, events=None, attempts=5):
 36        super().__init__(n=1,
 37                         probability=probability,
 38                         arity=arity,
 39                         mut_val_getter=lambda vec, index: vec.get_random_number_with_gauss(index, mu, sigma),
 40                         events=events,
 41                         attempts=attempts)
 42
 43    def on_fail(self, payload):
 44        """
 45        Handle gauss mutation failure by returning a callable uniform mutation
 46        """
 47        mut = FloatVectorUniformNPointMutation(1, self.probability, self.arity, self.events)
 48        return mut.apply_operator(payload)
 49
 50
 51class FloatVectorGaussNPointMutation(VectorNPointMutation):
 52    """
 53    Gaussian N Point Float Mutation
 54    """
 55    def __init__(self, n=1, probability=1.0, arity=1, mu=0.0, sigma=1.0, events=None, attempts=5):
 56        super().__init__(n=n,
 57                         probability=probability,
 58                         arity=arity,
 59                         mut_val_getter=lambda vec, index: vec.get_random_number_with_gauss(index, mu, sigma),
 60                         events=events,
 61                         attempts=attempts)
 62
 63    def on_fail(self, payload):
 64        """
 65        Handle gauss mutation failure by returning a callable uniform mutation
 66        """
 67        mut = FloatVectorUniformNPointMutation(self.n, self.probability, self.arity, self.events)
 68        return mut.apply_operator(payload)
 69
 70
 71class IntVectorOnePointMutation(VectorNPointMutation):
 72    """
 73    Uniform One Point Integer Mutation
 74    """
 75    def __init__(self, probability=1.0, arity=1, events=None):
 76        super().__init__(probability=probability,
 77                         arity=arity,
 78                         mut_val_getter=lambda individual, index: individual.get_random_number_in_bounds(index),
 79                         events=events,
 80                         n=1)
 81
 82
 83class IntVectorNPointMutation(VectorNPointMutation):
 84    """
 85    Uniform N Point Integer Mutation
 86    """
 87    def __init__(self, probability=1.0, arity=1, events=None, n=1):
 88        super().__init__(probability=probability,
 89                         arity=arity,
 90                         mut_val_getter=lambda individual, index: individual.get_random_number_in_bounds(index),
 91                         events=events,
 92                         n=n)
 93
 94
 95class BitStringVectorFlipMutation(VectorNPointMutation):
 96    """
 97    One Point Bit-Flip Mutation
 98    """
 99    def __init__(self, probability=1.0, arity=1, events=None):
100        super().__init__(probability=probability,
101                         arity=arity,
102                         mut_val_getter=lambda individual, index: individual.bit_flip(index),
103                         n=1,
104                         events=events)
105
106
107class BitStringVectorNFlipMutation(VectorNPointMutation):
108    """
109    N Point Bit-Flip Mutation
110    """
111    def __init__(self, probability=1.0, arity=1, events=None, probability_for_each=0.2, n=1):
112        self.probability_for_each = probability_for_each
113        super().__init__(probability=probability,
114                         arity=arity,
115                         mut_val_getter=lambda individual, index: individual.bit_flip(
116                             index) if random() <= self.probability_for_each else individual.cell_value(index),
117                         events=events,
118                         n=n)
class FloatVectorUniformOnePointMutation(eckity.genetic_operators.mutations.vector_n_point_mutation.VectorNPointMutation):
 8class FloatVectorUniformOnePointMutation(VectorNPointMutation):
 9    """
10    Uniform One Point Float Mutation
11    """
12    def __init__(self, probability=1.0, arity=1, events=None):
13        super().__init__(n=1,
14                         probability=probability,
15                         arity=arity,
16                         mut_val_getter=lambda vec, index: vec.get_random_number_in_bounds(index),
17                         events=events)

Uniform One Point Float Mutation

FloatVectorUniformOnePointMutation(probability=1.0, arity=1, events=None)
12    def __init__(self, probability=1.0, arity=1, events=None):
13        super().__init__(n=1,
14                         probability=probability,
15                         arity=arity,
16                         mut_val_getter=lambda vec, index: vec.get_random_number_in_bounds(index),
17                         events=events)
class FloatVectorUniformNPointMutation(eckity.genetic_operators.mutations.vector_n_point_mutation.VectorNPointMutation):
20class FloatVectorUniformNPointMutation(VectorNPointMutation):
21    """
22    Uniform N Point Float Mutation
23    """
24    def __init__(self, n=1, probability=1.0, arity=1, events=None):
25        super().__init__(n=n,
26                         probability=probability,
27                         arity=arity,
28                         mut_val_getter=lambda vec, index: vec.get_random_number_in_bounds(index),
29                         events=events)

Uniform N Point Float Mutation

FloatVectorUniformNPointMutation(n=1, probability=1.0, arity=1, events=None)
24    def __init__(self, n=1, probability=1.0, arity=1, events=None):
25        super().__init__(n=n,
26                         probability=probability,
27                         arity=arity,
28                         mut_val_getter=lambda vec, index: vec.get_random_number_in_bounds(index),
29                         events=events)
class FloatVectorGaussOnePointMutation(eckity.genetic_operators.mutations.vector_n_point_mutation.VectorNPointMutation):
32class FloatVectorGaussOnePointMutation(VectorNPointMutation):
33    """
34    Gaussian One Point Float Mutation
35    """
36    def __init__(self, probability=1.0, arity=1, mu=0.0, sigma=1.0, events=None, attempts=5):
37        super().__init__(n=1,
38                         probability=probability,
39                         arity=arity,
40                         mut_val_getter=lambda vec, index: vec.get_random_number_with_gauss(index, mu, sigma),
41                         events=events,
42                         attempts=attempts)
43
44    def on_fail(self, payload):
45        """
46        Handle gauss mutation failure by returning a callable uniform mutation
47        """
48        mut = FloatVectorUniformNPointMutation(1, self.probability, self.arity, self.events)
49        return mut.apply_operator(payload)

Gaussian One Point Float Mutation

FloatVectorGaussOnePointMutation(probability=1.0, arity=1, mu=0.0, sigma=1.0, events=None, attempts=5)
36    def __init__(self, probability=1.0, arity=1, mu=0.0, sigma=1.0, events=None, attempts=5):
37        super().__init__(n=1,
38                         probability=probability,
39                         arity=arity,
40                         mut_val_getter=lambda vec, index: vec.get_random_number_with_gauss(index, mu, sigma),
41                         events=events,
42                         attempts=attempts)
def on_fail(self, payload):
44    def on_fail(self, payload):
45        """
46        Handle gauss mutation failure by returning a callable uniform mutation
47        """
48        mut = FloatVectorUniformNPointMutation(1, self.probability, self.arity, self.events)
49        return mut.apply_operator(payload)

Handle gauss mutation failure by returning a callable uniform mutation

class FloatVectorGaussNPointMutation(eckity.genetic_operators.mutations.vector_n_point_mutation.VectorNPointMutation):
52class FloatVectorGaussNPointMutation(VectorNPointMutation):
53    """
54    Gaussian N Point Float Mutation
55    """
56    def __init__(self, n=1, probability=1.0, arity=1, mu=0.0, sigma=1.0, events=None, attempts=5):
57        super().__init__(n=n,
58                         probability=probability,
59                         arity=arity,
60                         mut_val_getter=lambda vec, index: vec.get_random_number_with_gauss(index, mu, sigma),
61                         events=events,
62                         attempts=attempts)
63
64    def on_fail(self, payload):
65        """
66        Handle gauss mutation failure by returning a callable uniform mutation
67        """
68        mut = FloatVectorUniformNPointMutation(self.n, self.probability, self.arity, self.events)
69        return mut.apply_operator(payload)

Gaussian N Point Float Mutation

FloatVectorGaussNPointMutation( n=1, probability=1.0, arity=1, mu=0.0, sigma=1.0, events=None, attempts=5)
56    def __init__(self, n=1, probability=1.0, arity=1, mu=0.0, sigma=1.0, events=None, attempts=5):
57        super().__init__(n=n,
58                         probability=probability,
59                         arity=arity,
60                         mut_val_getter=lambda vec, index: vec.get_random_number_with_gauss(index, mu, sigma),
61                         events=events,
62                         attempts=attempts)
def on_fail(self, payload):
64    def on_fail(self, payload):
65        """
66        Handle gauss mutation failure by returning a callable uniform mutation
67        """
68        mut = FloatVectorUniformNPointMutation(self.n, self.probability, self.arity, self.events)
69        return mut.apply_operator(payload)

Handle gauss mutation failure by returning a callable uniform mutation

72class IntVectorOnePointMutation(VectorNPointMutation):
73    """
74    Uniform One Point Integer Mutation
75    """
76    def __init__(self, probability=1.0, arity=1, events=None):
77        super().__init__(probability=probability,
78                         arity=arity,
79                         mut_val_getter=lambda individual, index: individual.get_random_number_in_bounds(index),
80                         events=events,
81                         n=1)

Uniform One Point Integer Mutation

IntVectorOnePointMutation(probability=1.0, arity=1, events=None)
76    def __init__(self, probability=1.0, arity=1, events=None):
77        super().__init__(probability=probability,
78                         arity=arity,
79                         mut_val_getter=lambda individual, index: individual.get_random_number_in_bounds(index),
80                         events=events,
81                         n=1)
84class IntVectorNPointMutation(VectorNPointMutation):
85    """
86    Uniform N Point Integer Mutation
87    """
88    def __init__(self, probability=1.0, arity=1, events=None, n=1):
89        super().__init__(probability=probability,
90                         arity=arity,
91                         mut_val_getter=lambda individual, index: individual.get_random_number_in_bounds(index),
92                         events=events,
93                         n=n)

Uniform N Point Integer Mutation

IntVectorNPointMutation(probability=1.0, arity=1, events=None, n=1)
88    def __init__(self, probability=1.0, arity=1, events=None, n=1):
89        super().__init__(probability=probability,
90                         arity=arity,
91                         mut_val_getter=lambda individual, index: individual.get_random_number_in_bounds(index),
92                         events=events,
93                         n=n)
 96class BitStringVectorFlipMutation(VectorNPointMutation):
 97    """
 98    One Point Bit-Flip Mutation
 99    """
100    def __init__(self, probability=1.0, arity=1, events=None):
101        super().__init__(probability=probability,
102                         arity=arity,
103                         mut_val_getter=lambda individual, index: individual.bit_flip(index),
104                         n=1,
105                         events=events)

One Point Bit-Flip Mutation

BitStringVectorFlipMutation(probability=1.0, arity=1, events=None)
100    def __init__(self, probability=1.0, arity=1, events=None):
101        super().__init__(probability=probability,
102                         arity=arity,
103                         mut_val_getter=lambda individual, index: individual.bit_flip(index),
104                         n=1,
105                         events=events)
108class BitStringVectorNFlipMutation(VectorNPointMutation):
109    """
110    N Point Bit-Flip Mutation
111    """
112    def __init__(self, probability=1.0, arity=1, events=None, probability_for_each=0.2, n=1):
113        self.probability_for_each = probability_for_each
114        super().__init__(probability=probability,
115                         arity=arity,
116                         mut_val_getter=lambda individual, index: individual.bit_flip(
117                             index) if random() <= self.probability_for_each else individual.cell_value(index),
118                         events=events,
119                         n=n)

N Point Bit-Flip Mutation

BitStringVectorNFlipMutation(probability=1.0, arity=1, events=None, probability_for_each=0.2, n=1)
112    def __init__(self, probability=1.0, arity=1, events=None, probability_for_each=0.2, n=1):
113        self.probability_for_each = probability_for_each
114        super().__init__(probability=probability,
115                         arity=arity,
116                         mut_val_getter=lambda individual, index: individual.bit_flip(
117                             index) if random() <= self.probability_for_each else individual.cell_value(index),
118                         events=events,
119                         n=n)
probability_for_each