mlpack  master
adam.hpp
Go to the documentation of this file.
1 
16 #ifndef __MLPACK_CORE_OPTIMIZERS_ADAM_ADAM_HPP
17 #define __MLPACK_CORE_OPTIMIZERS_ADAM_ADAM_HPP
18 
19 #include <mlpack/prereqs.hpp>
20 
21 namespace mlpack {
22 namespace optimization {
23 
61 template<typename DecomposableFunctionType>
62 class Adam
63 {
64  public:
85  Adam(DecomposableFunctionType& function,
86  const double stepSize = 0.001,
87  const double beta1 = 0.9,
88  const double beta2 = 0.999,
89  const double eps = 1e-8,
90  const size_t maxIterations = 100000,
91  const double tolerance = 1e-5,
92  const bool shuffle = true);
93 
102  double Optimize(arma::mat& iterate);
103 
105  const DecomposableFunctionType& Function() const { return function; }
107  DecomposableFunctionType& Function() { return function; }
108 
110  double StepSize() const { return stepSize; }
112  double& StepSize() { return stepSize; }
113 
115  double Beta1() const { return beta1; }
117  double& Beta1() { return beta1; }
118 
120  double Beta2() const { return beta2; }
122  double& Beta2() { return beta2; }
123 
125  double Epsilon() const { return eps; }
127  double& Epsilon() { return eps; }
128 
130  size_t MaxIterations() const { return maxIterations; }
132  size_t& MaxIterations() { return maxIterations; }
133 
135  double Tolerance() const { return tolerance; }
137  double& Tolerance() { return tolerance; }
138 
140  bool Shuffle() const { return shuffle; }
142  bool& Shuffle() { return shuffle; }
143 
144  private:
146  DecomposableFunctionType& function;
147 
149  double stepSize;
150 
152  double beta1;
153 
155  double beta2;
156 
158  double eps;
159 
162 
164  double tolerance;
165 
168  bool shuffle;
169 };
170 
171 } // namespace optimization
172 } // namespace mlpack
173 
174 // Include implementation.
175 #include "adam_impl.hpp"
176 
177 #endif
double Beta2() const
Get the second moment coefficient.
Definition: adam.hpp:120
const DecomposableFunctionType & Function() const
Get the instantiated function to be optimized.
Definition: adam.hpp:105
DecomposableFunctionType & Function()
Modify the instantiated function.
Definition: adam.hpp:107
double eps
The value used to initialise the mean squared gradient parameter.
Definition: adam.hpp:158
size_t maxIterations
The maximum number of allowed iterations.
Definition: adam.hpp:161
bool shuffle
Controls whether or not the individual functions are shuffled when iterating.
Definition: adam.hpp:168
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
Definition: adam.hpp:130
The core includes that mlpack expects; standard C++ includes and Armadillo.
double & Beta2()
Modify the second moment coefficient.
Definition: adam.hpp:122
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limit).
Definition: adam.hpp:132
double stepSize
The step size for each example.
Definition: adam.hpp:149
double Epsilon() const
Get the value used to initialise the mean squared gradient parameter.
Definition: adam.hpp:125
double tolerance
The tolerance for termination.
Definition: adam.hpp:164
bool Shuffle() const
Get whether or not the individual functions are shuffled.
Definition: adam.hpp:140
double Beta1() const
Get the smoothing parameter.
Definition: adam.hpp:115
double & Tolerance()
Modify the tolerance for termination.
Definition: adam.hpp:137
double & Beta1()
Modify the smoothing parameter.
Definition: adam.hpp:117
bool & Shuffle()
Modify whether or not the individual functions are shuffled.
Definition: adam.hpp:142
double Tolerance() const
Get the tolerance for termination.
Definition: adam.hpp:135
double beta1
Exponential decay rate for the first moment estimates.
Definition: adam.hpp:152
double StepSize() const
Get the step size.
Definition: adam.hpp:110
double & Epsilon()
Modify the value used to initialise the mean squared gradient parameter.
Definition: adam.hpp:127
double Optimize(arma::mat &iterate)
Optimize the given function using Adam.
double & StepSize()
Modify the step size.
Definition: adam.hpp:112
Adam is an optimizer that computes individual adaptive learning rates for different parameters from e...
Definition: adam.hpp:62
double beta2
Exponential decay rate for the weighted infinity norm estimates.
Definition: adam.hpp:155
Adam(DecomposableFunctionType &function, const double stepSize=0.001, const double beta1=0.9, const double beta2=0.999, const double eps=1e-8, const size_t maxIterations=100000, const double tolerance=1e-5, const bool shuffle=true)
Construct the Adam optimizer with the given function and parameters.