From 25f19c346c3056f7d59637b4f1e0ba3044e988e8 Mon Sep 17 00:00:00 2001 From: Mohsinmahmood Date: Wed, 12 Jun 2024 03:46:42 +0500 Subject: [PATCH 1/3] Fix incorrect parameters in np.argmax() for Genetic Algorithm in tsp.py Issue #1256: Replace np.argmax with argmax_random_ties to correctly reference method and avoid TypeError. --- gui/tsp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/tsp.py b/gui/tsp.py index 590fff354..bbe060499 100644 --- a/gui/tsp.py +++ b/gui/tsp.py @@ -260,7 +260,7 @@ def fitness_fn(state): while True: population = [mutate(recombine(*select(2, population, fitness_fn)), self.mutation_rate.get()) for _ in range(len(population))] - current_best = np.argmax(population, key=fitness_fn) + current_best = utils.argmax_random_ties(population, key=fitness_fn) if fitness_fn(current_best) > fitness_fn(all_time_best): all_time_best = current_best self.cost.set("Cost = " + str('%0.3f' % (-1 * problem.value(all_time_best)))) From fcc85b8b1f2628aba227b588e263436e761297e9 Mon Sep 17 00:00:00 2001 From: Mohsinmahmood Date: Wed, 12 Jun 2024 03:55:47 +0500 Subject: [PATCH 2/3] Fix ValueError in test_svc for test_learning.py and test_learning4e.py Issue #1272: Updated optimizer parameter from lr to learning_rate in deep_learning4e.py to resolve Rank(A) < p error. --- deep_learning4e.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deep_learning4e.py b/deep_learning4e.py index 9f5b0a8f7..7250751d3 100644 --- a/deep_learning4e.py +++ b/deep_learning4e.py @@ -575,7 +575,7 @@ def AutoencoderLearner(inputs, encoding_size, epochs=200, verbose=False): model.add(Dense(input_size, activation='relu', kernel_initializer='random_uniform', bias_initializer='ones')) # update model with sgd - sgd = optimizers.SGD(lr=0.01) + sgd = optimizers.SGD(learning_rate=0.01) model.compile(loss='mean_squared_error', optimizer=sgd, metrics=['accuracy']) # train the model From 03d4e1aa77d09f8213803e40c922e7976ef4c776 Mon Sep 17 00:00:00 2001 From: Donato Meoli Date: Fri, 26 Jun 2026 03:12:42 +0200 Subject: [PATCH 3/3] Use utils.argmax_random_tie for best-individual selection in tsp.py np.argmax does not accept a key argument (TypeError), and np.argmax_random_tie does not exist (argmax_random_tie lives in utils). Use utils.argmax_random_tie in both the genetic algorithm and hill climbing loops. --- gui/tsp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/tsp.py b/gui/tsp.py index bbe060499..05b94a343 100644 --- a/gui/tsp.py +++ b/gui/tsp.py @@ -260,7 +260,7 @@ def fitness_fn(state): while True: population = [mutate(recombine(*select(2, population, fitness_fn)), self.mutation_rate.get()) for _ in range(len(population))] - current_best = utils.argmax_random_ties(population, key=fitness_fn) + current_best = utils.argmax_random_tie(population, key=fitness_fn) if fitness_fn(current_best) > fitness_fn(all_time_best): all_time_best = current_best self.cost.set("Cost = " + str('%0.3f' % (-1 * problem.value(all_time_best)))) @@ -294,7 +294,7 @@ def find_neighbors(state, number_of_neighbors=100): current = Node(problem.initial) while True: neighbors = find_neighbors(current.state, self.no_of_neighbors.get()) - neighbor = np.argmax_random_tie(neighbors, key=lambda node: problem.value(node.state)) + neighbor = utils.argmax_random_tie(neighbors, key=lambda node: problem.value(node.state)) map_canvas.delete('poly') points = [] for city in current.state: