Movatterモバイル変換


[0]ホーム

URL:


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

Commit788423d

Browse files
authored
Bug fix when gene_type is nested.
Fix some bugs when the gene_type parameter is nested. Thanks to Rainer for opening a discussion (ahmedfgad#43) to report this bug:ahmedfgad#43 (reply in thread)
1 parentb3bd7e9 commit788423d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎pygad.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,12 +1578,16 @@ def mutation_randomly(self, offspring):
15781578
random_value=self.gene_type(random_value)
15791579
else:
15801580
random_value=self.gene_type[gene_idx](random_value)
1581-
# If the mutation_by_replacement attribute is False, then the random value is added to the gene value.
1581+
iftype(random_value)isnumpy.ndarray:
1582+
random_value=random_value[0]
1583+
# If the mutation_by_replacement attribute is False, then the random value is added to the gene value.
15821584
else:
15831585
ifself.gene_type_single==True:
15841586
random_value=self.gene_type(offspring[offspring_idx,gene_idx]+random_value)
15851587
else:
15861588
random_value=self.gene_type[gene_idx](offspring[offspring_idx,gene_idx]+random_value)
1589+
iftype(random_value)isnumpy.ndarray:
1590+
random_value=random_value[0]
15871591

15881592
offspring[offspring_idx,gene_idx]=random_value
15891593

@@ -1621,12 +1625,16 @@ def mutation_probs_randomly(self, offspring):
16211625
random_value=self.gene_type(random_value)
16221626
else:
16231627
random_value=self.gene_type[gene_idx](random_value)
1628+
iftype(random_value)isnumpy.ndarray:
1629+
random_value=random_value[0]
16241630
# If the mutation_by_replacement attribute is False, then the random value is added to the gene value.
16251631
else:
16261632
ifself.gene_type_single==True:
16271633
random_value=self.gene_type(offspring[offspring_idx,gene_idx]+random_value)
16281634
else:
16291635
random_value=self.gene_type[gene_idx](offspring[offspring_idx,gene_idx]+random_value)
1636+
iftype(random_value)isnumpy.ndarray:
1637+
random_value=random_value[0]
16301638

16311639
offspring[offspring_idx,gene_idx]=random_value
16321640

@@ -1872,12 +1880,16 @@ def adaptive_mutation_randomly(self, offspring):
18721880
random_value=self.gene_type(random_value)
18731881
else:
18741882
random_value=self.gene_type[gene_idx](random_value)
1883+
iftype(random_value)isnumpy.ndarray:
1884+
random_value=random_value[0]
18751885
# If the mutation_by_replacement attribute is False, then the random value is added to the gene value.
18761886
else:
18771887
ifself.gene_type_single==True:
18781888
random_value=self.gene_type(offspring[offspring_idx,gene_idx]+random_value)
18791889
else:
18801890
random_value=self.gene_type[gene_idx](offspring[offspring_idx,gene_idx]+random_value)
1891+
iftype(random_value)isnumpy.ndarray:
1892+
random_value=random_value[0]
18811893

18821894
offspring[offspring_idx,gene_idx]=random_value
18831895

@@ -2011,12 +2023,16 @@ def adaptive_mutation_probs_randomly(self, offspring):
20112023
random_value=self.gene_type(random_value)
20122024
else:
20132025
random_value=self.gene_type[gene_idx](random_value)
2026+
iftype(random_value)isnumpy.ndarray:
2027+
random_value=random_value[0]
20142028
# If the mutation_by_replacement attribute is False, then the random value is added to the gene value.
20152029
else:
20162030
ifself.gene_type_single==True:
20172031
random_value=self.gene_type(offspring[offspring_idx,gene_idx]+random_value)
20182032
else:
20192033
random_value=self.gene_type[gene_idx](offspring[offspring_idx,gene_idx]+random_value)
2034+
iftype(random_value)isnumpy.ndarray:
2035+
random_value=random_value[0]
20202036

20212037
offspring[offspring_idx,gene_idx]=random_value
20222038

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp