Minor style fixes (80 columns, clamp multiline, remove trailing spaces, comments).

This commit is contained in:
Marcus Edel
2017-04-23 23:33:54 +02:00
parent d7dc971b06
commit 504b02775c
14 changed files with 108 additions and 102 deletions
@@ -34,10 +34,10 @@ namespace optimization {
*
* @code
* @article{Zeiler2012,
* author = {Matthew D. Zeiler},
* title = {{ADADELTA:} An Adaptive Learning Rate Method},
* journal = {CoRR},
* year = {2012}
* author = {Matthew D. Zeiler},
* title = {{ADADELTA:} An Adaptive Learning Rate Method},
* journal = {CoRR},
* year = {2012}
* }
* @endcode
*
@@ -29,10 +29,10 @@ namespace optimization {
*
* @code
* @article{Zeiler2012,
* author = {Matthew D. Zeiler},
* title = {{ADADELTA:} An Adaptive Learning Rate Method},
* journal = {CoRR},
* year = {2012}
* author = {Matthew D. Zeiler},
* title = {{ADADELTA:} An Adaptive Learning Rate Method},
* journal = {CoRR},
* year = {2012}
* }
* @endcode
*
@@ -30,13 +30,13 @@ namespace optimization {
*
* @code
* @article{duchi2011adaptive,
* author = {Duchi, John and Hazan, Elad and Singer, Yoram},
* title = {Adaptive subgradient methods for online learning and stochastic optimization},
* journal = {Journal of Machine Learning Research},
* volume = {12},
* number = {Jul},
* pages = {2121--2159},
* year = {2011}
* author = {Duchi, John and Hazan, Elad and Singer, Yoram},
* title = {Adaptive subgradient methods for online learning and stochastic optimization},
* journal = {Journal of Machine Learning Research},
* volume = {12},
* number = {Jul},
* pages = {2121--2159},
* year = {2011}
* }
* @endcode
*
@@ -58,8 +58,8 @@ class AdaGradUpdate
* gradient matrix is initialized to the zeros matrix with the same size as
* gradient matrix (see mlpack::optimization::SGD::Optimizer).
*
* @param rows number of rows in the gradient matrix.
* @param cols number of columns in the gradient matrix.
* @param rows Number of rows in the gradient matrix.
* @param cols Number of columns in the gradient matrix.
*/
void Initialize(const size_t rows,
const size_t cols)
+12 -12
View File
@@ -37,11 +37,11 @@ namespace optimization {
*
* @code
* @article{Kingma2014,
* author = {Diederik P. Kingma and Jimmy Ba},
* title = {Adam: {A} Method for Stochastic Optimization},
* journal = {CoRR},
* year = {2014},
* url = {http://arxiv.org/abs/1412.6980}
* author = {Diederik P. Kingma and Jimmy Ba},
* title = {Adam: {A} Method for Stochastic Optimization},
* journal = {CoRR},
* year = {2014},
* url = {http://arxiv.org/abs/1412.6980}
* }
* @endcode
*
@@ -95,13 +95,13 @@ class AdamType
* function is visited in linear order.
*/
AdamType(DecomposableFunctionType& function,
const double stepSize = 0.001,
const double beta1 = 0.9,
const double beta2 = 0.999,
const double eps = 1e-8,
const size_t maxIterations = 100000,
const double tolerance = 1e-5,
const bool shuffle = true);
const double stepSize = 0.001,
const double beta1 = 0.9,
const double beta2 = 0.999,
const double eps = 1e-8,
const size_t maxIterations = 100000,
const double tolerance = 1e-5,
const bool shuffle = true);
/**
* Optimize the given function using Adam. The given starting point will be
@@ -31,11 +31,11 @@ namespace optimization {
*
* @code
* @article{Kingma2014,
* author = {Diederik P. Kingma and Jimmy Ba},
* title = {Adam: {A} Method for Stochastic Optimization},
* journal = {CoRR},
* year = {2014},
* url = {http://arxiv.org/abs/1412.6980}
* author = {Diederik P. Kingma and Jimmy Ba},
* title = {Adam: {A} Method for Stochastic Optimization},
* journal = {CoRR},
* year = {2014},
* url = {http://arxiv.org/abs/1412.6980}
* }
* @endcode
*/
@@ -65,8 +65,8 @@ class AdamUpdate
* The Initialize method is called by SGD Optimizer method before the start of
* the iteration update process.
*
* @param rows number of rows in the gradient matrix.
* @param cols number of columns in the gradient matrix.
* @param rows Number of rows in the gradient matrix.
* @param cols Number of columns in the gradient matrix.
*/
void Initialize(const size_t rows,
const size_t cols)
@@ -105,7 +105,7 @@ class AdamUpdate
* m / (arma::sqrt(v) + (arma::sqrt(biasCorrection2) * eps).
*/
iterate -= (stepSize * std::sqrt(biasCorrection2) / biasCorrection1) *
m / (arma::sqrt(v) + epsilon);
m / (arma::sqrt(v) + epsilon);
}
//! Get the value used to initialise the squared gradient parameter.
@@ -67,8 +67,8 @@ class AdaMaxUpdate
* The Initialize method is called by SGD Optimizer method before the start of
* the iteration update process.
*
* @param rows number of rows in the gradient matrix.
* @param cols number of columns in the gradient matrix.
* @param rows Number of rows in the gradient matrix.
* @param cols Number of columns in the gradient matrix.
*/
void Initialize(const size_t rows,
const size_t cols)
@@ -66,9 +66,9 @@ class GradientDescent
* @param tolerance Maximum absolute tolerance to terminate algorithm.
*/
GradientDescent(FunctionType& function,
const double stepSize = 0.01,
const size_t maxIterations = 100000,
const double tolerance = 1e-5);
const double stepSize = 0.01,
const size_t maxIterations = 100000,
const double tolerance = 1e-5);
/**
* Optimize the given function using gradient descent. The given starting
@@ -38,9 +38,9 @@ namespace optimization {
*
* @code
* @misc{tieleman2012,
* title={Lecture 6.5 - rmsprop, COURSERA: Neural Networks for Machine
* Learning},
* year={2012}
* title = {Lecture 6.5 - rmsprop, COURSERA: Neural Networks for Machine
* Learning},
* year = {2012}
* }
* @endcode
*
@@ -35,9 +35,9 @@ namespace optimization {
*
* @code
* @misc{tieleman2012,
* title={Lecture 6.5 - rmsprop, COURSERA: Neural Networks for Machine
* Learning},
* year={2012}
* title = {Lecture 6.5 - rmsprop, COURSERA: Neural Networks for Machine
* Learning},
* year = {2012}
* }
* @endcode
*/
@@ -63,8 +63,8 @@ class RMSPropUpdate
* The Initialize method is called by SGD Optimizer method before the start of
* the iteration update process.
*
* @param rows number of rows in the gradient matrix.
* @param cols number of columns in the gradient matrix.
* @param rows Number of rows in the gradient matrix.
* @param cols Number of columns in the gradient matrix.
*/
void Initialize(const size_t rows,
const size_t cols)
@@ -86,7 +86,8 @@ class RMSPropUpdate
{
meanSquaredGradient *= alpha;
meanSquaredGradient += (1 - alpha) * (gradient % gradient);
iterate -= stepSize * gradient / (arma::sqrt(meanSquaredGradient) + epsilon);
iterate -= stepSize * gradient / (arma::sqrt(meanSquaredGradient) +
epsilon);
}
//! Get the value used to initialise the squared gradient parameter.
@@ -42,23 +42,23 @@ namespace optimization {
*
* @code
* @article{rumelhart1988learning,
* title={Learning representations by back-propagating errors},
* author={Rumelhart, David E. and Hinton, Geoffrey E. and
* Williams, Ronald J.},
* journal={Cognitive Modeling},
* volume={5},
* number={3},
* pages={1},
* year={1988}
* title = {Learning representations by back-propagating errors},
* author = {Rumelhart, David E. and Hinton, Geoffrey E. and
* Williams, Ronald J.},
* journal = {Cognitive Modeling},
* volume = {5},
* number = {3},
* pages = {1},
* year = {1988}
* }
*
* @code
* @book{Goodfellow-et-al-2016,
* title={Deep Learning},
* author={Ian Goodfellow and Yoshua Bengio and Aaron Courville},
* publisher={MIT Press},
* note={\url{http://www.deeplearningbook.org}},
* year={2016}
* title = {Deep Learning},
* author = {Ian Goodfellow and Yoshua Bengio and Aaron Courville},
* publisher = {MIT Press},
* note = {\url{http://www.deeplearningbook.org}},
* year = {2016}
* }
*/
class MomentumUpdate
@@ -78,14 +78,14 @@ class MomentumUpdate
* matrix is initialized to the zeros matrix with the same size as the
* gradient matrix (see mlpack::optimization::SGD::Optimizer )
*
* @param n_rows number of rows in the gradient matrix.
* @param n_cols number of columns in the gradient matrix.
* @param rows Number of rows in the gradient matrix.
* @param cols Number of columns in the gradient matrix.
*/
void Initialize(const size_t n_rows,
const size_t n_cols)
void Initialize(const size_t rows,
const size_t cols)
{
//Initialize am empty velocity matrix.
velocity = arma::zeros<arma::mat>(n_rows, n_cols);
velocity = arma::zeros<arma::mat>(rows, cols);
}
/**
@@ -36,10 +36,10 @@ class VanillaUpdate
* the iteration update process. The vanilla update doesn't initialize
* anything.
*
* @param n_rows number of rows in the gradient matrix.
* @param n_cols number of columns in the gradient matrix.
* @param rows Number of rows in the gradient matrix.
* @param cols Number of columns in the gradient matrix.
*/
void Initialize(const size_t /* n_rows */, const size_t /* n_cols */)
void Initialize(const size_t /* rows */, const size_t /* cols */)
{ /* Do nothing. */ }
/**
+19 -15
View File
@@ -31,16 +31,16 @@ namespace optimization {
*
* @code
* @misc{Funk2015,
* author = {Simon Funk},
* title = {RMSprop loses to SMORMS3 - Beware the Epsilon!},
* year = {2015}
* url = {http://sifter.org/~simon/journal/20150420.html}
* author = {Simon Funk},
* title = {RMSprop loses to SMORMS3 - Beware the Epsilon!},
* year = {2015}
* url = {http://sifter.org/~simon/journal/20150420.html}
* }
* @endcode
*
*
* For SMORMS3 to work, a DecomposableFunctionType template parameter is required.
* This class must implement the following function:
* For SMORMS3 to work, a DecomposableFunctionType template parameter is
* required. This class must implement the following function:
*
* size_t NumFunctions();
* double Evaluate(const arma::mat& coordinates, const size_t i);
@@ -57,7 +57,7 @@ namespace optimization {
* is held internally in the DecomposableFunctionType).
*
* @tparam DecomposableFunctionType Decomposable objective function type to be
* minimized.
* minimized.
*/
template<typename DecomposableFunctionType>
class SMORMS3
@@ -73,7 +73,8 @@ class SMORMS3
*
* @param function Function to be optimized (minimized).
* @param stepSize Step size for each iteration.
* @param epsilon Value used to initialise the mean squared gradient parameter.
* @param epsilon Value used to initialise the mean squared gradient
* parameter.
* @param maxIterations Maximum number of iterations allowed (0 means no
* limit).
* @param tolerance Maximum absolute tolerance to terminate algorithm.
@@ -81,14 +82,14 @@ class SMORMS3
* function is visited in linear order.
*/
SMORMS3(DecomposableFunctionType& function,
const double stepSize = 0.001,
const double epsilon = 1e-16,
const size_t maxIterations = 100000,
const double tolerance = 1e-5,
const bool shuffle = true);
const double stepSize = 0.001,
const double epsilon = 1e-16,
const size_t maxIterations = 100000,
const double tolerance = 1e-5,
const bool shuffle = true);
/**
* Optimize the given function using SMORMS3. The given starting point will
* Optimize the given function using SMORMS3. The given starting point will
* be modified to store the finishing point of the algorithm, and the final
* objective value is returned.
*
@@ -98,7 +99,10 @@ class SMORMS3
double Optimize(arma::mat& iterate) { return optimizer.Optimize(iterate); }
//! Get the instantiated function to be optimized.
const DecomposableFunctionType& Function() const { return optimizer.Function(); }
const DecomposableFunctionType& Function() const
{
return optimizer.Function();
}
//! Modify the instantiated function.
DecomposableFunctionType& Function() { return optimizer.Function(); }
@@ -26,10 +26,10 @@ namespace optimization {
*
* @code
* @misc{Funk2015,
* author = {Simon Funk},
* title = {RMSprop loses to SMORMS3 - Beware the Epsilon!},
* year = {2015}
* url = {http://sifter.org/~simon/journal/20150420.html}
* author = {Simon Funk},
* title = {RMSprop loses to SMORMS3 - Beware the Epsilon!},
* year = {2015}
* url = {http://sifter.org/~simon/journal/20150420.html}
* }
* @endcode
*/
@@ -40,23 +40,18 @@ class SMORMS3Update
/**
* Construct the SMORMS3 update policy with given epsilon parameter.
*
* @param epsilon Value used to initialise the mean squared gradient parameter.
* @param epsilon Value used to initialise the mean squared gradient
* parameter.
*/
SMORMS3Update(const double epsilon = 1e-16) :
epsilon(epsilon)
SMORMS3Update(const double epsilon = 1e-16) : epsilon(epsilon)
{ /* Do nothing. */ }
//! Get the value used to initialise the mean squared gradient parameter.
double Epsilon() const { return epsilon; }
//! Modify the value used to initialise the mean squared gradient parameter.
double& Epsilon() { return epsilon; }
/**
* The Initialize method is called by SGD::Optimize method with UpdatePolicy
* SMORMS3Update before the start of the iteration update process.
*
* @param rows number of rows in the gradient matrix.
* @param cols number of columns in the gradient matrix.
* @param rows Number of rows in the gradient matrix.
* @param cols Number of columns in the gradient matrix.
*/
void Initialize(const size_t rows,
const size_t cols)
@@ -96,10 +91,16 @@ class SMORMS3Update
mem %= (1 - x);
mem += 1;
}
//! Get the value used to initialise the mean squared gradient parameter.
double Epsilon() const { return epsilon; }
//! Modify the value used to initialise the mean squared gradient parameter.
double& Epsilon() { return epsilon; }
private:
//! The value used to initialise the mean squared gradient parameter.
double epsilon;
// The parameters mem, g and g2.
arma::mat mem, g, g2;
};