MachineIntelligenceCore:NeuralNets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
GradientDescent.hpp
Go to the documentation of this file.
1 
25 #ifndef GRADIENTDESCENT_HPP_
26 #define GRADIENTDESCENT_HPP_
27 
29 
30 namespace mic {
31 namespace neural_nets {
32 namespace optimization {
33 
38 template <typename eT=float>
40 public:
41 
47  GradientDescent(size_t rows_, size_t cols_) {
48  // Allocate and reset delta.
49  delta = MAKE_MATRIX_PTR(eT, rows_, cols_);
50  delta->zeros();
51  }
52 
59  mic::types::MatrixPtr<eT> calculateUpdate(mic::types::MatrixPtr<eT> x_, mic::types::MatrixPtr<eT> dx_, eT learning_rate_ = 0.001) {
60  assert(x_->size() == dx_->size());
61  // daltea = - alpha * dW.
62  //for (size_t i=0; i<(size_t)x_->size(); i++)
63  (*delta) = learning_rate_ * (*dx_);
64 
65  // Return the update.
66  return delta;
67  }
68 
69 private:
71  mic::types::MatrixPtr<eT> delta;
72 
73 };
74 
75 } //: optimization
76 } //: neural_nets
77 } //: mic
78 
79 #endif /* GRADIENTDESCENT_HPP_ */
Abstract class representing interface to optimization function.
mic::types::MatrixPtr< eT > calculateUpdate(mic::types::MatrixPtr< eT > x_, mic::types::MatrixPtr< eT > dx_, eT learning_rate_=0.001)
Update in the direction of gradient descent.
mic::types::MatrixPtr< eT > delta
Calculated update.