From ea6b1962ba53e0e5ac4cc406561947722468fe9d Mon Sep 17 00:00:00 2001 From: domnenko_b Date: Thu, 15 Nov 2018 16:21:25 +0200 Subject: [PATCH] Update ga.py fixed crossover mask generation, moved crossover rate to constructor params --- pyclustering/cluster/ga.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyclustering/cluster/ga.py b/pyclustering/cluster/ga.py index e6ec6a26..3492591d 100755 --- a/pyclustering/cluster/ga.py +++ b/pyclustering/cluster/ga.py @@ -343,7 +343,7 @@ class genetic_algorithm: """ def __init__(self, data, count_clusters, chromosome_count, population_count, count_mutation_gens=2, - coeff_mutation_count=0.25, select_coeff=1.0, observer=ga_observer()): + coeff_mutation_count=0.25, select_coeff=1.0, crossover_rate=1.0, observer=ga_observer()): """! @brief Initialize genetic clustering algorithm for cluster analysis. @@ -383,7 +383,7 @@ def __init__(self, data, count_clusters, chromosome_count, population_count, cou self._count_mutation_gens = count_mutation_gens # Crossover rate - self._crossover_rate = 1.0 + self._crossover_rate = crossover_rate # Count of chromosome for mutation (range [0, 1]) self._coeff_mutation_count = coeff_mutation_count @@ -591,7 +591,7 @@ def _get_crossover_mask(mask_length): mask = np.zeros(mask_length) # Set a half of array to 1 - mask[:int(int(mask_length) / 6)] = 1 + mask[:int(int(mask_length) / 2)] = 1 # Random shuffle np.random.shuffle(mask)