-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1626e8c
commit 0bf71d0
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import numpy as np | ||
from numpy.testing import assert_allclose | ||
|
||
import lmfit | ||
|
||
|
||
def test_ampgo_Alpine02(): | ||
"""Test AMPGO algorithm on Alpine02 function.""" | ||
|
||
global_optimum = [7.91705268, 4.81584232] | ||
fglob = -6.12950 | ||
|
||
def residual_Alpine02(params): | ||
x0 = params['x0'].value | ||
x1 = params['x1'].value | ||
return np.prod(np.sqrt(x0) * np.sin(x0)) * np.prod(np.sqrt(x1) * | ||
np.sin(x1)) | ||
|
||
pars = lmfit.Parameters() | ||
pars.add_many(('x0', 1., True, 0.0, 10.0), | ||
('x1', 1., True, 0.0, 10.0)) | ||
|
||
mini = lmfit.Minimizer(residual_Alpine02, pars) | ||
out = mini.minimize(method='ampgo') | ||
out_x = np.array([out.params['x0'].value, out.params['x1'].value]) | ||
|
||
assert_allclose(out.chisqr, fglob, rtol=1e-5) | ||
assert_allclose(min(out_x), min(global_optimum), rtol=1e-3) | ||
assert_allclose(max(out_x), max(global_optimum), rtol=1e-3) | ||
assert('global' in out.ampgo_msg) | ||
|
||
|
||
|
||
def test_ampgo_Alpine02_maxfunevals(): | ||
"""Test AMPGO algorithm on Alpine02 function.""" | ||
|
||
def residual_Alpine02(params): | ||
x0 = params['x0'].value | ||
x1 = params['x1'].value | ||
return np.prod(np.sqrt(x0) * np.sin(x0)) * np.prod(np.sqrt(x1) * | ||
np.sin(x1)) | ||
|
||
pars = lmfit.Parameters() | ||
pars.add_many(('x0', 1., True, 0.0, 10.0), | ||
('x1', 1., True, 0.0, 10.0)) | ||
|
||
mini = lmfit.Minimizer(residual_Alpine02, pars) | ||
kws = {'maxfunevals': 50} | ||
out = mini.minimize(method='ampgo', **kws) | ||
assert('function' in out.ampgo_msg) | ||
|
||
|
||
if __name__ == '__main__': | ||
test_ampgo_Alpine02() | ||
test_ampgo_Alpine02_maxfunevals() |