# optimize_gjo.py import random def gjo_optimize(search_space, iterations=10): best_score = float('-inf') best_params = {} for i in range(iterations): lr = random.uniform(*search_space['learning_rate']) batch_size = random.choice(search_space['batch_size']) dropout = random.uniform(*search_space['dropout_rate']) # Simulate a scoring function (higher is better) score = 0.98 - abs(lr - 0.01) * 5 - abs(dropout - 0.2) * 2 print(f"Iteration {i+1}: LR={lr:.4f}, Batch={batch_size}, Dropout={dropout:.2f}, Score={score:.4f}") if score > best_score: best_score = score best_params = { "learning_rate": lr, "batch_size": batch_size, "dropout_rate": dropout } return best_params if __name__ == '__main__': param_space = { "learning_rate": (0.001, 0.05), "batch_size": [32, 64, 96, 128], "dropout_rate": (0.1, 0.5) } best = gjo_optimize(param_space, iterations=10) print("\nBest Hyperparameters Found:") print(best)