My Project
Public Member Functions | Protected Types | Static Protected Attributes | List of all members
cpu_mlp::BFGS< V, M, Solver > Class Template Reference

BFGS (Broyden–Fletcher–Goldfarb–Shanno) minimizer. More...

#include <bfgs.hpp>

Inheritance diagram for cpu_mlp::BFGS< V, M, Solver >:
Inheritance graph
[legend]
Collaboration diagram for cpu_mlp::BFGS< V, M, Solver >:
Collaboration graph
[legend]

Public Member Functions

 requires (UseDefaultSolver)
 
 requires (!UseDefaultSolver)
 
void setInitialHessian (const M &b)
 Sets the initial approximate Hessian matrix. More...
 
solve (V x, VecFun< V, double > &f, GradFun< V > &Gradient) override
 Solves the optimization problem using BFGS method. More...
 
- Public Member Functions inherited from cpu_mlp::FullBatchMinimizer< V, M >
virtual ~FullBatchMinimizer ()=default
 
virtual void setHessian (const HessFun< V, M > &)
 Sets the Hessian function (for Second Order methods). More...
 
template<auto LossFn, typename DataType >
solve_with_enzyme (V x, DataType *data)
 Helper to solve directly using an Enzyme-compatible raw function. More...
 
void setMaxIterations (int max_iters)
 Sets the maximum number of iterations. More...
 
void setMaxLineIters (int max_line)
 Sets the maximum number of iterations for the line search. More...
 
void setArmijoMaxIter (int max_armijo)
 Sets the maximum iterations for Armijo condition check (alias for setMaxLineIters). More...
 
void setTolerance (double tol)
 Sets the tolerance for convergence. More...
 
unsigned int iterations () const
 Returns the number of iterations performed. More...
 
double tolerance () const
 Returns the tolerance used. More...
 
void setRecorder (::IterationRecorder< CpuBackend > *recorder)
 Attach a recorder for loss/grad history. More...
 

Protected Types

using SolverT = typename std::conditional< UseDefaultSolver, Solver, Solver & >::type
 

Static Protected Attributes

static constexpr bool UseDefaultSolver = std::is_same_v<Solver, DefaultSolverT<M>>
 

Additional Inherited Members

- Protected Member Functions inherited from cpu_mlp::FullBatchMinimizer< V, M >
double line_search (V x, V p, VecFun< V, double > &f, GradFun< V > &Gradient)
 Backtracking Line Search satisfying Wolfe Conditions. More...
 
- Protected Attributes inherited from cpu_mlp::FullBatchMinimizer< V, M >
unsigned int _max_iters = 1000
 
unsigned int _iters = 0
 
double _tol = 1e-10
 
::IterationRecorder< CpuBackend > * recorder_ = nullptr
 Optional recorder for diagnostics. More...
 
double c1 = 1e-4
 
double c2 = 0.9
 
double rho = 0.5
 
double max_line_iters = 50
 

Detailed Description

template<typename V, typename M, typename Solver = DefaultSolverT<M>>
class cpu_mlp::BFGS< V, M, Solver >

BFGS (Broyden–Fletcher–Goldfarb–Shanno) minimizer.

Member Typedef Documentation

◆ SolverT

template<typename V , typename M , typename Solver = DefaultSolverT<M>>
using cpu_mlp::BFGS< V, M, Solver >::SolverT = typename std::conditional<UseDefaultSolver, Solver, Solver &>::type
protected

Member Function Documentation

◆ requires() [1/2]

template<typename V , typename M , typename Solver = DefaultSolverT<M>>
cpu_mlp::BFGS< V, M, Solver >::requires ( UseDefaultSolver)
inline

◆ requires() [2/2]

template<typename V , typename M , typename Solver = DefaultSolverT<M>>
cpu_mlp::BFGS< V, M, Solver >::requires ( UseDefaultSolver  )
inline

◆ setInitialHessian()

template<typename V , typename M , typename Solver = DefaultSolverT<M>>
void cpu_mlp::BFGS< V, M, Solver >::setInitialHessian ( const M &  b)
inlinevirtual

Sets the initial approximate Hessian matrix.

Parameters
bInitial Hessian approximation (usually Identity).

Reimplemented from cpu_mlp::FullBatchMinimizer< V, M >.

◆ solve()

template<typename V , typename M , typename Solver = DefaultSolverT<M>>
V cpu_mlp::BFGS< V, M, Solver >::solve ( x,
VecFun< V, double > &  f,
GradFun< V > &  Gradient 
)
inlineoverridevirtual

Solves the optimization problem using BFGS method.

Parameters
xInitial guess for the parameters.
fObjective function to minimize.
GradientFunction to compute the gradient of f.
Returns
Optimized parameter vector.

Implements cpu_mlp::FullBatchMinimizer< V, M >.

Here is the call graph for this function:

Member Data Documentation

◆ UseDefaultSolver

template<typename V , typename M , typename Solver = DefaultSolverT<M>>
constexpr bool cpu_mlp::BFGS< V, M, Solver >::UseDefaultSolver = std::is_same_v<Solver, DefaultSolverT<M>>
staticconstexprprotected

The documentation for this class was generated from the following file: