DiSMEC++
|
#include <newton.h>
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 | |
HyperParameterBase & | operator= (HyperParameterBase &&)=default |
HyperParameterBase & | operator= (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< StatisticsCollection > | get_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 |
|
explicit |
Definition at line 35 of file newton.cpp.
References dismec::HyperParameterBase::declare_hyper_parameter(), dismec::stats::Tracked::declare_stat(), dismec::HyperParameterBase::declare_sub_object(), dismec::stats::Tracked::declare_tag(), get_alpha_preconditioner(), get_epsilon(), get_maximum_iterations(), m_CG_Solver, m_LineSearcher, set_alpha_preconditioner(), set_epsilon(), set_maximum_iterations(), anonymous_namespace{newton.cpp}::STAT_ABSOLUTE_STEP, anonymous_namespace{newton.cpp}::STAT_CG_ITERS, anonymous_namespace{newton.cpp}::STAT_GRADIENT, anonymous_namespace{newton.cpp}::STAT_GRADIENT_NORM, anonymous_namespace{newton.cpp}::STAT_GRADIENT_NORM_0, anonymous_namespace{newton.cpp}::STAT_ITER_TIME, anonymous_namespace{newton.cpp}::STAT_LINESEARCH_STEPSIZE, anonymous_namespace{newton.cpp}::STAT_LS_FAIL, anonymous_namespace{newton.cpp}::STAT_LS_STEPS, anonymous_namespace{newton.cpp}::STAT_OBJECTIVE_VALUE, anonymous_namespace{newton.cpp}::STAT_PRECONDITIONER, anonymous_namespace{newton.cpp}::STAT_PROGRESS, anonymous_namespace{newton.cpp}::STAT_WEIGHT_VECTOR, and anonymous_namespace{newton.cpp}::TAG_ITERATION.
|
inline |
Definition at line 28 of file newton.h.
References m_Alpha_PCG.
Referenced by NewtonWithLineSearch().
|
inline |
|
inline |
|
private |
Definition at line 169 of file newton.cpp.
References dismec::HashVector::get(), m_Gradient, dismec::solvers::Minimizer::m_Logger, m_PreConditioner, m_Weights, dismec::solvers::sLineSearchResult::NumIters, dismec::stats::Tracked::record(), anonymous_namespace{newton.cpp}::STAT_CG_ITERS, anonymous_namespace{newton.cpp}::STAT_GRADIENT, anonymous_namespace{newton.cpp}::STAT_GRADIENT_NORM, anonymous_namespace{newton.cpp}::STAT_LINESEARCH_STEPSIZE, anonymous_namespace{newton.cpp}::STAT_LS_STEPS, anonymous_namespace{newton.cpp}::STAT_OBJECTIVE_VALUE, anonymous_namespace{newton.cpp}::STAT_PRECONDITIONER, anonymous_namespace{newton.cpp}::STAT_PROGRESS, anonymous_namespace{newton.cpp}::STAT_WEIGHT_VECTOR, and dismec::solvers::sLineSearchResult::StepSize.
Referenced by run().
|
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.
void NewtonWithLineSearch::set_alpha_preconditioner | ( | double | alpha | ) |
Definition at line 202 of file newton.cpp.
References m_Alpha_PCG.
Referenced by NewtonWithLineSearch().
void NewtonWithLineSearch::set_epsilon | ( | double | eps | ) |
Definition at line 186 of file newton.cpp.
References m_Epsilon.
Referenced by NewtonWithLineSearch(), and TEST_CASE().
void NewtonWithLineSearch::set_maximum_iterations | ( | long | max_iter | ) |
Definition at line 194 of file newton.cpp.
References m_MaxIter.
Referenced by NewtonWithLineSearch().
|
private |
Definition at line 35 of file newton.h.
Referenced by get_alpha_preconditioner(), run(), and set_alpha_preconditioner().
|
private |
Definition at line 39 of file newton.h.
Referenced by NewtonWithLineSearch(), and run().
|
private |
Definition at line 34 of file newton.h.
Referenced by get_epsilon(), run(), and set_epsilon().
|
private |
Definition at line 43 of file newton.h.
Referenced by record_iteration(), and run().
|
private |
Definition at line 40 of file newton.h.
Referenced by NewtonWithLineSearch(), and run().
|
private |
Definition at line 36 of file newton.h.
Referenced by get_maximum_iterations(), run(), and set_maximum_iterations().
|
private |
Definition at line 44 of file newton.h.
Referenced by record_iteration(), and run().
|
private |
Definition at line 45 of file newton.h.
Referenced by record_iteration(), and run().