Skip to content

Commit

Permalink
Factor out number of mutations calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
diogomatoschaves committed Jun 22, 2020
1 parent fd66a8e commit 1db50bd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions geneal/genetic_algorithms/genetic_algorithm_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def __init__(
self.prob_intervals = self.get_selection_probabilities()

self.n_matings = math.floor((self.pop_size - self.pop_keep) / 2)
self.n_mutations = math.ceil(
(self.pop_size - 1) * self.n_genes * self.mutation_rate
)
self.n_mutations = self.get_number_mutations()

self.generations_ = 0
self.best_fitness_ = 0
Expand Down Expand Up @@ -296,6 +294,11 @@ def get_selection_probabilities(self):
elif self.selection_strategy == "random":
return np.linspace(0, 1, self.pop_keep + 1)

def get_number_mutations(self):
return math.ceil(
(self.pop_size - 1) * self.n_genes * self.mutation_rate
)

@staticmethod
def sort_by_fitness(fitness, population):
"""
Expand Down

0 comments on commit 1db50bd

Please sign in to comment.