def lbest_reset(): """Returns a LocalBestPSO instance that has been run and reset to check default value""" pso = LocalBestPSO(10, 2, {'c1': 0.5, 'c2': 0.7, 'w': 0.5, 'k': 2, 'p': 2}) pso.optimize(sphere_func, 10, verbose=0) pso.reset() return pso
def lbest_reset(): """Returns a LocalBestPSO instance that has been run and reset to check default value""" pso = LocalBestPSO(10, 2, {"c1": 0.5, "c2": 0.7, "w": 0.5, "k": 2, "p": 2}) pso.optimize(sphere_func, 10, verbose=0) pso.reset() return pso
def test_reset_best_pos_none(self): """Tests if best pos is set to NoneType when reset() is called""" # Perform a simple optimization optimizer = LocalBestPSO(5, 2, options=self.options) optimizer.optimize(sphere_func, 100, verbose=0) optimizer.reset() self.assertIsNone(optimizer.best_pos)
def test_reset_best_cost_inf(self): """Tests if best cost is set to infinity when reset() is called""" # Perform a simple optimization optimizer = LocalBestPSO(5, 2, options=self.options) optimizer.optimize(sphere_func, 100, verbose=0) optimizer.reset() self.assertEqual(optimizer.best_cost, np.inf)
def test_reset_best_pos_none(self): """Tests if best pos is set to NoneType when reset() is called""" # Perform a simple optimization optimizer = LocalBestPSO(5,2, options=self.options) optimizer.optimize(sphere_func, 100, verbose=0) optimizer.reset() self.assertIsNone(optimizer.best_pos)
def test_reset_best_cost_inf(self): """Tests if best cost is set to infinity when reset() is called""" # Perform a simple optimization optimizer = LocalBestPSO(5,2, options=self.options) optimizer.optimize(sphere_func, 100, verbose=0) optimizer.reset() self.assertEqual(optimizer.best_cost, np.inf)
def test_reset(self): """Tests if the reset method resets the attributes required""" # Perform a simple optimization optimizer = LocalBestPSO(5,2, options=self.options) optimizer.optimize(sphere_func, 100, verbose=0) # Reset the attributes optimizer.reset() # Perform testing self.assertEqual(optimizer.best_cost, np.inf) self.assertIsNone(optimizer.best_pos)
def optimizer_reset(self, options): opt = LocalBestPSO(10, 2, options) opt.optimize(sphere, 10) opt.reset() return opt