Skip to content

Commit

Permalink
Upgrade ensmallen to 2.21.1 (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: coatless <coatless@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and coatless authored Feb 16, 2024
1 parent 394c439 commit 8101425
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 38 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2024-02-16 James Balamuta <balamut2@illinois.edu>

* DESCRIPTION (Version): Release 2.21.1
* NEWS.md: Update for Ensmallen release 2.21.1
* inst/include/ensmallen_bits: Upgraded to Ensmallen 2.21.1
* inst/include/ensmallen.hpp: ditto

2023-11-27 James Balamuta <balamut2@illinois.edu>

* DESCRIPTION (Version): Release 2.21.0
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: RcppEnsmallen
Title: Header-Only C++ Mathematical Optimization Library for 'Armadillo'
Version: 0.2.21.0.1
Version: 0.2.21.1.1
Authors@R: c(
person("James Joseph", "Balamuta", email = "balamut2@illinois.edu",
role = c("aut", "cre", "cph"),
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# RcppEnsmallen 0.2.21.1.1

- Upgraded to ensmallen 2.21.1: "Bent Antenna" (2024-02-16)
- Fix numerical precision issues for small-gradient L-BFGS scaling factor
computations ([#392](https://github.com/mlpack/ensmallen/pull/392)).
- Ensure the tests are built with optimisation enabled
([#394](https://github.com/mlpack/ensmallen/pull/394)).

# RcppEnsmallen 0.2.21.0.1

- Upgraded to ensmallen 2.21.0: "Stripped Bolt Head" (2023-11-27)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ AugLagrangian::Optimize(
<< ", starting with objective " << lastObjective << "." << std::endl;

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

const ElemType objective = function.Evaluate(coordinates);

Expand Down
2 changes: 1 addition & 1 deletion inst/include/ensmallen_bits/callbacks/query_front.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class QueryFront
typename MatType,
typename ObjectivesVecType,
typename IndicesType>
bool GenerationalStepTaken(OptimizerType& opt,
bool GenerationalStepTaken(OptimizerType& /* opt */,
FunctionType& /* function */,
const MatType& /* coordinates */,
const ObjectivesVecType& objectives,
Expand Down
32 changes: 19 additions & 13 deletions inst/include/ensmallen_bits/cmaes/not_empty_transformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@
* the 3-clause BSD license along with ensmallen. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef NOT_EMPTY_TRANSFORMATION
#define NOT_EMPTY_TRANSFORMATION
#ifndef ENSMALLEN_CMAES_NOT_EMPTY_TRANSFORMATION
#define ENSMALLEN_CMAES_NOT_EMPTY_TRANSFORMATION

/*
This partial specialization is used to throw an exception when the
TransformationPolicyType is EmptyTransformation and call a
constructor with parameters 'lowerBound' and 'upperBound' otherwise.
This shall be removed when the deprecated constructor is removed in
the next major version of ensmallen.
/**
* This partial specialization is used to throw an exception when the
* TransformationPolicyType is EmptyTransformation and call a constructor with
* parameters 'lowerBound' and 'upperBound' otherwise. This shall be removed
* when the deprecated constructor is removed in the next major version of
* ensmallen.
*/
template<typename T1, typename T2>
struct NotEmptyTransformation : std::true_type {
void Assign(T1& obj, double lowerBound, double upperBound) {
struct NotEmptyTransformation : std::true_type
{
void Assign(T1& obj, double lowerBound, double upperBound)
{
obj = T1(lowerBound, upperBound);
}
};

template<template<typename...> class T, typename... A, typename... B>
struct NotEmptyTransformation<T<A...>, T<B...>> : std::false_type {
void Assign(T<A...>& obj, double lowerBound, double upperBound) {
struct NotEmptyTransformation<T<A...>, T<B...>> : std::false_type
{
void Assign(T<A...>& /* obj */,
double /* lowerBound */,
double /* upperBound */)
{
throw std::logic_error("TransformationPolicyType is EmptyTransformation");
}
};

#endif
#endif
8 changes: 4 additions & 4 deletions inst/include/ensmallen_bits/ens_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
// The minor version is two digits so regular numerical comparisons of versions
// work right. The first minor version of a release is always 10.
#define ENS_VERSION_MINOR 21
#define ENS_VERSION_PATCH 0
#define ENS_VERSION_PATCH 1
// If this is a release candidate, it will be reflected in the version name
// (i.e. the version name will be "RC1", "RC2", etc.). Otherwise the version
// name will typically be a seemingly arbitrary set of words that does not
// contain the capitalized string "RC".
#define ENS_VERSION_NAME "Bent Antenna"
// Incorporate the date the version was released.
#define ENS_VERSION_YEAR "2023"
#define ENS_VERSION_MONTH "11"
#define ENS_VERSION_DAY "23"
#define ENS_VERSION_YEAR "2024"
#define ENS_VERSION_MONTH "02"
#define ENS_VERSION_DAY "15"

namespace ens {

Expand Down
34 changes: 20 additions & 14 deletions inst/include/ensmallen_bits/lbfgs/lbfgs_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,27 @@ double L_BFGS::ChooseScalingFactor(const size_t iterationNum,
{
typedef typename CubeType::elem_type CubeElemType;

constexpr const CubeElemType tol =
100 * std::numeric_limits<CubeElemType>::epsilon();

double scalingFactor;
if (iterationNum > 0)
{
int previousPos = (iterationNum - 1) % numBasis;
// Get s and y matrices once instead of multiple times.
const arma::Mat<CubeElemType>& sMat = s.slice(previousPos);
const arma::Mat<CubeElemType>& yMat = y.slice(previousPos);

const CubeElemType tmp = arma::dot(yMat, yMat);
const CubeElemType denom = (tmp != CubeElemType(0)) ? tmp : CubeElemType(1);
const CubeElemType denom = (tmp >= tol) ? tmp : CubeElemType(1);

scalingFactor = arma::dot(sMat, yMat) / denom;
}
else
{
const CubeElemType tmp = arma::norm(gradient, "fro");
scalingFactor = (tmp != CubeElemType(0)) ? (1.0 / tmp) : 1.0;

scalingFactor = (tmp >= tol) ? (1.0 / tmp) : 1.0;
}

return scalingFactor;
Expand Down Expand Up @@ -135,16 +138,18 @@ void L_BFGS::SearchDirection(const MatType& gradient,
for (size_t i = iterationNum; i != limit; i--)
{
int translatedPosition = (i + (numBasis - 1)) % numBasis;

const arma::Mat<CubeElemType>& sMat = s.slice(translatedPosition);
const arma::Mat<CubeElemType>& yMat = y.slice(translatedPosition);

const CubeElemType tmp = arma::dot(yMat, sMat);

rho[iterationNum - i] = (tmp != CubeElemType(0)) ? (1.0 / tmp) : CubeElemType(1);

alpha[iterationNum - i] = rho[iterationNum - i] * arma::dot(sMat, searchDirection);


rho[iterationNum - i] = (tmp != CubeElemType(0)) ? (1.0 / tmp) :
CubeElemType(1);

alpha[iterationNum - i] = rho[iterationNum - i] *
arma::dot(sMat, searchDirection);

searchDirection -= alpha[iterationNum - i] * yMat;
}

Expand Down Expand Up @@ -410,7 +415,8 @@ L_BFGS::Optimize(FunctionType& function,
//
// But don't do this on the first iteration to ensure we always take at
// least one descent step.
// TODO: to speed this up, investigate use of arma::norm2est() in Armadillo 12.4
// TODO: to speed this up, investigate use of arma::norm2est() in Armadillo
// 12.4
if (arma::norm(gradient, 2) < minGradientNorm)
{
Info << "L-BFGS gradient norm too small (terminating successfully)."
Expand Down Expand Up @@ -442,7 +448,7 @@ L_BFGS::Optimize(FunctionType& function,
<< std::endl;
break;
}

// Build an approximation to the Hessian and choose the search
// direction for the current iteration.
SearchDirection(gradient, itNum, scalingFactor, s, y, searchDirection);
Expand Down
12 changes: 10 additions & 2 deletions tools/HISTORYold.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
### ensmallen ?.??.?: "???"
###### ????-??-??
### ensmallen 2.21.1: "Bent Antenna"
###### 2024-02-15
* Fix numerical precision issues for small-gradient L-BFGS scaling factor
computations ([#392](https://github.com/mlpack/ensmallen/pull/392)).

* Ensure the tests are built with optimisation enabled
([#394](https://github.com/mlpack/ensmallen/pull/394)).

### ensmallen 2.21.0: "Bent Antenna"
###### 2023-11-27
* Clarify return values for different callback types
([#383](https://github.com/mlpack/ensmallen/pull/383)).

Expand Down

0 comments on commit 8101425

Please sign in to comment.