Skip to content

Commit 0096379

Browse files
authored
Upgrade ensmallen to 1.15.0 (#11)
* Upgrade ensmallen to 1.15.0 * Update NEWS entry for 1.15.0 * Bump package version * Add ChangeLog entry * Change order of initialization to address R CMD check issue. ../inst/include/ensmallen_bits/qhadam/qhadam_update.hpp:57:5: warning: field 'v2' will be initialized after field 'iteration' [-Wreorder] * Deletes all instances of `shuffle` from the `spsa` implementation ../inst/include/ensmallen_bits/spsa/spsa.hpp:120:8: warning: private field 'shuffle' is not used [-Wunused-private-field] bool shuffle; * Update with custom changes. * Add a changelog notice
1 parent 203630d commit 0096379

File tree

13 files changed

+503
-17
lines changed

13 files changed

+503
-17
lines changed

ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2019-05-20 James Balamuta <[email protected]>
2+
3+
* DESCRIPTION (Version, Date): Release 1.15.0
4+
5+
* NEWS.md: Update for Ensmallen release 1.15.0
6+
7+
* inst/include/ensmallen_bits/spsa: Removed unused `shuffle` parameter.
8+
9+
* inst/include/ensmallen_bits/qhadam/qhadam_update: Reorder parameter initialization.
10+
11+
* inst/include/ensmallen_bits: Upgraded to Ensmallen 1.15.0
12+
* inst/include/ensmallen.hpp: ditto
13+
114
2019-05-12 James Balamuta <[email protected]>
215

316
* DESCRIPTION (Version, Date): Release 1.14.4

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: RcppEnsmallen
22
Title: Header-Only C++ Mathematical Optimization Library for 'Armadillo'
3-
Version: 0.1.14.4.1
3+
Version: 0.1.15.0.1
44
Authors@R: c(
55
person("James Joseph", "Balamuta", email = "[email protected]",
66
role = c("aut", "cre", "cph"),

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# RcppEnsmallen 0.1.15.0.1
2+
3+
- Upgraded to ensmallen release 1.15.0 "Wrong Side Of The Road" (2019-05-14)
4+
- Added QHAdam and QHSGD optimizers ([#81](https://github.com/mlpack/ensmallen/pull/81)).
5+
- Fix `-Wreorder` in `qhadam` warning ([#115](https://github.com/mlpack/ensmallen/pull/115)).
6+
- Fix `-Wunused-private-field` warning in `spsa` ([#115](https://github.com/mlpack/ensmallen/pull/115)).
7+
18
# RcppEnsmallen 0.1.14.4.1
29

310
- Upgraded to ensmallen release 1.14.4 "Difficult Crimp" (2019-05-12)

inst/include/ensmallen.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "ensmallen_bits/ada_delta/ada_delta.hpp"
6565
#include "ensmallen_bits/ada_grad/ada_grad.hpp"
6666
#include "ensmallen_bits/adam/adam.hpp"
67+
#include "ensmallen_bits/qhadam/qhadam.hpp"
6768
#include "ensmallen_bits/aug_lagrangian/aug_lagrangian.hpp"
6869
#include "ensmallen_bits/bigbatch_sgd/bigbatch_sgd.hpp"
6970
#include "ensmallen_bits/cmaes/cmaes.hpp"

inst/include/ensmallen_bits/adam/adam.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* for first-order gradient-based optimization of stochastic objective
1212
* functions, based on adaptive estimates of lower-order moments. AdaMax is
1313
* simply a variant of Adam based on the infinity norm. AMSGrad is another
14-
* variant of Adam with guaranteed convergence. Nadam is another variant of
14+
* variant of Adam with guaranteed convergence. Nadam is another variant of
1515
* Adam based on NAG. NadaMax is a variant for Nadam based on Infinity form.
1616
*
1717
* ensmallen is free software; you may redistribute it and/or modify it under

inst/include/ensmallen_bits/ens_version.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
#define ENS_VERSION_MAJOR 1
1616
// The minor version is two digits so regular numerical comparisons of versions
1717
// work right. The first minor version of a release is always 10.
18-
#define ENS_VERSION_MINOR 14
19-
#define ENS_VERSION_PATCH 4
18+
#define ENS_VERSION_MINOR 15
19+
#define ENS_VERSION_PATCH 0
2020
// If this is a release candidate, it will be reflected in the version name
2121
// (i.e. the version name will be "RC1", "RC2", etc.). Otherwise the version
2222
// name will typically be a seemingly arbitrary set of words that does not
2323
// contain the capitalized string "RC".
24-
#define ENS_VERSION_NAME "Difficult Crimp"
24+
#define ENS_VERSION_NAME "Wrong Side Of The Road"
2525

2626
namespace ens {
2727

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/**
2+
* @file qhadam.hpp
3+
* @author Niteya Shah
4+
*
5+
* Class wrapper for the QHAdam update Policy. QHAdam is a variant of the Adam
6+
* based on quasi hyperbolic moments.
7+
*
8+
* ensmallen is free software; you may redistribute it and/or modify it under
9+
* the terms of the 3-clause BSD license. You should have received a copy of
10+
* the 3-clause BSD license along with ensmallen. If not, see
11+
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
12+
*/
13+
#ifndef ENSMALLEN_ADAM_QHADAM_HPP
14+
#define ENSMALLEN_ADAM_QHADAM_HPP
15+
16+
#include <ensmallen_bits/sgd/sgd.hpp>
17+
#include "qhadam_update.hpp"
18+
19+
namespace ens {
20+
21+
/**
22+
* QHadam is an variation of Adam with Quasi-Hyperbolic step. It can be
23+
* a weighted mean of the momentum step. Due to its paramterisation it can
24+
* recover many other optimisation strategies.
25+
*
26+
* For more information, see the following.
27+
*
28+
* @code
29+
* @inproceedings{ma2019qh,
30+
* title={Quasi-hyperbolic momentum and Adam for deep learning},
31+
* author={Jerry Ma and Denis Yarats},
32+
* booktitle={International Conference on Learning Representations},
33+
* year={2019}
34+
* }
35+
* @endcode
36+
*
37+
* QHAdam can optimize differentiable separable functions. For more details,
38+
* see the documentation on function types included with this distribution or
39+
* on the ensmallen website.
40+
*/
41+
class QHAdam
42+
{
43+
public:
44+
/**
45+
* Construct the QHAdam optimizer with the given function and parameters.
46+
* QHAdam is sensitive to its paramters and hence a good hyper paramater
47+
* selection is necessary as its default may not fit every case.
48+
*
49+
* The maximum number of iterations refers to the maximum number of
50+
* points that are processed (i.e., one iteration equals one point; one
51+
* iteration does not equal one pass over the dataset).
52+
*
53+
* @param stepSize Step size for each iteration.
54+
* @param batchSize Number of points to process in a single step.
55+
* @param v1 The first quasi-hyperbolic term.
56+
* @param v1 The second quasi-hyperbolic term.
57+
* @param beta1 Exponential decay rate for the first moment estimates.
58+
* @param beta2 Exponential decay rate for the weighted infinity norm
59+
* estimates.
60+
* @param epsilon Value used to initialise the mean squared gradient
61+
* parameter.
62+
* @param maxIterations Maximum number of iterations allowed (0 means no
63+
* limit).
64+
* @param tolerance Maximum absolute tolerance to terminate algorithm.
65+
* @param shuffle If true, the function order is shuffled; otherwise, each
66+
* function is visited in linear order.
67+
* @param resetPolicy If true, parameters are reset before every Optimize
68+
* call; otherwise, their values are retained.
69+
*/
70+
QHAdam(const double stepSize = 0.001,
71+
const size_t batchSize = 32,
72+
const double v1 = 0.7,
73+
const double v2 = 1,
74+
const double beta1 = 0.9,
75+
const double beta2 = 0.999,
76+
const double epsilon = 1e-8,
77+
const size_t maxIterations = 100000,
78+
const double tolerance = 1e-5,
79+
const bool shuffle = true,
80+
const bool resetPolicy = true);
81+
82+
/**
83+
* Optimize the given function using QHAdam. The given starting point will be
84+
* modified to store the finishing point of the algorithm, and the final
85+
* objective value is returned.
86+
*
87+
* @tparam DecomposableFunctionType Type of the function to optimize.
88+
* @param function Function to optimize.
89+
* @param iterate Starting point (will be modified).
90+
* @return Objective value of the final point.
91+
*/
92+
template<typename DecomposableFunctionType>
93+
double Optimize(DecomposableFunctionType& function, arma::mat& iterate)
94+
{
95+
return optimizer.Optimize(function, iterate);
96+
}
97+
98+
//! Get the step size.
99+
double StepSize() const { return optimizer.StepSize(); }
100+
//! Modify the step size.
101+
double& StepSize() { return optimizer.StepSize(); }
102+
103+
//! Get the batch size.
104+
size_t BatchSize() const { return optimizer.BatchSize(); }
105+
//! Modify the batch size.
106+
size_t& BatchSize() { return optimizer.BatchSize(); }
107+
108+
//! Get the smoothing parameter.
109+
double Beta1() const { return optimizer.UpdatePolicy().Beta1(); }
110+
//! Modify the smoothing parameter.
111+
double& Beta1() { return optimizer.UpdatePolicy().Beta1(); }
112+
113+
//! Get the second moment coefficient.
114+
double Beta2() const { return optimizer.UpdatePolicy().Beta2(); }
115+
//! Modify the second moment coefficient.
116+
double& Beta2() { return optimizer.UpdatePolicy().Beta2(); }
117+
118+
//! Get the value used to initialise the mean squared gradient parameter.
119+
double Epsilon() const { return optimizer.UpdatePolicy().Epsilon(); }
120+
//! Modify the value used to initialise the mean squared gradient parameter.
121+
double& Epsilon() { return optimizer.UpdatePolicy().Epsilon(); }
122+
123+
//! Get the maximum number of iterations (0 indicates no limit).
124+
size_t MaxIterations() const { return optimizer.MaxIterations(); }
125+
//! Modify the maximum number of iterations (0 indicates no limit).
126+
size_t& MaxIterations() { return optimizer.MaxIterations(); }
127+
128+
//! Get the tolerance for termination.
129+
double Tolerance() const { return optimizer.Tolerance(); }
130+
//! Modify the tolerance for termination.
131+
double& Tolerance() { return optimizer.Tolerance(); }
132+
133+
//! Get whether or not the individual functions are shuffled.
134+
bool Shuffle() const { return optimizer.Shuffle(); }
135+
//! Modify whether or not the individual functions are shuffled.
136+
bool& Shuffle() { return optimizer.Shuffle(); }
137+
138+
//! Get whether or not the update policy parameters are reset before
139+
//! Optimize call.
140+
bool ResetPolicy() const { return optimizer.ResetPolicy(); }
141+
//! Modify whether or not the update policy parameters
142+
//! are reset before Optimize call.
143+
bool& ResetPolicy() { return optimizer.ResetPolicy(); }
144+
145+
//! Get the first quasi hyperbolic parameter.
146+
double V1() const { return optimizer.UpdatePolicy().V1(); }
147+
//! Modify the first quasi hyperbolic parameter.
148+
double& V1() { return optimizer.UpdatePolicy().V1(); }
149+
150+
//! Get the second quasi hyperbolic parameter.
151+
double V2() const { return optimizer.UpdatePolicy().V2(); }
152+
//! Modify the second quasi hyperbolic parameter.
153+
double& V2() { return optimizer.UpdatePolicy().V2(); }
154+
155+
private:
156+
//! The Stochastic Gradient Descent object with QHAdam policy.
157+
SGD<QHAdamUpdate> optimizer;
158+
};
159+
160+
} // namespace ens
161+
162+
// Include implementation.
163+
#include "qhadam_impl.hpp"
164+
165+
#endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @file qhadam_impl.hpp
3+
* @author Niteya Shah
4+
*
5+
* Implementation of QHAdam class wrapper.
6+
*
7+
* ensmallen is free software; you may redistribute it and/or modify it under
8+
* the terms of the 3-clause BSD license. You should have received a copy of
9+
* the 3-clause BSD license along with ensmallen. If not, see
10+
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
11+
*/
12+
#ifndef ENSMALLEN_ADAM_QHADAM_IMPL_HPP
13+
#define ENSMALLEN_ADAM_QHADAM_IMPL_HPP
14+
15+
// In case it hasn't been included yet.
16+
#include "qhadam.hpp"
17+
18+
namespace ens {
19+
20+
inline QHAdam::QHAdam(
21+
const double stepSize,
22+
const size_t batchSize,
23+
const double v1,
24+
const double v2,
25+
const double beta1,
26+
const double beta2,
27+
const double epsilon,
28+
const size_t maxIterations,
29+
const double tolerance,
30+
const bool shuffle,
31+
const bool resetPolicy) :
32+
optimizer(stepSize,
33+
batchSize,
34+
maxIterations,
35+
tolerance,
36+
shuffle,
37+
QHAdamUpdate(epsilon, beta1, beta2, v1, v2),
38+
NoDecay(),
39+
resetPolicy)
40+
{ /* Nothing to do. */ }
41+
42+
} // namespace ens
43+
44+
#endif

0 commit comments

Comments
 (0)