Exemple #1
0
 def test_general_correct_pos(self, options, optimizer):
     """ Test to check general optimiser returns the correct position corresponding to the best cost """
     cost, pos = optimizer.optimize(sphere, iters=5)
     # find best pos from history
     min_cost_idx = np.argmin(optimizer.cost_history)
     min_pos_idx = np.argmin(sphere(optimizer.pos_history[min_cost_idx]))
     assert np.array_equal(optimizer.pos_history[min_cost_idx][min_pos_idx],
                           pos)
 def test_local_correct_pos(self, options):
     """ Test to check local optimiser returns the correct position corresponding to the best cost """
     opt = LocalBestPSO(n_particles=10, dimensions=2, options=options)
     cost, pos = opt.optimize(sphere, iters=5)
     # find best pos from history
     min_cost_idx = np.argmin(opt.cost_history)
     min_pos_idx = np.argmin(sphere(opt.pos_history[min_cost_idx]))
     assert np.array_equal(opt.pos_history[min_cost_idx][min_pos_idx], pos)
 def test_binary_correct_pos(self, options):
     """Test to check binary optimiser returns the correct position
     corresponding to the best cost"""
     opt = BinaryPSO(10, 2, options=options)
     cost, pos = opt.optimize(sphere, 10)
     # find best pos from history
     min_cost_idx = np.argmin(opt.cost_history)
     min_pos_idx = np.argmin(sphere(opt.pos_history[min_cost_idx]))
     assert np.array_equal(opt.pos_history[min_cost_idx][min_pos_idx], pos)
def test_sphere_output_size(common_minima, targetdim):
    """Tests sphere output size."""
    assert fx.sphere(common_minima).shape == targetdim
Exemple #5
0
def test_sphere_output(common_minima):
    """Tests sphere function output."""
    assert np.array_equal(fx.sphere(common_minima), np.zeros((3, )))