pub trait LineSearch {
// Required method
fn search<F, G>(
&self,
f: &F,
grad: &G,
x: &Vector<f32>,
d: &Vector<f32>,
) -> f32
where F: Fn(&Vector<f32>) -> f32,
G: Fn(&Vector<f32>) -> Vector<f32>;
}Expand description
Trait for line search strategies.
Given a function f, current point x, and search direction d, finds a step size α > 0 such that x + α*d satisfies certain decrease conditions.
§Example
use aprender::optim::{LineSearch, BacktrackingLineSearch};
use aprender::primitives::Vector;
let ls = BacktrackingLineSearch::default();
let f = |x: &Vector<f32>| x[0] * x[0];
let grad = |x: &Vector<f32>| Vector::from_slice(&[2.0 * x[0]]);
let x = Vector::from_slice(&[1.0]);
let d = Vector::from_slice(&[-2.0]); // Descent direction
let alpha = ls.search(&f, &grad, &x, &d);
assert!(alpha > 0.0);Different strategies enforce different conditions on the step size.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.