Skip to content

Commit 059893e

Browse files
Upgrade ensmallen to 2.19.0 (#49)
Co-authored-by: coatless <[email protected]>
1 parent 86adefb commit 059893e

35 files changed

+1951
-213
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2022-04-11 James Balamuta <[email protected]>
2+
3+
* DESCRIPTION (Version): Release 2.19.0
4+
* NEWS.md: Update for Ensmallen release 2.19.0
5+
* inst/include/ensmallen_bits: Upgraded to Ensmallen 2.19.0
6+
* inst/include/ensmallen.hpp: ditto
7+
18
2022-02-18 James Balamuta <[email protected]>
29

310
* DESCRIPTION: Update URLs

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.2.18.2.1
3+
Version: 0.2.19.0.1
44
Authors@R: c(
55
person("James Joseph", "Balamuta", email = "[email protected]",
66
role = c("aut", "cre", "cph"),

NEWS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# RcppEnsmallen 0.2.19.0.1
2+
3+
- Upgraded to ensmallen 2.19.0: "Eight Ball Deluxe" (2022-04-11)
4+
- Added DemonSGD and DemonAdam optimizers
5+
([#211](https://github.com/mlpack/ensmallen/pull/211)).
6+
- Fix bug with Adam-like optimizers not resetting when `resetPolicy` is `true`.
7+
([#340](https://github.com/mlpack/ensmallen/pull/340)).
8+
- Add Yogi optimizer
9+
([#232](https://github.com/mlpack/ensmallen/pull/232)).
10+
- Add AdaBelief optimizer
11+
([#233](https://github.com/mlpack/ensmallen/pull/233)).
12+
- Add AdaSqrt optimizer
13+
([#234](https://github.com/mlpack/ensmallen/pull/234)).
14+
15+
- Bump check for minimum supported version of Armadillo
16+
([#342](https://github.com/mlpack/ensmallen/pull/342)).
17+
118
# RcppEnsmallen 0.2.18.2.1
219

320
- Upgraded to ensmallen 2.18.2: "Fairmount Bagel" (2022-02-14)

inst/include/ensmallen.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#error "please enable C++11/C++14 mode in your compiler"
3030
#endif
3131

32-
#if ((ARMA_VERSION_MAJOR < 8) || ((ARMA_VERSION_MAJOR == 8) && (ARMA_VERSION_MINOR < 400)))
33-
#error "need Armadillo version 8.400 or later"
32+
#if ((ARMA_VERSION_MAJOR < 9) || ((ARMA_VERSION_MAJOR == 9) && (ARMA_VERSION_MINOR < 800)))
33+
#error "need Armadillo version 9.800 or later"
3434
#endif
3535

3636
#include <cctype>
@@ -85,10 +85,14 @@
8585

8686
#include "ensmallen_bits/problems/problems.hpp" // TODO: should move to another place
8787

88+
#include "ensmallen_bits/ada_belief/ada_belief.hpp"
8889
#include "ensmallen_bits/ada_bound/ada_bound.hpp"
8990
#include "ensmallen_bits/ada_delta/ada_delta.hpp"
9091
#include "ensmallen_bits/ada_grad/ada_grad.hpp"
92+
#include "ensmallen_bits/ada_sqrt/ada_sqrt.hpp"
9193
#include "ensmallen_bits/adam/adam.hpp"
94+
#include "ensmallen_bits/demon_adam/demon_adam.hpp"
95+
#include "ensmallen_bits/demon_sgd/demon_sgd.hpp"
9296
#include "ensmallen_bits/qhadam/qhadam.hpp"
9397
#include "ensmallen_bits/aug_lagrangian/aug_lagrangian.hpp"
9498
#include "ensmallen_bits/bigbatch_sgd/bigbatch_sgd.hpp"
@@ -131,5 +135,6 @@
131135
#include "ensmallen_bits/svrg/svrg.hpp"
132136
#include "ensmallen_bits/swats/swats.hpp"
133137
#include "ensmallen_bits/wn_grad/wn_grad.hpp"
138+
#include "ensmallen_bits/yogi/yogi.hpp"
134139

135140
#endif
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/**
2+
* @file ada_belief.hpp
3+
* @author Marcus Edel
4+
*
5+
* Class wrapper for the AdaBelief update Policy. The intuition for AdaBelief is
6+
* to adapt the stepsize according to the "belief" in the current gradient
7+
* direction.
8+
*
9+
* ensmallen is free software; you may redistribute it and/or modify it under
10+
* the terms of the 3-clause BSD license. You should have received a copy of
11+
* the 3-clause BSD license along with ensmallen. If not, see
12+
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
13+
*/
14+
#ifndef ENSMALLEN_ADA_BELIEF_HPP
15+
#define ENSMALLEN_ADA_BELIEF_HPP
16+
17+
#include <ensmallen_bits/sgd/sgd.hpp>
18+
#include "ada_belief_update.hpp"
19+
20+
namespace ens {
21+
22+
/**
23+
* The intuition for AdaBelief is to adapt the stepsize according to the
24+
* "belief" in the current gradient direction. For more information, see the
25+
* following.
26+
*
27+
* @code
28+
* @misc{zhuang2020adabelief,
29+
* title = {AdaBelief Optimizer: Adapting Stepsizes by the Belief in
30+
* Observed Gradients},
31+
* author = {Juntang Zhuang and Tommy Tang and Sekhar Tatikonda and
32+
* Nicha Dvornek and Yifan Ding and Xenophon Papademetris
33+
* and James S. Duncan},
34+
* year = {2020},
35+
* eprint = {2010.07468},
36+
* archivePrefix = {arXiv},
37+
* }
38+
* @endcode
39+
*
40+
* AdaBelief can optimize differentiable separable functions. For more details,
41+
* see the documentation on function types included with this distribution or
42+
* on the ensmallen website.
43+
*/
44+
class AdaBelief
45+
{
46+
public:
47+
/**
48+
* Construct the AdaBelief optimizer with the given function and parameters.
49+
* AdaBelief is sensitive to its parameters and hence a good hyperparameter
50+
* selection is necessary as its default may not fit every case.
51+
*
52+
* The maximum number of iterations refers to the maximum number of
53+
* points that are processed (i.e., one iteration equals one point; one
54+
* iteration does not equal one pass over the dataset).
55+
*
56+
* @param stepSize Step size for each iteration.
57+
* @param batchSize Number of points to process in a single step.
58+
* @param beta1 The exponential decay rate for the 1st moment estimates.
59+
* @param beta2 The exponential decay rate for the 2nd moment estimates.
60+
* @param epsilon A small constant for numerical stability.
61+
* @param maxIterations Maximum number of iterations allowed (0 means no
62+
* limit).
63+
* @param tolerance Maximum absolute tolerance to terminate algorithm.
64+
* @param shuffle If true, the function order is shuffled; otherwise, each
65+
* function is visited in linear order.
66+
* @param resetPolicy If true, parameters are reset before every Optimize
67+
* call; otherwise, their values are retained.
68+
* @param exactObjective Calculate the exact objective (Default: estimate the
69+
* final objective obtained on the last pass over the data).
70+
*/
71+
AdaBelief(const double stepSize = 0.001,
72+
const size_t batchSize = 32,
73+
const double beta1 = 0.9,
74+
const double beta2 = 0.999,
75+
const double epsilon = 1e-12,
76+
const size_t maxIterations = 100000,
77+
const double tolerance = 1e-5,
78+
const bool shuffle = true,
79+
const bool resetPolicy = true,
80+
const bool exactObjective = false);
81+
82+
/**
83+
* Optimize the given function using AdaBelief. The given starting point will
84+
* be modified to store the finishing point of the algorithm, and the final
85+
* objective value is returned.
86+
*
87+
* @tparam SeparableFunctionType Type of the function to optimize.
88+
* @tparam MatType Type of matrix to optimize with.
89+
* @tparam GradType Type of matrix to use to represent function gradients.
90+
* @tparam CallbackTypes Types of callback functions.
91+
* @param function Function to optimize.
92+
* @param iterate Starting point (will be modified).
93+
* @param callbacks Callback functions.
94+
* @return Objective value of the final point.
95+
*/
96+
template<typename SeparableFunctionType,
97+
typename MatType,
98+
typename GradType,
99+
typename... CallbackTypes>
100+
typename std::enable_if<IsArmaType<GradType>::value,
101+
typename MatType::elem_type>::type
102+
Optimize(SeparableFunctionType& function,
103+
MatType& iterate,
104+
CallbackTypes&&... callbacks)
105+
{
106+
return optimizer.Optimize<SeparableFunctionType, MatType, GradType,
107+
CallbackTypes...>(function, iterate,
108+
std::forward<CallbackTypes>(callbacks)...);
109+
}
110+
111+
//! Forward the MatType as GradType.
112+
template<typename SeparableFunctionType,
113+
typename MatType,
114+
typename... CallbackTypes>
115+
typename MatType::elem_type Optimize(SeparableFunctionType& function,
116+
MatType& iterate,
117+
CallbackTypes&&... callbacks)
118+
{
119+
return Optimize<SeparableFunctionType, MatType, MatType,
120+
CallbackTypes...>(function, iterate,
121+
std::forward<CallbackTypes>(callbacks)...);
122+
}
123+
124+
//! Get the step size.
125+
double StepSize() const { return optimizer.StepSize(); }
126+
//! Modify the step size.
127+
double& StepSize() { return optimizer.StepSize(); }
128+
129+
//! Get the batch size.
130+
size_t BatchSize() const { return optimizer.BatchSize(); }
131+
//! Modify the batch size.
132+
size_t& BatchSize() { return optimizer.BatchSize(); }
133+
134+
//! Get the exponential decay rate for the 1st moment estimates.
135+
double Beta1() const { return optimizer.UpdatePolicy().Beta1(); }
136+
//! Modify the exponential decay rate for the 1st moment estimates.
137+
double& Beta1() { return optimizer.UpdatePolicy().Beta1(); }
138+
139+
//! Get the exponential decay rate for the 2nd moment estimates.
140+
double Beta2() const { return optimizer.UpdatePolicy().Beta2(); }
141+
//! Get the second moment coefficient.
142+
double& Beta2() { return optimizer.UpdatePolicy().Beta2(); }
143+
144+
//! Get the value for numerical stability.
145+
double Epsilon() const { return optimizer.UpdatePolicy().Epsilon(); }
146+
//! Modify the value used for numerical stability.
147+
double& Epsilon() { return optimizer.UpdatePolicy().Epsilon(); }
148+
149+
//! Get the maximum number of iterations (0 indicates no limit).
150+
size_t MaxIterations() const { return optimizer.MaxIterations(); }
151+
//! Modify the maximum number of iterations (0 indicates no limit).
152+
size_t& MaxIterations() { return optimizer.MaxIterations(); }
153+
154+
//! Get the tolerance for termination.
155+
double Tolerance() const { return optimizer.Tolerance(); }
156+
//! Modify the tolerance for termination.
157+
double& Tolerance() { return optimizer.Tolerance(); }
158+
159+
//! Get whether or not the individual functions are shuffled.
160+
bool Shuffle() const { return optimizer.Shuffle(); }
161+
//! Modify whether or not the individual functions are shuffled.
162+
bool& Shuffle() { return optimizer.Shuffle(); }
163+
164+
//! Get whether or not the actual objective is calculated.
165+
bool ExactObjective() const { return optimizer.ExactObjective(); }
166+
//! Modify whether or not the actual objective is calculated.
167+
bool& ExactObjective() { return optimizer.ExactObjective(); }
168+
169+
//! Get whether or not the update policy parameters are reset before
170+
//! Optimize call.
171+
bool ResetPolicy() const { return optimizer.ResetPolicy(); }
172+
//! Modify whether or not the update policy parameters
173+
//! are reset before Optimize call.
174+
bool& ResetPolicy() { return optimizer.ResetPolicy(); }
175+
176+
private:
177+
//! The Stochastic Gradient Descent object with AdaBelief policy.
178+
SGD<AdaBeliefUpdate> optimizer;
179+
};
180+
181+
} // namespace ens
182+
183+
// Include implementation.
184+
#include "ada_belief_impl.hpp"
185+
186+
#endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @file ada_belief_impl.hpp
3+
* @author Marcus Edel
4+
*
5+
* Implementation of AdaBelief 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_ADA_BELIEF_ADA_BELIEF_IMPL_HPP
13+
#define ENSMALLEN_ADA_BELIEF_ADA_BELIEF_IMPL_HPP
14+
15+
// In case it hasn't been included yet.
16+
#include "ada_belief.hpp"
17+
18+
namespace ens {
19+
20+
inline AdaBelief::AdaBelief(
21+
const double stepSize,
22+
const size_t batchSize,
23+
const double beta1,
24+
const double beta2,
25+
const double epsilon,
26+
const size_t maxIterations,
27+
const double tolerance,
28+
const bool shuffle,
29+
const bool resetPolicy,
30+
const bool exactObjective) :
31+
optimizer(stepSize,
32+
batchSize,
33+
maxIterations,
34+
tolerance,
35+
shuffle,
36+
AdaBeliefUpdate(epsilon, beta1, beta2),
37+
NoDecay(),
38+
resetPolicy,
39+
exactObjective)
40+
{ /* Nothing to do. */ }
41+
42+
} // namespace ens
43+
44+
#endif

0 commit comments

Comments
 (0)