pub struct DampedNewton { /* private fields */ }Expand description
Damped Newton optimizer with finite-difference Hessian approximation.
Newton’s method uses second-order information (Hessian) to find the minimum by solving the linear system: H * d = -g, where H is the Hessian and g is the gradient. The damping factor and line search ensure global convergence.
§Algorithm
- Compute gradient g = ∇f(x)
- Approximate Hessian H using finite differences
- Solve H * d = -g using Cholesky decomposition
- If Hessian not positive definite, fall back to steepest descent
- Line search along d to find step size α
- Update: x_{k+1} =
x_k+ α *d_k
§Parameters
max_iter: Maximum number of iterations- tol: Convergence tolerance (gradient norm)
- epsilon: Finite difference step size for Hessian approximation (default: 1e-5)
§Example
use aprender::optim::{DampedNewton, Optimizer};
use aprender::primitives::Vector;
let mut optimizer = DampedNewton::new(100, 1e-5);
// Minimize quadratic function f(x,y) = x^2 + 2y^2
let f = |x: &Vector<f32>| x[0] * x[0] + 2.0 * x[1] * x[1];
let grad = |x: &Vector<f32>| Vector::from_slice(&[2.0 * x[0], 4.0 * x[1]]);
let x0 = Vector::from_slice(&[5.0, 3.0]);
let result = optimizer.minimize(f, grad, x0);Implementations§
Source§impl DampedNewton
impl DampedNewton
Trait Implementations§
Source§impl Clone for DampedNewton
impl Clone for DampedNewton
Source§fn clone(&self) -> DampedNewton
fn clone(&self) -> DampedNewton
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 DampedNewton
impl Debug for DampedNewton
Source§impl Optimizer for DampedNewton
impl Optimizer for DampedNewton
Source§fn step(&mut self, _params: &mut Vector<f32>, _gradients: &Vector<f32>)
fn step(&mut self, _params: &mut Vector<f32>, _gradients: &Vector<f32>)
Stochastic update (mini-batch mode) - for SGD, Adam,
RMSprop. Read moreAuto Trait Implementations§
impl Freeze for DampedNewton
impl RefUnwindSafe for DampedNewton
impl Send for DampedNewton
impl Sync for DampedNewton
impl Unpin for DampedNewton
impl UnwindSafe for DampedNewton
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