Fixed cppcheck issues + removing legacy code
This commit is contained in:
@@ -163,7 +163,7 @@ class MiniBatchSGDType
|
||||
bool ResetPolicy() const { return resetPolicy; }
|
||||
//! Modify whether or not the update policy parameters
|
||||
//! are reset before Optimize call.
|
||||
bool& ResetPolicy() { return resetPolicy; }
|
||||
bool& ResetPolicy() { return resetPolicy; }
|
||||
|
||||
//! Get the update policy.
|
||||
UpdatePolicyType UpdatePolicy() const { return updatePolicy; }
|
||||
@@ -211,4 +211,4 @@ using MiniBatchSGD = MiniBatchSGDType<VanillaUpdate, NoDecay>;
|
||||
// Include implementation.
|
||||
#include "minibatch_sgd_impl.hpp"
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -182,4 +182,4 @@ double MiniBatchSGDType<
|
||||
} // namespace optimization
|
||||
} // namespace mlpack
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -108,10 +108,7 @@ class SGD
|
||||
const double tolerance = 1e-5,
|
||||
const bool shuffle = true,
|
||||
const UpdatePolicyType updatePolicy = UpdatePolicyType(),
|
||||
const bool resetPolicy = true,
|
||||
const bool clipGradient = false,
|
||||
const double minGradient = 0.0,
|
||||
const double maxGradient = 0.0);
|
||||
const bool resetPolicy = true);
|
||||
|
||||
/**
|
||||
* Optimize the given function using stochastic gradient descent. The given
|
||||
@@ -154,21 +151,6 @@ class SGD
|
||||
//! are reset before Optimize call.
|
||||
bool& ResetPolicy() { return resetPolicy; }
|
||||
|
||||
//! Get whether or not the gradient is clipped.
|
||||
bool ClipGradient() const { return clipGradient; }
|
||||
//! Modify whether or not the gradient is clipped.
|
||||
bool& ClipGradient() { return clipGradient; }
|
||||
|
||||
//! Get minimum gradient value.
|
||||
double MinGradient() const { return minGradient; }
|
||||
//! Modify minimum gradient value.
|
||||
double& MinGradient() { return minGradient; }
|
||||
|
||||
//! Get maximum gradient value.
|
||||
double MaxGradient() const { return maxGradient; }
|
||||
//! Modify maximum gradient value.
|
||||
double& MaxGradient() { return maxGradient; }
|
||||
|
||||
//! Get the update policy.
|
||||
UpdatePolicyType UpdatePolicy() const { return updatePolicy; }
|
||||
//! Modify the update policy.
|
||||
@@ -194,16 +176,6 @@ class SGD
|
||||
//! Flag indicating whether update policy
|
||||
//! should be reset before running optimization.
|
||||
bool resetPolicy;
|
||||
|
||||
//! Flag that determines whether gradient should be clipped
|
||||
//! to some range before every SGD step.
|
||||
bool clipGradient;
|
||||
|
||||
//! Minimum gradient value.
|
||||
double minGradient;
|
||||
|
||||
//! Maximum gradient value.
|
||||
double maxGradient;
|
||||
};
|
||||
|
||||
using StandardSGD = SGD<VanillaUpdate>;
|
||||
@@ -216,4 +188,4 @@ using MomentumSGD = SGD<MomentumUpdate>;
|
||||
// Include implementation.
|
||||
#include "sgd_impl.hpp"
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -30,19 +30,13 @@ SGD<UpdatePolicyType>::SGD(
|
||||
const double tolerance,
|
||||
const bool shuffle,
|
||||
const UpdatePolicyType updatePolicy,
|
||||
const bool resetPolicy,
|
||||
const bool clipGradient,
|
||||
const double minGradient,
|
||||
const double maxGradient) :
|
||||
const bool resetPolicy) :
|
||||
stepSize(stepSize),
|
||||
maxIterations(maxIterations),
|
||||
tolerance(tolerance),
|
||||
shuffle(shuffle),
|
||||
updatePolicy(updatePolicy),
|
||||
resetPolicy(resetPolicy),
|
||||
clipGradient(clipGradient),
|
||||
minGradient(minGradient),
|
||||
maxGradient(maxGradient)
|
||||
resetPolicy(resetPolicy)
|
||||
{ /* Nothing to do. */ }
|
||||
|
||||
//! Optimize the function (minimize).
|
||||
@@ -116,18 +110,6 @@ double SGD<UpdatePolicyType>::Optimize(
|
||||
else
|
||||
function.Gradient(iterate, currentFunction, gradient);
|
||||
|
||||
// Clip the gradient.
|
||||
if (clipGradient)
|
||||
{
|
||||
gradient.transform
|
||||
(
|
||||
[&](double val)
|
||||
{
|
||||
return std::min(std::max(val, minGradient), maxGradient);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Use the update policy to take a step.
|
||||
updatePolicy.Update(iterate, stepSize, gradient);
|
||||
|
||||
@@ -156,4 +138,4 @@ double SGD<UpdatePolicyType>::Optimize(
|
||||
} // namespace optimization
|
||||
} // namespace mlpack
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -73,13 +73,9 @@ class GradientClipping
|
||||
const arma::mat& gradient)
|
||||
{
|
||||
// First, clip the gradient.
|
||||
gradient.transform
|
||||
(
|
||||
[&](double val)
|
||||
{
|
||||
return std::min(std::max(val, minGradient), maxGradient);
|
||||
}
|
||||
);
|
||||
gradient.transform(
|
||||
[&](double val)
|
||||
{ return std::min(std::max(val, minGradient), maxGradient); });
|
||||
// And only then do the update.
|
||||
updatePolicy.Update(iterate, stepSize, gradient);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user