12 #ifndef MLPACK_CORE_OPTIMIZERS_SGD_GRADIENT_CLIPPING_HPP 13 #define MLPACK_CORE_OPTIMIZERS_SGD_GRADIENT_CLIPPING_HPP 18 namespace optimization {
28 template<
typename UpdatePolicyType>
41 const double maxGradient,
42 UpdatePolicyType& updatePolicy) :
43 minGradient(minGradient),
44 maxGradient(maxGradient),
45 updatePolicy(updatePolicy)
60 updatePolicy.Initialize(rows, cols);
72 const double stepSize,
73 const arma::mat& gradient)
76 arma::mat clippedGradient = arma::clamp(gradient, minGradient, maxGradient);
78 updatePolicy.Update(iterate, stepSize, clippedGradient);
104 UpdatePolicyType updatePolicy;
void Initialize(const size_t rows, const size_t cols)
The Initialize method is called by SGD Optimizer method before the start of the iteration update proc...
double & MaxGradient()
Modify the maximum gradient value.
GradientClipping(const double minGradient, const double maxGradient, UpdatePolicyType &updatePolicy)
Constructor for creating a GradientClipping instance.
The core includes that mlpack expects; standard C++ includes and Armadillo.
Interface for wrapping around update policies (e.g., VanillaUpdate) and feeding a clipped gradient to...
double MinGradient() const
Get the minimum gradient value.
double MaxGradient() const
Get the maximum gradient value.
UpdatePolicyType & UpdatePolicy()
Modify the update policy.
double & MinGradient()
Modify the minimum gradient value.
UpdatePolicyType & UpdatePolicy() const
Get the update policy.
void Update(arma::mat &iterate, const double stepSize, const arma::mat &gradient)
Update step.