How to use the pyswarms.utils.functions.single_obj.sphere function in pyswarms

To help you get started, we’ve selected a few pyswarms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ljvmiranda921 / pyswarms / tests / optimizers / test_general_optimizer.py View on Github external
def optimizer_reset(self, request, options):
        opt = GeneralOptimizerPSO(
            n_particles=10,
            dimensions=2,
            options=options,
            topology=request.param,
        )
        opt.optimize(sphere, 1000)
        opt.reset()
        return opt
github ljvmiranda921 / pyswarms / tests / optimizers / test_general_optimizer.py View on Github external
def optimizer_history(self, request, options):
        opt = GeneralOptimizerPSO(
            n_particles=10,
            dimensions=2,
            options=options,
            topology=request.param,
        )
        opt.optimize(sphere, 1000)
        return opt
github ljvmiranda921 / pyswarms / tests / optimizers / test_local_best.py View on Github external
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)
github ljvmiranda921 / pyswarms / tests / utils / functions / test_singleobj_return.py View on Github external
def test_sphere_output(common_minima):
    """Tests sphere function output."""
    assert np.array_equal(fx.sphere(common_minima), np.zeros((3,)))
github ljvmiranda921 / pyswarms / tests / optimizers / test_binary.py View on Github external
def optimizer_history(self, options):
        opt = BinaryPSO(10, 2, options=options)
        opt.optimize(sphere, 1000)
        return opt
github ljvmiranda921 / pyswarms / tests / optimizers / test_global_best.py View on Github external
def test_global_correct_pos(self, options):
        """ Test to check global optimiser returns the correct position corresponding to the best cost """
        opt = GlobalBestPSO(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)
github ljvmiranda921 / pyswarms / tests / optimizers / test_binary.py View on Github external
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)
github ljvmiranda921 / pyswarms / tests / utils / functions / test_singleobj_returndims.py View on Github external
def test_sphere_output_size(common_minima, targetdim):
    """Tests sphere output size."""
    assert fx.sphere(common_minima).shape == targetdim
github ljvmiranda921 / pyswarms / tests / optimizers / test_binary.py View on Github external
def optimizer_reset(self, options):
        opt = BinaryPSO(10, 2, options=options)
        opt.optimize(sphere, 10)
        opt.reset()
        return opt