Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ee8fe42

Browse files
Bug fix in applying crossover
Bug fix in applying the crossover operation when the `crossover_probability` parameter is used. Thanks to Eng. Hamada Kassem, RA/TA, Construction Engineering and Management, Faculty of Engineering, Alexandria University, Egypt: https://www.linkedin.com/in/hamadakassem
1 parent b126f69 commit ee8fe42

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

‎pygad.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,9 @@ def single_point_crossover(self, parents, offspring_size):
775775
for k in range(offspring_size[0]):
776776
# The point at which crossover takes place between two parents. Usually, it is at the center.
777777
crossover_point = numpy.random.randint(low=0, high=parents.shape[1], size=1)[0]
778-
779-
if self.crossover_probability != None:
780-
probs = numpy.random.random(size=parents.shape[1])
778+
779+
if self.crossover_probability != None:
780+
probs = numpy.random.random(size=parents.shape[0])
781781
indices = numpy.where(probs <= self.crossover_probability)[0]
782782

783783
# If no parent satisfied the probability, no crossover is applied and a parent is selected.
@@ -824,7 +824,7 @@ def two_points_crossover(self, parents, offspring_size):
824824
crossover_point2 = crossover_point1 + int(parents.shape[1]/2) # The second point must always be greater than the first point.
825825

826826
if self.crossover_probability != None:
827-
probs = numpy.random.random(size=parents.shape[1])
827+
probs = numpy.random.random(size=parents.shape[0])
828828
indices = numpy.where(probs <= self.crossover_probability)[0]
829829

830830
# If no parent satisfied the probability, no crossover is applied and a parent is selected.
@@ -866,7 +866,7 @@ def uniform_crossover(self, parents, offspring_size):
866866

867867
for k in range(offspring_size[0]):
868868
if self.crossover_probability != None:
869-
probs = numpy.random.random(size=parents.shape[1])
869+
probs = numpy.random.random(size=parents.shape[0])
870870
indices = numpy.where(probs <= self.crossover_probability)[0]
871871

872872
# If no parent satisfied the probability, no crossover is applied and a parent is selected.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /