You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
else: # In case there are no hidden layers (num_hidden_layers == 0)
84
-
print("WARNING: There are no hidden layers however a value is assigned to the parameter 'hidden_activations'. It will be reset to [].")
85
+
warnings.warn("WARNING: There are no hidden layers however a value is assigned to the parameter 'hidden_activations'. It will be reset to [].")
85
86
hidden_activations= []
86
87
87
88
# If the value passed to the 'hidden_activations' parameter is actually a list, then its elements are checked to make sure the listed name(s) of the activation function(s) are supported.
Copy file name to clipboardExpand all lines: pygad/pygad.py
+90-22Lines changed: 90 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -1531,8 +1531,7 @@ def cal_pop_fitness(self):
1531
1531
elif (self.keep_elitism>0) and (self.last_generation_elitismisnotNone) and (len(self.last_generation_elitism) >0) and (list(sol) inlast_generation_elitism_as_list):
1532
1532
# Return the index of the elitism from the elitism array 'self.last_generation_elitism'.
1533
1533
# This is not its index within the population. It is just its index in the 'self.last_generation_elitism' array.
raiseValueError(f"Size mismatch between the output of on_fitness() {on_fitness_output.shape} and the expected fitness output {self.last_generation_fitness.shape}.")
1755
+
else:
1756
+
raiseValueError(f"The output of on_fitness() is expected to be tuple/list/range/numpy.ndarray but {type(on_fitness_output)} found.")
1751
1757
1752
1758
# Appending the fitness value of the best solution in the current generation to the best_solutions_fitness attribute.
raiseValueError(f"The iterable holding the selected parents indices is expected to have ({self.num_parents_mating}) values but ({len(self.last_generation_parents_indices)}) found.")
raiseValueError(f"The output of on_parents() is expected to be tuple/list/numpy.ndarray of length 2 but {type(on_parents_output)} of length {len(on_parents_output)} found.")
1807
+
1808
+
# Validate the parents.
1809
+
ifon_parents_selected_parentsisNone:
1810
+
raiseValueError("The returned outputs of on_parents() cannot be None but the first output is None.")
1811
+
else:
1812
+
iftype(on_parents_selected_parents) in [tuple, list, numpy.ndarray]:
raiseValueError(f"Size mismatch between the parents retrned by on_parents() {on_parents_selected_parents.shape} and the expected parents shape {self.last_generation_parents.shape}.")
1818
+
else:
1819
+
raiseValueError(f"The output of on_parents() is expected to be tuple/list/numpy.ndarray but the first output type is {type(on_parents_selected_parents)}.")
1820
+
1821
+
# Validate the parents indices.
1822
+
ifon_parents_selected_parents_indicesisNone:
1823
+
raiseValueError("The returned outputs of on_parents() cannot be None but the second output is None.")
1824
+
else:
1825
+
iftype(on_parents_selected_parents_indices) in [tuple, list, numpy.ndarray, range]:
raiseValueError(f"Size mismatch between the parents indices returned by on_parents() {on_parents_selected_parents_indices.shape} and the expected crossover output {self.last_generation_parents_indices.shape}.")
1831
+
else:
1832
+
raiseValueError(f"The output of on_parents() is expected to be tuple/list/range/numpy.ndarray but the second output type is {type(on_parents_selected_parents_indices)}.")
1833
+
1834
+
else:
1835
+
raiseTypeError(f"The output of on_parents() is expected to be tuple/list/numpy.ndarray but {type(on_parents_output)} found.")
1792
1836
1793
1837
# If self.crossover_type=None, then no crossover is applied and thus no offspring will be created in the next generations. The next generation will use the solutions in the current population.
1794
1838
ifself.crossover_typeisNone:
@@ -1832,8 +1876,19 @@ def run(self):
1832
1876
1833
1877
# PyGAD 2.18.2 // The on_crossover() callback function is called even if crossover_type is None.
1834
1878
ifnot (self.on_crossoverisNone):
1835
-
self.on_crossover(
1836
-
self, self.last_generation_offspring_crossover)
1879
+
on_crossover_output=self.on_crossover(self,
1880
+
self.last_generation_offspring_crossover)
1881
+
ifon_crossover_outputisNone:
1882
+
pass
1883
+
else:
1884
+
iftype(on_crossover_output) in [tuple, list, numpy.ndarray]:
raiseValueError(f"Size mismatch between the output of on_crossover() {on_crossover_output.shape} and the expected crossover output {self.last_generation_offspring_crossover.shape}.")
1890
+
else:
1891
+
raiseValueError(f"The output of on_crossover() is expected to be tuple/list/numpy.ndarray but {type(on_crossover_output)} found.")
1837
1892
1838
1893
# If self.mutation_type=None, then no mutation is applied and thus no changes are applied to the offspring created using the crossover operation. The offspring will be used unchanged in the next generation.
1839
1894
ifself.mutation_typeisNone:
@@ -1857,7 +1912,20 @@ def run(self):
1857
1912
1858
1913
# PyGAD 2.18.2 // The on_mutation() callback function is called even if mutation_type is None.
raiseValueError(f"Size mismatch between the output of on_mutation() {on_mutation_output.shape} and the expected mutation output {self.last_generation_offspring_mutation.shape}.")
1927
+
else:
1928
+
raiseValueError(f"The output of on_mutation() is expected to be tuple/list/numpy.ndarray but {type(on_mutation_output)} found.")
1861
1929
1862
1930
# Update the population attribute according to the offspring generated.
0 commit comments