Skip to content

Commit ea6b196

Browse files
committed
Update ga.py
fixed crossover mask generation, moved crossover rate to constructor params
1 parent 1f2a6a2 commit ea6b196

File tree

1 file changed

+3
-3
lines changed
  • pyclustering/cluster

1 file changed

+3
-3
lines changed

pyclustering/cluster/ga.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class genetic_algorithm:
343343
"""
344344

345345
def __init__(self, data, count_clusters, chromosome_count, population_count, count_mutation_gens=2,
346-
coeff_mutation_count=0.25, select_coeff=1.0, observer=ga_observer()):
346+
coeff_mutation_count=0.25, select_coeff=1.0, crossover_rate=1.0, observer=ga_observer()):
347347
"""!
348348
@brief Initialize genetic clustering algorithm for cluster analysis.
349349
@@ -383,7 +383,7 @@ def __init__(self, data, count_clusters, chromosome_count, population_count, cou
383383
self._count_mutation_gens = count_mutation_gens
384384

385385
# Crossover rate
386-
self._crossover_rate = 1.0
386+
self._crossover_rate = crossover_rate
387387

388388
# Count of chromosome for mutation (range [0, 1])
389389
self._coeff_mutation_count = coeff_mutation_count
@@ -591,7 +591,7 @@ def _get_crossover_mask(mask_length):
591591
mask = np.zeros(mask_length)
592592

593593
# Set a half of array to 1
594-
mask[:int(int(mask_length) / 6)] = 1
594+
mask[:int(int(mask_length) / 2)] = 1
595595

596596
# Random shuffle
597597
np.random.shuffle(mask)

0 commit comments

Comments
 (0)