DiSMEC++
dismec::solvers::NewtonWithLineSearch Class Reference

#include <newton.h>

Inheritance diagram for dismec::solvers::NewtonWithLineSearch:
dismec::solvers::Minimizer dismec::HyperParameterBase dismec::stats::Tracked

Public Member Functions

 NewtonWithLineSearch (long num_variables)
 
void set_epsilon (double eps)
 
double get_epsilon () const
 
void set_maximum_iterations (long max_iter)
 
long get_maximum_iterations () const
 
void set_alpha_preconditioner (double alpha)
 
double get_alpha_preconditioner () const
 
- Public Member Functions inherited from dismec::solvers::Minimizer
 Minimizer (std::shared_ptr< spdlog::logger > logger={})
 
 ~Minimizer () override
 
MinimizationResult minimize (objective::Objective &objective, Eigen::Ref< DenseRealVector > init)
 
void set_logger (std::shared_ptr< spdlog::logger > logger)
 sets the logger object that is used for progress tracking. More...
 
- Public Member Functions inherited from dismec::HyperParameterBase
 HyperParameterBase ()=default
 
virtual ~HyperParameterBase ()=default
 
 HyperParameterBase (const HyperParameterBase &)=default
 
 HyperParameterBase (HyperParameterBase &&)=default
 
HyperParameterBaseoperator= (HyperParameterBase &&)=default
 
HyperParameterBaseoperator= (const HyperParameterBase &)=default
 
void set_hyper_parameter (const std::string &name, long value)
 
void set_hyper_parameter (const std::string &name, double value)
 
hyper_param_t get_hyper_parameter (const std::string &name) const
 
std::vector< std::string > get_hyper_parameter_names () const
 Returns a vector that lists all hyper parameter names. More...
 
- Public Member Functions inherited from dismec::stats::Tracked
 Tracked ()
 Default constructor, creates the internal stats::StatisticsCollection. More...
 
void register_stat (const std::string &name, std::unique_ptr< Statistics > stat)
 Registers a tracker for the statistics name. More...
 
std::shared_ptr< StatisticsCollectionget_stats () const
 Gets an ownership-sharing reference to the StatisticsCollection. More...
 

Private Member Functions

MinimizationResult run (objective::Objective &objective, Eigen::Ref< DenseRealVector > init) override
 
void record_iteration (int iter, int cg_iter, real_t gnorm, real_t objective, const sLineSearchResult &step, real_t gnorm0)
 

Private Attributes

double m_Epsilon = 0.01
 
double m_Alpha_PCG = 0.01
 
long m_MaxIter = 1000
 
CGMinimizer m_CG_Solver
 
BacktrackingLineSearch m_LineSearcher
 
DenseRealVector m_Gradient
 
DenseRealVector m_PreConditioner
 
HashVector m_Weights
 

Additional Inherited Members

- Public Types inherited from dismec::HyperParameterBase
using hyper_param_t = std::variant< long, double >
 
- Protected Member Functions inherited from dismec::HyperParameterBase
template<class U , class S >
void declare_hyper_parameter (std::string name, U S::*pointer)
 
template<class U , class S >
void declare_hyper_parameter (std::string name, U(S::*getter)() const, void(S::*setter)(U))
 Declares an constrained hyper-parameter with explicit getter and setter function. More...
 
template<class T , class S >
void declare_sub_object (const std::string &name, T S::*object)
 Declares a sub-object that also contains hyper-parameters. More...
 
- Protected Member Functions inherited from dismec::stats::Tracked
 ~Tracked ()
 Non-virtual destructor. Declared protected, so we don't accidentally try to do a polymorphic delete. More...
 
template<class T >
void record (stat_id_t stat, T &&value)
 Record statistics. This function just forwards all its arguments to the internal StatisticsCollection. More...
 
void declare_stat (stat_id_t index, StatisticMetaData meta)
 Declares a new statistics. This function just forwards all its arguments to the internal StatisticsCollection. More...
 
void declare_tag (tag_id_t index, std::string name)
 Declares a new tag. This function just forwards all its arguments to the internal StatisticsCollection. More...
 
template<class... Args>
void set_tag (tag_id_t tag, long value)
 Set value of tag. This function just forwards all its arguments to the internal StatisticsCollection. More...
 
template<class... Args>
auto make_timer (stat_id_t id, Args... args)
 Creates a new ScopeTimer using stats::record_scope_time. More...
 
- Protected Attributes inherited from dismec::solvers::Minimizer
std::shared_ptr< spdlog::logger > m_Logger
 

Detailed Description

Definition at line 16 of file newton.h.

Constructor & Destructor Documentation

◆ NewtonWithLineSearch()

Member Function Documentation

◆ get_alpha_preconditioner()

double dismec::solvers::NewtonWithLineSearch::get_alpha_preconditioner ( ) const
inline

Definition at line 28 of file newton.h.

References m_Alpha_PCG.

Referenced by NewtonWithLineSearch().

◆ get_epsilon()

double dismec::solvers::NewtonWithLineSearch::get_epsilon ( ) const
inline

Definition at line 22 of file newton.h.

References m_Epsilon.

Referenced by NewtonWithLineSearch().

◆ get_maximum_iterations()

long dismec::solvers::NewtonWithLineSearch::get_maximum_iterations ( ) const
inline

Definition at line 25 of file newton.h.

References m_MaxIter.

Referenced by NewtonWithLineSearch().

◆ record_iteration()

◆ run()

MinimizationResult NewtonWithLineSearch::run ( objective::Objective objective,
Eigen::Ref< DenseRealVector init 
)
overrideprivatevirtual

We are using Objective::gradient_and_pre_conditioner here, and in the loop below. It can be more efficient to calculate both values at once (if the loss vector is sparse, only one loop is needed), but as a consequence we perform one more calculation of the preconditioner vector than necessary. At least for squared hinge, this seems to result in a net win (the more iterations we have to do, the more speedup we get).

Implements dismec::solvers::Minimizer.

Definition at line 63 of file newton.cpp.

References dismec::solvers::DIVERGED, dismec::solvers::FAILED, dismec::HashVector::get(), dismec::solvers::CGMinimizer::get_solution(), m_Alpha_PCG, m_CG_Solver, m_Epsilon, m_Gradient, m_LineSearcher, dismec::solvers::Minimizer::m_Logger, m_MaxIter, m_PreConditioner, m_Weights, dismec::stats::Tracked::make_timer(), dismec::solvers::CGMinimizer::minimize(), dismec::stats::Tracked::record(), record_iteration(), dismec::solvers::BacktrackingLineSearch::search(), dismec::stats::Tracked::set_tag(), anonymous_namespace{newton.cpp}::STAT_ABSOLUTE_STEP, anonymous_namespace{newton.cpp}::STAT_GRADIENT_NORM_0, anonymous_namespace{newton.cpp}::STAT_ITER_TIME, anonymous_namespace{newton.cpp}::STAT_LS_FAIL, dismec::solvers::SUCCESS, anonymous_namespace{newton.cpp}::TAG_ITERATION, and dismec::solvers::TIMED_OUT.

◆ set_alpha_preconditioner()

void NewtonWithLineSearch::set_alpha_preconditioner ( double  alpha)

Definition at line 202 of file newton.cpp.

References m_Alpha_PCG.

Referenced by NewtonWithLineSearch().

◆ set_epsilon()

void NewtonWithLineSearch::set_epsilon ( double  eps)

Definition at line 186 of file newton.cpp.

References m_Epsilon.

Referenced by NewtonWithLineSearch(), and TEST_CASE().

◆ set_maximum_iterations()

void NewtonWithLineSearch::set_maximum_iterations ( long  max_iter)

Definition at line 194 of file newton.cpp.

References m_MaxIter.

Referenced by NewtonWithLineSearch().

Member Data Documentation

◆ m_Alpha_PCG

double dismec::solvers::NewtonWithLineSearch::m_Alpha_PCG = 0.01
private

Definition at line 35 of file newton.h.

Referenced by get_alpha_preconditioner(), run(), and set_alpha_preconditioner().

◆ m_CG_Solver

CGMinimizer dismec::solvers::NewtonWithLineSearch::m_CG_Solver
private

Definition at line 39 of file newton.h.

Referenced by NewtonWithLineSearch(), and run().

◆ m_Epsilon

double dismec::solvers::NewtonWithLineSearch::m_Epsilon = 0.01
private

Definition at line 34 of file newton.h.

Referenced by get_epsilon(), run(), and set_epsilon().

◆ m_Gradient

DenseRealVector dismec::solvers::NewtonWithLineSearch::m_Gradient
private

Definition at line 43 of file newton.h.

Referenced by record_iteration(), and run().

◆ m_LineSearcher

BacktrackingLineSearch dismec::solvers::NewtonWithLineSearch::m_LineSearcher
private

Definition at line 40 of file newton.h.

Referenced by NewtonWithLineSearch(), and run().

◆ m_MaxIter

long dismec::solvers::NewtonWithLineSearch::m_MaxIter = 1000
private

Definition at line 36 of file newton.h.

Referenced by get_maximum_iterations(), run(), and set_maximum_iterations().

◆ m_PreConditioner

DenseRealVector dismec::solvers::NewtonWithLineSearch::m_PreConditioner
private

Definition at line 44 of file newton.h.

Referenced by record_iteration(), and run().

◆ m_Weights

HashVector dismec::solvers::NewtonWithLineSearch::m_Weights
private

Definition at line 45 of file newton.h.

Referenced by record_iteration(), and run().


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