Skip to content

Instantly share code, notes, and snippets.

@kris-singh
Last active March 3, 2017 18:04
Show Gist options
  • Save kris-singh/e9ab5ebe4b54175fd860204d33e85597 to your computer and use it in GitHub Desktop.
Save kris-singh/e9ab5ebe4b54175fd860204d33e85597 to your computer and use it in GitHub Desktop.
template<typename DecomposableFunctionType, typename DecayType = SomeValue>
class SGD
{
...
...
...
...
private:
...
}
---------------------------------------------------------------------------------------
Policy Class
---------------------------------------------------------------------------------------
/**
* Implementation of the NoDecaySGD Policy
*/
class NoDecay
{
public:
NoDecay(){}
/**
* Decay the learning rate based on the policy
*
* @param stepSize: Step size of SGD
* @param decay_rate: Decay rate for the step size
* @param decay_step_size: Step size for the step policy
* @param iteration: Iteration index
*/
inline double decay_learning_rate(double stepSize,
double decay_rate,
int decay_step_size,
int iteration);
{
return stepSize;
}
};//similarly i have implement 3 other policies
----------------------------------------------------------------------------------
sgd_impl.hpp
----------------------------------------------------------------------------------
template<typename DecomposableFunctionType, typename DecayType = SomeValue>
SGD<DecomposableFunctionType>::SGD(DecomposableFunctionType& function,
...
...
{
using DecayType::decay_learning_rate;
...
...
stepSize = decay_learning_rate(stepSize, decay_rate, decay_step_size, i)
iterate -= stepSize * gradient;
...
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment