1 unstable release

0.1.0 May 16, 2022

#20 in #line-search

32 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

40KB
586 lines

Line search, also called one-dimensional search, refers to an optimization procedure for univariable functions.

Available algorithms

  • MoreThuente
  • BackTracking
  • BackTrackingArmijo
  • BackTrackingWolfe
  • BackTrackingStrongWolfe

References

  • Sun, W.; Yuan, Y. Optimization Theory and Methods: Nonlinear Programming, 1st ed.; Springer, 2006.
  • Nocedal, J.; Wright, S. Numerical Optimization; Springer Science & Business Media, 2006.

Examples

use line::linesearch;

let mut step = 1.0;
let count = linesearch()
    .with_initial_step(1.5) // the default is 1.0
    .with_algorithm("BackTracking") // the default is MoreThuente
    .find(5, |a: f64, out: &mut Output| {
        // restore position
        x.veccpy(&x_k);
        // update position with step along d
        x.vecadd(&d_k, a);
        // update value and gradient
        out.fx = f(x, &mut gx)?;
        // update line search gradient
        out.gx = gx.vecdot(d);
        // update optimal step size
        step = a;
        // return any user defined data
        Ok(())
    })?;

let ls = linesearch()
    .with_max_iterations(5) // the default is 10
    .with_initial_step(1.5) // the default is 1.0
    .with_algorithm("BackTracking") // the default is MoreThuente
    .find_iter(|a: f64, out: &mut Output| {
        // restore position
        x.veccpy(&x_k);
        // update position with step along d
        x.vecadd(&d_k, a);
        // update value and gradient
        out.fx = f(x, &mut gx)?;
        // update line search gradient
        out.gx = gx.vecdot(d);
        // update optimal step size
        step = a;
        // return any user defined data
        Ok(())
    })?;

for success in ls {
    if success {
        //
    } else {
        //
    }
}

Dependencies

~9–21MB
~286K SLoC