How to use pyswarms - 10 common examples

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 / utils / functions / test_singleobj.py View on Github external
def test_rosenbrock_output(self):
        """Tests rosenbrock function output."""
        self.assertEqual(fx.rosenbrock_func(self.input2).all(),np.zeros(3).all())
github ljvmiranda921 / pyswarms / tests / utils / functions / test_singleobj.py View on Github external
def test_bukin6_output(self):
        """Test bukin function output."""
        assert np.isclose(fx.matyas_func(self.input),self.target).all()
github ljvmiranda921 / pyswarms / tests / utils / functions / test_singleobj_bounds.py View on Github external
def test_matyas_bound_fail(outbound):
    """Test matyas bound exception"""
    with pytest.raises(ValueError):
        x = outbound(b["matyas"].low, b["matyas"].high, size=(3, 2))
        fx.matyas(x)
github ljvmiranda921 / pyswarms / tests / utils / functions / test_singleobj.py View on Github external
def test_sphere_output(self):
        """Tests sphere function output."""
        self.assertEqual(fx.sphere_func(self.input).all(), self.target.all())
github ljvmiranda921 / pyswarms / tests / utils / functions / test_singleobj_return.py View on Github external
def test_bukin6_output(common_minima2):
    """Test bukin function output."""
    assert np.isclose(fx.bukin6([-10, 1] * common_minima2), np.zeros(3)).all()
github ljvmiranda921 / pyswarms / tests / utils / functions / test_singleobj.py View on Github external
def test_beale_output(self):
        """Tests beale function output."""
        assert np.isclose(fx.beale_func([3, 0.5] * self.input2),
            self.target).all()
github ljvmiranda921 / pyswarms / tests / utils / functions / test_singleobj.py View on Github external
def test_rastrigin_bound_fail(self):
        """Test rastrigin bound exception"""
        x = - np.random.uniform(low=6,high=100,size=(3,2))
        x_ = np.random.uniform(low=6,high=100,size=(3,2))

        with self.assertRaises(ValueError):
            fx.rastrigin_func(x)

        with self.assertRaises(ValueError):
            fx.rastrigin_func(x_)
github ljvmiranda921 / pyswarms / tests / utils / functions / test_singleobj.py View on Github external
def test_booth_output_size(self):
        """Test booth output size."""
        self.assertEqual(fx.booth_func(self.input).shape, self.target_size)
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