-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_optimini.py
More file actions
34 lines (23 loc) · 896 Bytes
/
test_optimini.py
File metadata and controls
34 lines (23 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
from optimini.history import History, history_plot
from optimini.minimize import minimize
def dict_fun(params):
return params["a"] ** 2 + params["b"] ** 2
def array_fun(params):
return params @ params
def test_simple_minimize_with_dict_params():
params = {"a": 1, "b": 2}
res = minimize(dict_fun, params, method="L-BFGS-B")
assert isinstance(res.x, dict)
assert np.allclose(res.x["a"], 0)
assert np.allclose(res.x["b"], 0)
def test_simple_minimize_with_array_params():
params = np.array([1, 2])
res = minimize(array_fun, params, method="L-BFGS-B")
assert isinstance(res.x, np.ndarray)
assert np.allclose(res.x, np.array([0, 0]))
def test_history_collection():
params = {"a": 1, "b": 2}
res = minimize(dict_fun, params, method="L-BFGS-B")
assert isinstance(res.history, History)
history_plot({"test": res})