DiSMEC++
minimizer.h
Go to the documentation of this file.
1 // Copyright (c) 2021, Aalto University, developed by Erik Schultheis
2 // All rights reserved.
3 //
4 // SPDX-License-Identifier: MIT
5 
6 #ifndef DISMEC_MINIMIZER_H
7 #define DISMEC_MINIMIZER_H
8 
9 #include "objective/objective.h"
10 #include "utils/hyperparams.h"
11 #include "spdlog/spdlog.h"
12 #include "stats/tracked.h"
13 #include <chrono>
14 
15 namespace dismec::solvers
16 {
17  enum class MinimizerStatus {
18  SUCCESS,
19  DIVERGED,
20  TIMED_OUT,
21  FAILED
22  };
23 
26  long NumIters;
27  double FinalValue;
28  double FinalGrad;
29  double InitialValue;
30  double InitialGrad;
31  std::chrono::milliseconds Duration = {};
32  };
33 
34  class Minimizer : public HyperParameterBase, public stats::Tracked {
35  public:
36  explicit Minimizer(std::shared_ptr<spdlog::logger> logger = {});
37  ~Minimizer() override;
38 
39  MinimizationResult minimize(objective::Objective& objective, Eigen::Ref<DenseRealVector> init);
40 
42  void set_logger(std::shared_ptr<spdlog::logger> logger);
43 
44  protected:
45  std::shared_ptr<spdlog::logger> m_Logger;
46 
47  virtual MinimizationResult run(objective::Objective& objective, Eigen::Ref<DenseRealVector> init) = 0;
48  };
49 }
50 
51 #endif //DISMEC_MINIMIZER_H
Base class for all objects that have adjustable hyper-parameters.
Definition: hyperparams.h:83
Class that models an optimization objective.
Definition: objective.h:41
Minimizer(std::shared_ptr< spdlog::logger > logger={})
Definition: minimizer.cpp:14
MinimizationResult minimize(objective::Objective &objective, Eigen::Ref< DenseRealVector > init)
Definition: minimizer.cpp:24
virtual MinimizationResult run(objective::Objective &objective, Eigen::Ref< DenseRealVector > init)=0
std::shared_ptr< spdlog::logger > m_Logger
Definition: minimizer.h:45
void set_logger(std::shared_ptr< spdlog::logger > logger)
sets the logger object that is used for progress tracking.
Definition: minimizer.cpp:20
A base class to be used for all types that implement some for of statistics tracking.
Definition: tracked.h:42
@ FAILED
Some internal operation failed.
@ DIVERGED
The optimization objective appears to be unbounded.
@ SUCCESS
The returned result is a minimum according to the stopping criterion of the algorithm.
@ TIMED_OUT
The maximum number of iterations has been reached but no minimum has been found.
std::chrono::milliseconds Duration
Definition: minimizer.h:31