1个不稳定版本

0.1.0 2022年5月16日

#19 in #line-search


3 个crate中使用 (直接使用2个)

MIT/Apache

40KB
586

线搜索,也称为一维搜索,是指对单变量函数的优化过程。

可用算法

  • MoreThuente
  • BackTracking
  • BackTrackingArmijo
  • BackTrackingWolfe
  • BackTrackingStrongWolfe

参考文献

  • Sun, W.; Yuan, Y. 优化理论与方法:非线性规划,第1版;Springer,2006。
  • Nocedal, J.; Wright, S. 数值优化;Springer Science & Business Media,2006。

示例

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 {
        //
    }
}

依赖

~9–20MB
~292K SLoC