Skip to content

Commit 8101425

Browse files
Upgrade ensmallen to 2.21.1 (#64)
Co-authored-by: coatless <[email protected]>
1 parent 394c439 commit 8101425

File tree

9 files changed

+72
-38
lines changed

9 files changed

+72
-38
lines changed

ChangeLog

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

310
* DESCRIPTION (Version): Release 2.21.0

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

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# RcppEnsmallen 0.2.21.1.1
2+
3+
- Upgraded to ensmallen 2.21.1: "Bent Antenna" (2024-02-16)
4+
- Fix numerical precision issues for small-gradient L-BFGS scaling factor
5+
computations ([#392](https://github.com/mlpack/ensmallen/pull/392)).
6+
- Ensure the tests are built with optimisation enabled
7+
([#394](https://github.com/mlpack/ensmallen/pull/394)).
8+
19
# RcppEnsmallen 0.2.21.0.1
210

311
- Upgraded to ensmallen 2.21.0: "Stripped Bolt Head" (2023-11-27)

inst/include/ensmallen_bits/aug_lagrangian/aug_lagrangian_impl.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,8 @@ AugLagrangian::Optimize(
136136
<< ", starting with objective " << lastObjective << "." << std::endl;
137137

138138
if (!lbfgs.Optimize(augfunc, coordinates, callbacks...))
139-
Info << "L-BFGS reported an error during optimization."
140-
<< std::endl;
141-
Info << "Done with L-BFGS: " << coordinates << "\n";
139+
Info << "L-BFGS reported an error during optimization." << std::endl;
140+
Info << "Done with L-BFGS." << std::endl;
142141

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

inst/include/ensmallen_bits/callbacks/query_front.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class QueryFront
4848
typename MatType,
4949
typename ObjectivesVecType,
5050
typename IndicesType>
51-
bool GenerationalStepTaken(OptimizerType& opt,
51+
bool GenerationalStepTaken(OptimizerType& /* opt */,
5252
FunctionType& /* function */,
5353
const MatType& /* coordinates */,
5454
const ObjectivesVecType& objectives,

inst/include/ensmallen_bits/cmaes/not_empty_transformation.hpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,34 @@
99
* the 3-clause BSD license along with ensmallen. If not, see
1010
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
1111
*/
12-
#ifndef NOT_EMPTY_TRANSFORMATION
13-
#define NOT_EMPTY_TRANSFORMATION
12+
#ifndef ENSMALLEN_CMAES_NOT_EMPTY_TRANSFORMATION
13+
#define ENSMALLEN_CMAES_NOT_EMPTY_TRANSFORMATION
1414

15-
/*
16-
This partial specialization is used to throw an exception when the
17-
TransformationPolicyType is EmptyTransformation and call a
18-
constructor with parameters 'lowerBound' and 'upperBound' otherwise.
19-
This shall be removed when the deprecated constructor is removed in
20-
the next major version of ensmallen.
15+
/**
16+
* This partial specialization is used to throw an exception when the
17+
* TransformationPolicyType is EmptyTransformation and call a constructor with
18+
* parameters 'lowerBound' and 'upperBound' otherwise. This shall be removed
19+
* when the deprecated constructor is removed in the next major version of
20+
* ensmallen.
2121
*/
2222
template<typename T1, typename T2>
23-
struct NotEmptyTransformation : std::true_type {
24-
void Assign(T1& obj, double lowerBound, double upperBound) {
23+
struct NotEmptyTransformation : std::true_type
24+
{
25+
void Assign(T1& obj, double lowerBound, double upperBound)
26+
{
2527
obj = T1(lowerBound, upperBound);
2628
}
2729
};
2830

2931
template<template<typename...> class T, typename... A, typename... B>
30-
struct NotEmptyTransformation<T<A...>, T<B...>> : std::false_type {
31-
void Assign(T<A...>& obj, double lowerBound, double upperBound) {
32+
struct NotEmptyTransformation<T<A...>, T<B...>> : std::false_type
33+
{
34+
void Assign(T<A...>& /* obj */,
35+
double /* lowerBound */,
36+
double /* upperBound */)
37+
{
3238
throw std::logic_error("TransformationPolicyType is EmptyTransformation");
3339
}
3440
};
3541

36-
#endif
42+
#endif

inst/include/ensmallen_bits/ens_version.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
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.
1818
#define ENS_VERSION_MINOR 21
19-
#define ENS_VERSION_PATCH 0
19+
#define ENS_VERSION_PATCH 1
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".
2424
#define ENS_VERSION_NAME "Bent Antenna"
2525
// Incorporate the date the version was released.
26-
#define ENS_VERSION_YEAR "2023"
27-
#define ENS_VERSION_MONTH "11"
28-
#define ENS_VERSION_DAY "23"
26+
#define ENS_VERSION_YEAR "2024"
27+
#define ENS_VERSION_MONTH "02"
28+
#define ENS_VERSION_DAY "15"
2929

3030
namespace ens {
3131

inst/include/ensmallen_bits/lbfgs/lbfgs_impl.hpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,27 @@ double L_BFGS::ChooseScalingFactor(const size_t iterationNum,
7979
{
8080
typedef typename CubeType::elem_type CubeElemType;
8181

82+
constexpr const CubeElemType tol =
83+
100 * std::numeric_limits<CubeElemType>::epsilon();
84+
8285
double scalingFactor;
8386
if (iterationNum > 0)
8487
{
8588
int previousPos = (iterationNum - 1) % numBasis;
8689
// Get s and y matrices once instead of multiple times.
8790
const arma::Mat<CubeElemType>& sMat = s.slice(previousPos);
8891
const arma::Mat<CubeElemType>& yMat = y.slice(previousPos);
89-
92+
9093
const CubeElemType tmp = arma::dot(yMat, yMat);
91-
const CubeElemType denom = (tmp != CubeElemType(0)) ? tmp : CubeElemType(1);
92-
94+
const CubeElemType denom = (tmp >= tol) ? tmp : CubeElemType(1);
95+
9396
scalingFactor = arma::dot(sMat, yMat) / denom;
9497
}
9598
else
9699
{
97100
const CubeElemType tmp = arma::norm(gradient, "fro");
98-
99-
scalingFactor = (tmp != CubeElemType(0)) ? (1.0 / tmp) : 1.0;
101+
102+
scalingFactor = (tmp >= tol) ? (1.0 / tmp) : 1.0;
100103
}
101104

102105
return scalingFactor;
@@ -135,16 +138,18 @@ void L_BFGS::SearchDirection(const MatType& gradient,
135138
for (size_t i = iterationNum; i != limit; i--)
136139
{
137140
int translatedPosition = (i + (numBasis - 1)) % numBasis;
138-
141+
139142
const arma::Mat<CubeElemType>& sMat = s.slice(translatedPosition);
140143
const arma::Mat<CubeElemType>& yMat = y.slice(translatedPosition);
141-
144+
142145
const CubeElemType tmp = arma::dot(yMat, sMat);
143-
144-
rho[iterationNum - i] = (tmp != CubeElemType(0)) ? (1.0 / tmp) : CubeElemType(1);
145-
146-
alpha[iterationNum - i] = rho[iterationNum - i] * arma::dot(sMat, searchDirection);
147-
146+
147+
rho[iterationNum - i] = (tmp != CubeElemType(0)) ? (1.0 / tmp) :
148+
CubeElemType(1);
149+
150+
alpha[iterationNum - i] = rho[iterationNum - i] *
151+
arma::dot(sMat, searchDirection);
152+
148153
searchDirection -= alpha[iterationNum - i] * yMat;
149154
}
150155

@@ -410,7 +415,8 @@ L_BFGS::Optimize(FunctionType& function,
410415
//
411416
// But don't do this on the first iteration to ensure we always take at
412417
// least one descent step.
413-
// TODO: to speed this up, investigate use of arma::norm2est() in Armadillo 12.4
418+
// TODO: to speed this up, investigate use of arma::norm2est() in Armadillo
419+
// 12.4
414420
if (arma::norm(gradient, 2) < minGradientNorm)
415421
{
416422
Info << "L-BFGS gradient norm too small (terminating successfully)."
@@ -442,7 +448,7 @@ L_BFGS::Optimize(FunctionType& function,
442448
<< std::endl;
443449
break;
444450
}
445-
451+
446452
// Build an approximation to the Hessian and choose the search
447453
// direction for the current iteration.
448454
SearchDirection(gradient, itNum, scalingFactor, s, y, searchDirection);

tools/HISTORYold.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
### ensmallen ?.??.?: "???"
2-
###### ????-??-??
1+
### ensmallen 2.21.1: "Bent Antenna"
2+
###### 2024-02-15
3+
* Fix numerical precision issues for small-gradient L-BFGS scaling factor
4+
computations ([#392](https://github.com/mlpack/ensmallen/pull/392)).
5+
6+
* Ensure the tests are built with optimisation enabled
7+
([#394](https://github.com/mlpack/ensmallen/pull/394)).
8+
9+
### ensmallen 2.21.0: "Bent Antenna"
10+
###### 2023-11-27
311
* Clarify return values for different callback types
412
([#383](https://github.com/mlpack/ensmallen/pull/383)).
513

0 commit comments

Comments
 (0)