pub fn linesearch() -> LineSearchExpand description
A unified interface to line search methods.
§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 {
//
}
}