A parallel version of the L-BFGS-B optimizer of scipy.optimize.minimize().
Project description
optimParallel-python
A parallel version of the L-BFGS-B optimizer of scipy.optimize.minimize()
.
Using it can significantly reduce the optimization time. For an objective
function with an execution time of more than 0.1 seconds and p parameters
the optimization speed increases by up to factor 1+p when no analytic
gradient is specified and 1+p processor cores with sufficient memory
are available.
A similar extension of the L-BFGS-B optimizer exists in the R package optimParallel:
Installation
To install the package run:
pip install optimparallel
Usage
Replace scipy.optimize.minimize()
by optimparallel.minimize_parallel()
to execute
the minimization in parallel:
from optimparallel import minimize_parallel
from scipy.optimize import minimize
import numpy as np
## objective function
def f(x, sleep_secs=.5):
print('fn')
time.sleep(sleep_secs)
return sum((x-14)**2)
## start value
x0 = np.array([10,20])
## minimize with parallel evaluation of 'fun' and
## its approximate gradient.
o1 = minimize_parallel(fun=f, x0=x0, args=.5)
print(o1)
## test against scipy.optimize.minimize()
o2 = minimize(fun=f, x0=x0, args=.5, method='L-BFGS-B')
print(all(np.isclose(o1.x, o2.x, atol=1e-10)),
np.isclose(o1.fun, o2.fun, atol=1e-10),
all(np.isclose(o1.jac, o2.jac, atol=1e-10)))
The evaluated x
values, fun(x)
, and jac(x)
can be returned:
o1 = minimize_parallel(fun=f, x0=x0, args=.5, parallel={'loginfo': True})
print(o1.loginfo)
More examples are given in example.py.
Contributions
Contributions via pull requests are welcome.
Contributors:
- Lewis Blake: code for the 'loginfo' and 'time' features.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for optimparallel-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86ce399202875a8bcb40047e017334f34693b4b78d70ddb53b148d57d7473a6a |
|
MD5 | 4fdd73bd48027fa09c37ec5b78497d5e |
|
BLAKE2b-256 | edfcea5eb82894be38fbcacb36a8d82d76c8853603706f6b3818652ec632d8f4 |