cost += fit(model, loss, opt, X_train[:, start:end, :], Y_train[start:end]) # Predicting samples from evaluating set preds = predict(model, X_val) # Calculates accuracy acc = np.mean(preds == Y_val) return 1 - acc # Number of agents and decision variables n_agents = 10 n_variables = 2 # Lower and upper bounds (has to be the same size as `n_variables`) lower_bound = [0, 0] upper_bound = [1, 1] # Creates the space, optimizer and function space = SearchSpace(n_agents, n_variables, lower_bound, upper_bound) optimizer = PSO() function = Function(lstm) # Bundles every piece into Opytimizer class opt = Opytimizer(space, optimizer, function) # Runs the optimization task opt.start(n_iterations=100)
from opytimizer.optimizers.swarm import PSO # One should declare a hyperparameters object based # on the desired algorithm that will be used params = {'w': 0.7, 'c1': 1.7, 'c2': 1.7} # Creates a PSO optimizer o = PSO(params=params)