pub struct BacktrackingLineSearch { /* private fields */ }Expand description
Backtracking line search with Armijo condition.
Starts with step size α = 1 and repeatedly shrinks it by factor ρ until the Armijo condition is satisfied:
f(x + α*d) ≤ f(x) + c₁*α*∇f(x)ᵀdThis ensures sufficient decrease in the objective function.
§Parameters
- c1: Armijo constant (typical: 1e-4), controls acceptable decrease
- rho: Backtracking factor (typical: 0.5), shrinkage rate for α
max_iter: Maximum backtracking iterations (safety limit)
§Example
use aprender::optim::{BacktrackingLineSearch, LineSearch};
use aprender::primitives::Vector;
let line_search = BacktrackingLineSearch::new(1e-4, 0.5, 50);
// Define a simple quadratic function
let f = |x: &Vector<f32>| x[0] * x[0] + x[1] * x[1];
let grad = |x: &Vector<f32>| Vector::from_slice(&[2.0 * x[0], 2.0 * x[1]]);
let x = Vector::from_slice(&[1.0, 1.0]);
let d = Vector::from_slice(&[-2.0, -2.0]); // Descent direction
let alpha = line_search.search(&f, &grad, &x, &d);
assert!(alpha > 0.0);Implementations§
Trait Implementations§
Source§impl Clone for BacktrackingLineSearch
impl Clone for BacktrackingLineSearch
Source§fn clone(&self) -> BacktrackingLineSearch
fn clone(&self) -> BacktrackingLineSearch
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BacktrackingLineSearch
impl Debug for BacktrackingLineSearch
Source§impl Default for BacktrackingLineSearch
impl Default for BacktrackingLineSearch
Auto Trait Implementations§
impl Freeze for BacktrackingLineSearch
impl RefUnwindSafe for BacktrackingLineSearch
impl Send for BacktrackingLineSearch
impl Sync for BacktrackingLineSearch
impl Unpin for BacktrackingLineSearch
impl UnsafeUnpin for BacktrackingLineSearch
impl UnwindSafe for BacktrackingLineSearch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more