Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_rosenbrock_output(self):
"""Tests rosenbrock function output."""
self.assertEqual(fx.rosenbrock_func(self.input2).all(),np.zeros(3).all())
def test_bukin6_output(self):
"""Test bukin function output."""
assert np.isclose(fx.matyas_func(self.input),self.target).all()
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)
def test_sphere_output(self):
"""Tests sphere function output."""
self.assertEqual(fx.sphere_func(self.input).all(), self.target.all())
def test_bukin6_output(common_minima2):
"""Test bukin function output."""
assert np.isclose(fx.bukin6([-10, 1] * common_minima2), np.zeros(3)).all()
def test_beale_output(self):
"""Tests beale function output."""
assert np.isclose(fx.beale_func([3, 0.5] * self.input2),
self.target).all()
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_)
def test_booth_output_size(self):
"""Test booth output size."""
self.assertEqual(fx.booth_func(self.input).shape, self.target_size)
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
def optimizer_history(self, request, options):
opt = GeneralOptimizerPSO(
n_particles=10,
dimensions=2,
options=options,
topology=request.param,
)
opt.optimize(sphere, 1000)
return opt