Skip to content

Commit 4e62b77

Browse files
authored
Upgrade ensmallen 2.13.0 (#27)
* Update ensmallen to 2.13.0 * Add NEWS entry * Add ChangeLog entry * Update R version in CRAN-comments * Bump version
1 parent c29d5e5 commit 4e62b77

File tree

7 files changed

+81
-20
lines changed

7 files changed

+81
-20
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2020-07-23 James Balamuta <[email protected]>
2+
3+
* DESCRIPTION (Version): Release 2.13.0
4+
5+
* NEWS.md: Update for Ensmallen release 2.13.0
6+
7+
* inst/include/ensmallen_bits: Upgraded to Ensmallen 2.13.0
8+
* inst/include/ensmallen.hpp: ditto
9+
110
2020-04-23 James Balamuta <[email protected]>
211

312
* DESCRIPTION (Version): Release 2.12.1

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.12.1.1
3+
Version: 0.2.13.0.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.13.0.1
2+
3+
- Upgraded to ensmallen 2.13.0: "Automatically Automated Automation" (2020-07-15)
4+
- Fix CMake package export
5+
([#198](https://github.com/mlpack/ensmallen/pull/198)).
6+
- Allow early stop callback to accept a lambda function
7+
([#165](https://github.com/mlpack/ensmallen/pull/165)).
8+
19
# RcppEnsmallen 0.2.12.1.1
210

311
- Upgraded to ensmallen 2.12.1: "Stir Crazy" (2020-04-20)

cran-comments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Test environments
22

3-
* local macOS install, R 3.6.3
4-
* ubuntu 16.04 (with GitHub Actions), R 3.6.3
3+
* local macOS install, R 4.0.2
4+
* ubuntu 16.04 (with GitHub Actions), R 4.0.2
55
* win-builder (devel and release)
66

77
## R CMD check results

inst/include/ensmallen.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@
3333
#error "need Armadillo version 8.400 or later"
3434
#endif
3535

36-
#include <cmath>
37-
#include <cstdlib>
38-
#include <cstdio>
39-
#include <cstring>
4036
#include <cctype>
41-
#include <climits>
4237
#include <cfloat>
38+
#include <cmath>
4339
#include <cstdint>
40+
#include <cstdio>
41+
#include <cstdlib>
42+
#include <cstring>
43+
#include <iostream>
44+
#include <limits>
45+
#include <sstream>
4446
#include <stdexcept>
47+
#include <string>
4548
#include <tuple>
4649
#include <utility>
47-
#include <iostream>
48-
#include <string>
49-
#include <sstream>
5050

5151
// On Visual Studio, disable C4519 (default arguments for function templates)
5252
// since it's by default an error, which doesn't even make any sense because

inst/include/ensmallen_bits/callbacks/early_stop_at_min_loss.hpp

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @file early_stop_at_min_loss.hpp
33
* @author Marcus Edel
4+
* @author Omar Shrit
45
*
56
* Implementation of the early stop at minimum loss callback function.
67
*
@@ -12,13 +13,16 @@
1213
#ifndef ENSMALLEN_CALLBACKS_EARLY_STOP_AT_MIN_LOSS_HPP
1314
#define ENSMALLEN_CALLBACKS_EARLY_STOP_AT_MIN_LOSS_HPP
1415

16+
#include <functional>
17+
1518
namespace ens {
1619

1720
/**
1821
* Early stopping to terminate the optimization process early if the loss stops
1922
* decreasing.
2023
*/
21-
class EarlyStopAtMinLoss
24+
template<typename MatType = arma::mat>
25+
class EarlyStopAtMinLossType
2226
{
2327
public:
2428
/**
@@ -28,12 +32,33 @@ class EarlyStopAtMinLoss
2832
* @param patienceIn The number of epochs to wait after the minimum loss has
2933
* been reached or no improvement has been made (Default: 10).
3034
*/
31-
EarlyStopAtMinLoss(const size_t patienceIn = 10) :
32-
patience(patienceIn),
35+
EarlyStopAtMinLossType<MatType>(const size_t patienceIn = 10) :
36+
callbackUsed(false),
37+
patience(patienceIn),
3338
bestObjective(std::numeric_limits<double>::max()),
3439
steps(0)
3540
{ /* Nothing to do here */ }
3641

42+
/**
43+
* Set up the early stop at min loss class, which keeps track of the minimum
44+
* loss and stops the optimization process if the loss stops decreasing.
45+
*
46+
* @param func, callback to return immediate loss evaluated by the function
47+
* @param patienceIn The number of epochs to wait after the minimum loss has
48+
* been reached or no improvement has been made (Default: 10).
49+
*/
50+
EarlyStopAtMinLossType<MatType>(
51+
std::function<double(const MatType&)> func,
52+
const size_t patienceIn = 10)
53+
: callbackUsed(true),
54+
patience(patienceIn),
55+
bestObjective(std::numeric_limits<double>::max()),
56+
steps(0),
57+
localFunc(func)
58+
{
59+
// Nothing to do here
60+
}
61+
3762
/**
3863
* Callback function called at the end of a pass over the data.
3964
*
@@ -43,13 +68,18 @@ class EarlyStopAtMinLoss
4368
* @param epoch The index of the current epoch.
4469
* @param objective Objective value of the current point.
4570
*/
46-
template<typename OptimizerType, typename FunctionType, typename MatType>
71+
template<typename OptimizerType, typename FunctionType>
4772
bool EndEpoch(OptimizerType& /* optimizer */,
4873
FunctionType& /* function */,
49-
const MatType& /* coordinates */,
74+
const MatType& coordinates,
5075
const size_t /* epoch */,
51-
const double objective)
76+
double objective)
5277
{
78+
if (callbackUsed)
79+
{
80+
objective = localFunc(coordinates);
81+
}
82+
5383
if (objective < bestObjective)
5484
{
5585
steps = 0;
@@ -68,6 +98,9 @@ class EarlyStopAtMinLoss
6898
}
6999

70100
private:
101+
//! False if the first constructor is called, true if the user passed a lambda.
102+
bool callbackUsed;
103+
71104
//! The number of epochs to wait before terminating the optimization process.
72105
size_t patience;
73106

@@ -76,8 +109,19 @@ class EarlyStopAtMinLoss
76109

77110
//! Locally-stored number of steps since the loss improved.
78111
size_t steps;
112+
113+
//! Function to call at the end of the epoch.
114+
std::function<double(const MatType&)> localFunc;
79115
};
80116

117+
/*
118+
* Note that the using definition is temporary, this definition should
119+
* be removed when releasing ensmallen 3.0
120+
* The renaming of the class is only to avoid a major version bump
121+
* because if the template type added to this class
122+
*/
123+
using EarlyStopAtMinLoss = EarlyStopAtMinLossType<arma::mat>;
124+
81125
} // namespace ens
82126

83127
#endif

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 2
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 12
19-
#define ENS_VERSION_PATCH 1
18+
#define ENS_VERSION_MINOR 13
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 "Stir Crazy"
24+
#define ENS_VERSION_NAME "Automatically Automated Automation"
2525

2626
namespace ens {
2727

0 commit comments

Comments
 (0)