MiniDNN
SGD.h
1 #ifndef OPTIMIZER_SGD_H_
2 #define OPTIMIZER_SGD_H_
3 
4 #include <Eigen/Core>
5 #include "../Config.h"
6 #include "../Optimizer.h"
7 
8 namespace MiniDNN {
9 
10 
16 class SGD: public Optimizer
17 {
18 private:
19  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
20  typedef Vector::ConstAlignedMapType ConstAlignedMapVec;
21  typedef Vector::AlignedMapType AlignedMapVec;
22 
23 public:
24  Scalar m_lrate;
25  Scalar m_decay;
26 
27  SGD() :
28  m_lrate(Scalar(0.01)), m_decay(Scalar(0))
29  {}
30 
31  void update(ConstAlignedMapVec& dvec, AlignedMapVec& vec)
32  {
33  vec.noalias() -= m_lrate * (dvec + m_decay * vec);
34  }
35 };
36 
37 
38 } // namespace MiniDNN
39 
40 
41 #endif /* OPTIMIZER_SGD_H_ */
void update(ConstAlignedMapVec &dvec, AlignedMapVec &vec)
Definition: SGD.h:31