-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_acc.py
18 lines (14 loc) · 1.26 KB
/
test_acc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import optimtool
from optimtool.base import sp
from joblib import Parallel, delayed
x = sp.symbols("x1:5")
f1 = 100 * (x[1] - x[0]**2)**2 + (1 - x[0])**2 + 100 * (x[3] - x[2]**2)**2 + (1 - x[2])**2
f2 = (sp.exp(x[0]) - x[0]) + (sp.exp(x[1]) - x[1]) + (sp.exp(x[2]) - x[2]) + (sp.exp(x[3]) - x[3])
f3 = 100 * (x[1] - x[0]**3)**2 + (1 - x[0])**2 + 100 * (x[3] - x[2]**3)**2 + (1 - x[2])**2
f4 = (x[0] - 1)**2 + (x[1] - 1)**2 + (x[2] - 1)**2 + ((x[0]**2 + x[1]**2 + x[2]**2 + x[3]**2) - 0.25)**2
f5 = (sp.exp(x[0]) - x[0]) + (sp.exp(x[1]) - 2 * x[1]) + (sp.exp(x[2]) - 3 * x[2]) + (sp.exp(x[3]) - 4 * x[3])
# add fit function into acc_data with collections as functions, initial starts, epsilons for multiple convergence conditions.
acc_data = [(f1, (-2, 2, -2, 2), 1e-1), (f2, (2, 2, 2, 2), 1e-2), (f3, (-1, 0.5, -1, 0.5), 1e-2), (f4, (5, 5, 5, 5), 1e-1), (f5, (0.5, 0.5, 0.5, 0.5), 1e-2)]
acc_function = optimtool.unconstrain.newton_quasi.bfgs # plot with full target description on third parameters in plot_iteration
Parallel(n_jobs=-1, backend="loky", prefer="processes")(delayed(acc_function)(f[0], x, f[1], epsilon=f[2]) for f in acc_data)
# Parallel(n_jobs=-1, backend="threading", prefer="processes")(delayed(acc_function)(f[0], x, f[1], draw=False, epsilon=f[2]) for f in acc_data)