Expand description

Limited memory BFGS (L-BFGS) algorithm ported from liblbfgs

Example

// 0. Import the lib
use liblbfgs::lbfgs;
 
const N: usize = 100;
 
// 1. Initialize data
let mut x = [0.0 as f64; N];
for i in (0..N).step_by(2) {
    x[i] = -1.2;
    x[i + 1] = 1.0;
}
 
// 2. Defining how to evaluate function and gradient
let evaluate = |x: &[f64], gx: &mut [f64]| {
    let n = x.len();
 
    let mut fx = 0.0;
    for i in (0..n).step_by(2) {
        let t1 = 1.0 - x[i];
        let t2 = 10.0 * (x[i + 1] - x[i] * x[i]);
        gx[i + 1] = 20.0 * t2;
        gx[i] = -2.0 * (x[i] * gx[i + 1] + t1);
        fx += t1 * t1 + t2 * t2;
    }
 
    Ok(fx)
};
 
let prb = lbfgs()
    .with_max_iterations(5)
    .with_orthantwise(1.0, 0, 99) // enable OWL-QN
    .minimize(
        &mut x,                   // input variables
        evaluate,                 // define how to evaluate function
        |prgr| {                  // define progress monitor
            println!("iter: {:}", prgr.niter);
            false                 // returning true will cancel optimization
        }
    )
    .expect("lbfgs owlqn minimize");
 
println!("fx = {:}", prb.fx);

Modules

Find a satisfactory step length along predefined search direction

Find a satisfactory step length along predefined search direction

Backend for lbfgs vector operations

Structs

L-BFGS optimization parameters.

LBFGS optimization state allowing iterative propagation

Evaluated function value and gradient

Represents an optimization problem.

Store optimization progress data, for progress monitor

Functions

Default test function (rosenbrock) adopted from liblbfgs sample.c

Default progress monitor adopted from liblbfgs sample.c