Skip to content

Commit efdf457

Browse files
Upgrade ensmallen to 2.21.0 (#62)
* Upgrade ensmallen to 2.21.0 * Add news --------- Co-authored-by: coatless <[email protected]> Co-authored-by: James J Balamuta <[email protected]>
1 parent 7f7d719 commit efdf457

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+686
-375
lines changed

ChangeLog

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

310
* NEWS.md: Fixed redirected HTTP to HTTPS 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.20.0.1
3+
Version: 0.2.21.0.1
44
Authors@R: c(
55
person("James Joseph", "Balamuta", email = "[email protected]",
66
role = c("aut", "cre", "cph"),

NEWS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# RcppEnsmallen 0.2.21.0.1
2+
3+
- Upgraded to ensmallen 2.21.0: "Stripped Bolt Head" (2023-11-27)
4+
- Clarify return values for different callback types
5+
([#383](https://github.com/mlpack/ensmallen/pull/383)).
6+
- Fix return types of callbacks
7+
([#382](https://github.com/mlpack/ensmallen/pull/382)).
8+
- Minor cleanup for printing optimization reports via `Report()`
9+
([#385](https://github.com/mlpack/ensmallen/pull/385)).
10+
- Updated vignettes to account for R 4.0.0 change. ([#61](https://github.com/coatless-rpkg/rcppensmallen/pull/61))
11+
- Added pkgdown website URL to DESCRIPTION.
12+
113
# RcppEnsmallen 0.2.20.0.1
214

315
- Upgraded to ensmallen 2.20.0: "Eight Ball Deluxe" (2023-10-05)

inst/include/ensmallen_bits/aug_lagrangian/aug_lagrangian_impl.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ AugLagrangian::Optimize(
117117
for (size_t i = 0; i < function.NumConstraints(); i++)
118118
{
119119
const ElemType p = std::pow(function.EvaluateConstraint(i, coordinates), 2);
120-
Callback::EvaluateConstraint(*this, function, coordinates, i, p,
121-
callbacks...);
120+
terminate |= Callback::EvaluateConstraint(*this, function, coordinates, i,
121+
p, callbacks...);
122122

123123
penalty += p;
124124
}
@@ -129,8 +129,7 @@ AugLagrangian::Optimize(
129129
// The odd comparison allows user to pass maxIterations = 0 (i.e. no limit on
130130
// number of iterations).
131131
size_t it;
132-
terminate |= Callback::BeginOptimization(*this, function, coordinates,
133-
callbacks...);
132+
Callback::BeginOptimization(*this, function, coordinates, callbacks...);
134133
for (it = 0; it != (maxIterations - 1) && !terminate; it++)
135134
{
136135
Info << "AugLagrangian on iteration " << it
@@ -143,7 +142,7 @@ AugLagrangian::Optimize(
143142

144143
const ElemType objective = function.Evaluate(coordinates);
145144

146-
Callback::Evaluate(*this, function, coordinates, objective,
145+
terminate |= Callback::Evaluate(*this, function, coordinates, objective,
147146
callbacks...);
148147

149148
// Check if we are done with the entire optimization (the threshold we are
@@ -170,14 +169,17 @@ AugLagrangian::Optimize(
170169
{
171170
const ElemType p = std::pow(function.EvaluateConstraint(i, coordinates),
172171
2);
173-
Callback::EvaluateConstraint(*this, function, coordinates, i, p,
174-
callbacks...);
172+
terminate |= Callback::EvaluateConstraint(*this, function, coordinates, i,
173+
p, callbacks...);
175174

176175
penalty += p;
177176
}
178177

179-
Info << "Penalty is " << penalty << " (threshold "
180-
<< penaltyThreshold << ")." << std::endl;
178+
Info << "Penalty is " << penalty << " (threshold " << penaltyThreshold
179+
<< ")." << std::endl;
180+
181+
if (terminate)
182+
break;
181183

182184
if (penalty < penaltyThreshold) // We update lambda.
183185
{
@@ -186,8 +188,8 @@ AugLagrangian::Optimize(
186188
for (size_t i = 0; i < function.NumConstraints(); i++)
187189
{
188190
const ElemType p = function.EvaluateConstraint(i, coordinates);
189-
Callback::EvaluateConstraint(*this, function, coordinates, i, p,
190-
callbacks...);
191+
terminate |= Callback::EvaluateConstraint(*this, function, coordinates,
192+
i, p, callbacks...);
191193

192194
augfunc.Lambda()[i] -= augfunc.Sigma() * p;
193195
}

inst/include/ensmallen_bits/bigbatch_sgd/bigbatch_sgd_impl.hpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ BigBatchSGD<UpdatePolicyType>::Optimize(
104104
BaseGradType functionGradient(iterate.n_rows, iterate.n_cols);
105105
const size_t actualMaxIterations = (maxIterations == 0) ?
106106
std::numeric_limits<size_t>::max() : maxIterations;
107-
terminate |= Callback::BeginOptimization(*this, f, iterate, callbacks...);
107+
Callback::BeginOptimization(*this, f, iterate, callbacks...);
108108
for (size_t i = 0; i < actualMaxIterations && !terminate;
109109
/* incrementing done manually */)
110110
{
@@ -191,6 +191,9 @@ BigBatchSGD<UpdatePolicyType>::Optimize(
191191
}
192192
}
193193

194+
if (terminate)
195+
break;
196+
194197
instUpdatePolicy.As<InstUpdatePolicyType>().Update(f, stepSize, iterate,
195198
gradient, gB, vB, currentFunction, batchSize, effectiveBatchSize,
196199
reset);
@@ -229,9 +232,7 @@ BigBatchSGD<UpdatePolicyType>::Optimize(
229232
return overallObjective;
230233
}
231234

232-
if (std::abs(lastObjective - overallObjective) < tolerance ||
233-
Callback::BeginEpoch(*this, f, iterate, epoch, overallObjective,
234-
callbacks...))
235+
if (std::abs(lastObjective - overallObjective) < tolerance)
235236
{
236237
Info << "Big-batch SGD: minimized within tolerance " << tolerance
237238
<< "; terminating optimization." << std::endl;
@@ -240,6 +241,9 @@ BigBatchSGD<UpdatePolicyType>::Optimize(
240241
return overallObjective;
241242
}
242243

244+
terminate |= Callback::BeginEpoch(*this, f, iterate, epoch,
245+
overallObjective, callbacks...);
246+
243247
// Reset the counter variables.
244248
lastObjective = overallObjective;
245249
overallObjective = 0;
@@ -250,8 +254,11 @@ BigBatchSGD<UpdatePolicyType>::Optimize(
250254
}
251255
}
252256

253-
Info << "Big-batch SGD: maximum iterations (" << maxIterations << ") "
254-
<< "reached; terminating optimization." << std::endl;
257+
if (!terminate)
258+
{
259+
Info << "Big-batch SGD: maximum iterations (" << maxIterations << ") "
260+
<< "reached; terminating optimization." << std::endl;
261+
}
255262

256263
// Calculate final objective if exactObjective is set to true.
257264
if (exactObjective)
@@ -263,7 +270,9 @@ BigBatchSGD<UpdatePolicyType>::Optimize(
263270
const ElemType objective = f.Evaluate(iterate, i, effectiveBatchSize);
264271
overallObjective += objective;
265272

266-
Callback::Evaluate(*this, f, iterate, objective, callbacks...);
273+
// The optimization is finished, so we don't need to care what the
274+
// callback returns.
275+
(void) Callback::Evaluate(*this, f, iterate, objective, callbacks...);
267276
}
268277
}
269278

0 commit comments

Comments
 (0)