A simple Python binding for libLBFGS.
import pylbfgs
import numpy as np
def evaluate(instance, x, n, step):
# sphere function
fx = np.sum(x * x)
g = 2 * x
return fx, g
x = np.random.normal(size=(10,))
print("BEFORE: " + str(x))
param = pylbfgs.default_params()
param.epsilon = 1e-30
param.past = 3
code, fx, x = pylbfgs.lbfgs(x, evaluate)
print("Optimization exited with code {code} and function value {fx:.5f}".format(code=code, fx=fx))
print("AFTER: " + str(x))
No setup.py yet, but you can simply add the pylbfgs
directory into your project after compiling libLBFGS:
- clone this repo and
cd
into it git submodule init && git submodule update
cd pylbfgs/liblbfgs
./autogen.sh && ./configure.sh && make
MIT