Skip to content

Commit 297b9cd

Browse files
Upgrade ensmallen to 2.17.0 (#44)
* Upgrade ensmallen to 2.17.0 Co-authored-by: coatless <[email protected]>
1 parent 4d14a8f commit 297b9cd

37 files changed

+2909
-119
lines changed

ChangeLog

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

310
* DESCRIPTION (Version): Release 2.16.2

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

NEWS.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
# RcppEnsmallen 0.2.17.0.1
2+
3+
- Upgraded to ensmallen 2.17.0: "Pachis Din Me Pesa Double" (2021-07-06)
4+
- CheckArbitraryFunctionTypeAPI extended for MOO support
5+
([#283](https://github.com/mlpack/ensmallen/pull/283)).
6+
- Refactor NSGA2
7+
([#263](https://github.com/mlpack/ensmallen/pull/263),
8+
[#304](https://github.com/mlpack/ensmallen/pull/304)).
9+
- Add Indicators for Multiobjective optimizers
10+
([#285](https://github.com/mlpack/ensmallen/pull/285)).
11+
- Make Callback flexible for MultiObjective Optimizers
12+
([#289](https://github.com/mlpack/ensmallen/pull/289)).
13+
- Add ZDT Test Suite
14+
([#273](https://github.com/mlpack/ensmallen/pull/273)).
15+
- Add MOEA-D/DE Optimizer
16+
([#269](https://github.com/mlpack/ensmallen/pull/269)).
17+
- Introduce Policy Methods for MOEA/D-DE
18+
([#293](https://github.com/mlpack/ensmallen/pull/293)).
19+
- Add Das-Dennis weight initialization method
20+
([#295](https://github.com/mlpack/ensmallen/pull/295)).
21+
- Add Dirichlet Weight Initialization
22+
([#296](https://github.com/mlpack/ensmallen/pull/296)).
23+
- Improved installation and compilation instructions
24+
([#300](https://github.com/mlpack/ensmallen/pull/300)).
25+
- Disable building the tests by default for faster installation
26+
([#303](https://github.com/mlpack/ensmallen/pull/303)).
27+
- Modify matrix initialisation to take into account
28+
default element zeroing in Armadillo 10.5
29+
([#305](https://github.com/mlpack/ensmallen/pull/305)).
30+
131
# RcppEnsmallen 0.2.16.2.1 (GitHub-only Release)
232

333
- Upgraded to ensmallen 2.16.2: "Severely Dented Can Of Polyurethane" (2021-03-25)

inst/include/ensmallen.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565

6666
#include "ensmallen_bits/utility/any.hpp"
6767
#include "ensmallen_bits/utility/arma_traits.hpp"
68+
#include "ensmallen_bits/utility/indicators/epsilon.hpp"
69+
#include "ensmallen_bits/utility/indicators/igd_plus.hpp"
6870

6971
// Contains traits, must be placed before report callback.
7072
#include "ensmallen_bits/function.hpp" // TODO: should move to function/
@@ -74,6 +76,7 @@
7476
#include "ensmallen_bits/callbacks/early_stop_at_min_loss.hpp"
7577
#include "ensmallen_bits/callbacks/print_loss.hpp"
7678
#include "ensmallen_bits/callbacks/progress_bar.hpp"
79+
#include "ensmallen_bits/callbacks/query_front.hpp"
7780
#include "ensmallen_bits/callbacks/report.hpp"
7881
#include "ensmallen_bits/callbacks/store_best_coordinates.hpp"
7982
#include "ensmallen_bits/callbacks/timer_stop.hpp"
@@ -100,6 +103,7 @@
100103
#include "ensmallen_bits/katyusha/katyusha.hpp"
101104
#include "ensmallen_bits/lbfgs/lbfgs.hpp"
102105
#include "ensmallen_bits/lookahead/lookahead.hpp"
106+
#include "ensmallen_bits/moead/moead.hpp"
103107
#include "ensmallen_bits/nsga2/nsga2.hpp"
104108
#include "ensmallen_bits/padam/padam.hpp"
105109
#include "ensmallen_bits/parallel_sgd/parallel_sgd.hpp"

inst/include/ensmallen_bits/callbacks/callbacks.hpp

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,79 @@ class Callback
744744
MatType& /* coordinates */)
745745
{ return false; }
746746

747+
/**
748+
* Invoke the GenerationalStepTaken() callback if it exists.
749+
* Specialization for MultiObjective case.
750+
*
751+
* @param callback The callback to call.
752+
* @param optimizer The optimizer used to update the function.
753+
* @param function Function to optimize.
754+
* @param coordinates Starting point.
755+
* @param objectives The set of calculated objectives so far.
756+
* @param frontIndices The indices of the members belonging to Pareto Front.
757+
*/
758+
template<typename CallbackType,
759+
typename OptimizerType,
760+
typename FunctionType,
761+
typename MatType,
762+
typename ObjectivesVecType,
763+
typename IndicesType>
764+
static typename std::enable_if<
765+
callbacks::traits::HasGenerationalStepTakenSignature<
766+
CallbackType, OptimizerType, FunctionType, MatType, ObjectivesVecType,
767+
IndicesType>::hasBool, bool>::type
768+
GenerationalStepTakenFunction(CallbackType& callback,
769+
OptimizerType& optimizer,
770+
FunctionType& function,
771+
MatType& coordinates,
772+
ObjectivesVecType& objectives,
773+
IndicesType& frontIndices)
774+
{
775+
return const_cast<CallbackType&>(callback).GenerationalStepTaken(
776+
optimizer, function, coordinates, objectives, frontIndices);
777+
}
778+
779+
template<typename CallbackType,
780+
typename OptimizerType,
781+
typename FunctionType,
782+
typename MatType,
783+
typename ObjectivesVecType,
784+
typename IndicesType>
785+
static typename std::enable_if<
786+
callbacks::traits::HasGenerationalStepTakenSignature<
787+
CallbackType, OptimizerType, FunctionType, MatType, ObjectivesVecType,
788+
IndicesType>::hasVoid, bool>::type
789+
GenerationalStepTakenFunction(CallbackType& callback,
790+
OptimizerType& optimizer,
791+
FunctionType& function,
792+
MatType& coordinates,
793+
ObjectivesVecType& objectives,
794+
IndicesType& frontIndices)
795+
{
796+
const_cast<CallbackType&>(callback).GenerationalStepTaken(
797+
optimizer, function, coordinates, objectives, frontIndices);
798+
799+
return false;
800+
}
801+
802+
template<typename CallbackType,
803+
typename OptimizerType,
804+
typename FunctionType,
805+
typename MatType,
806+
typename ObjectivesVecType,
807+
typename IndicesType>
808+
static typename std::enable_if<
809+
callbacks::traits::HasGenerationalStepTakenSignature<
810+
CallbackType, OptimizerType, FunctionType, MatType, ObjectivesVecType,
811+
IndicesType>::hasNone, bool>::type
812+
GenerationalStepTakenFunction(CallbackType& /* callback */,
813+
OptimizerType& /* optimizer */,
814+
FunctionType& /* function */,
815+
MatType& /* coordinates */,
816+
ObjectivesVecType& /* objectives */,
817+
IndicesType& /* frontIndices */)
818+
{ return false; }
819+
747820
/**
748821
* Iterate over the callbacks and invoke the StepTaken() callback if it
749822
* exists.
@@ -769,8 +842,41 @@ class Callback
769842
function, coordinates)... };
770843
return result;
771844
}
772-
};
773845

846+
/**
847+
* Iterate over the callbacks and invoke the GenerationalStepTaken() callback if it
848+
* exists.
849+
*
850+
* Specialization for MultiObjective case.
851+
*
852+
* @param optimizer The optimizer used to update the function.
853+
* @param function Function to optimize.
854+
* @param coordinates Starting point.
855+
* @param objectives The set of calculated objectives so far.
856+
* @param frontIndices The indices of the members belonging to Pareto Front.
857+
* @param callbacks The callbacks container.
858+
*/
859+
template<typename OptimizerType,
860+
typename FunctionType,
861+
typename ObjectivesVecType,
862+
typename IndicesType,
863+
typename MatType,
864+
typename ...CallbackTypes>
865+
static bool GenerationalStepTaken(OptimizerType& optimizer,
866+
FunctionType& functions,
867+
MatType& coordinates,
868+
ObjectivesVecType& objectives,
869+
IndicesType& frontIndices,
870+
CallbackTypes&... callbacks)
871+
{
872+
// This will return immediately once a callback returns true.
873+
bool result = false;
874+
(void)std::initializer_list<bool>{ result =
875+
result || Callback::GenerationalStepTakenFunction(callbacks, optimizer,
876+
functions, coordinates, objectives, frontIndices)... };
877+
return result;
878+
}
879+
};
774880
} // namespace ens
775881

776882
#endif
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* @file query_front.hpp
3+
* @author Nanubala Gnana Sai
4+
*
5+
* Implementation of the query front callback function.
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_CALLBACKS_QUERY_FRONT_HPP
13+
#define ENSMALLEN_CALLBACKS_QUERY_FRONT_HPP
14+
15+
namespace ens {
16+
17+
/**
18+
* Query the current Pareto Front after every GenerationalStepTaken callback function.
19+
*/
20+
class QueryFront
21+
{
22+
public:
23+
/**
24+
* Set up the query front callback class with the specified inputs.
25+
*
26+
* @param queryRate The frequency at which the Pareto Front is queried.
27+
* @param paretoFrontArray A reference to a vector of cube to store the queried fronts.
28+
*/
29+
QueryFront(const size_t queryRate, std::vector<arma::cube>& paretoFrontArray) :
30+
queryRate(queryRate),
31+
paretoFrontArray(paretoFrontArray),
32+
genCounter(0)
33+
{ /* Nothing to do here */ }
34+
35+
/**
36+
* Callback function called at the end of a single generational run.
37+
*
38+
* @param optimizer The optimizer used to update the function.
39+
* @param function Function to optimize.
40+
* @param coordinates Starting point.
41+
* @param objectives The set of calculated objectives so far.
42+
* @param frontIndices The indices of the members belonging to Pareto Front.
43+
*/
44+
template<typename OptimizerType,
45+
typename FunctionType,
46+
typename MatType,
47+
typename ObjectivesVecType,
48+
typename IndicesType>
49+
void GenerationalStepTaken(OptimizerType& opt,
50+
FunctionType& /* function */,
51+
const MatType& /* coordinates */,
52+
const ObjectivesVecType& objectives,
53+
const IndicesType& frontIndices)
54+
{
55+
arma::cube currentParetoFront{};
56+
57+
if (genCounter % queryRate == 0)
58+
{
59+
currentParetoFront.resize(objectives[0].n_rows, objectives[0].n_cols,
60+
frontIndices[0].size());
61+
for (size_t solutionIdx = 0; solutionIdx < frontIndices[0].size(); ++solutionIdx)
62+
{
63+
currentParetoFront.slice(solutionIdx) =
64+
arma::conv_to<arma::mat>::from(objectives[frontIndices[0][solutionIdx]]);
65+
}
66+
67+
paretoFrontArray.emplace_back(std::move(currentParetoFront));
68+
}
69+
70+
++genCounter;
71+
}
72+
73+
74+
private:
75+
//! The rate of query.
76+
size_t queryRate;
77+
//! A reference to the array of pareto fronts.
78+
std::vector<arma::cube>& paretoFrontArray;
79+
//! A counter for the current generation.
80+
size_t genCounter;
81+
};
82+
83+
} // namespace ens
84+
85+
#endif

inst/include/ensmallen_bits/callbacks/traits.hpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ ENS_HAS_EXACT_METHOD_FORM(BeginEpoch, HasBeginEpoch)
3737
ENS_HAS_EXACT_METHOD_FORM(EndEpoch, HasEndEpoch)
3838
//! Detect an StepTaken() method.
3939
ENS_HAS_EXACT_METHOD_FORM(StepTaken, HasStepTaken)
40+
//! Detect an GenerationalStepTaken() method.
41+
ENS_HAS_EXACT_METHOD_FORM(GenerationalStepTaken, HasGenerationalStepTaken)
4042

4143
template<typename OptimizerType,
4244
typename FunctionType,
@@ -365,6 +367,69 @@ struct HasStepTakenSignature
365367
FunctionType, MatType>::template StepTakenVoidForm>::value;
366368
};
367369

370+
//! A utility struct for Typed Forms required in
371+
//! callbacks for MultiObjective Optimizers.
372+
template<typename OptimizerType,
373+
typename FunctionType,
374+
typename MatType,
375+
typename ObjectivesVecType,
376+
typename IndicesType,
377+
typename GradType = MatType>
378+
struct MOOTypedForms
379+
{
380+
//! This is the form of a bool GenerationalStepTaken() for MOO callback method.
381+
template<typename CallbackType>
382+
using GenerationalStepTakenBoolForm =
383+
bool(CallbackType::*)(OptimizerType&,
384+
FunctionType&,
385+
const MatType&,
386+
const ObjectivesVecType&,
387+
const IndicesType&);
388+
389+
//! This is the form of a void StepTaken() for MOO callback method.
390+
template<typename CallbackType>
391+
using GenerationalStepTakenVoidForm =
392+
void(CallbackType::*)(OptimizerType&,
393+
FunctionType&,
394+
const MatType&,
395+
const ObjectivesVecType&,
396+
const IndicesType&);
397+
};
398+
399+
//! Utility struct, check if either void StepTaken() or bool StepTaken() exists.
400+
//! Specialization for Multiobjective case.
401+
template<typename CallbackType,
402+
typename OptimizerType,
403+
typename FunctionType,
404+
typename ObjectivesVecType,
405+
typename IndicesType,
406+
typename MatType>
407+
struct HasGenerationalStepTakenSignature
408+
{
409+
const static bool hasBool =
410+
HasGenerationalStepTaken<CallbackType, MOOTypedForms<OptimizerType,
411+
FunctionType, MatType, ObjectivesVecType, IndicesType>::
412+
template GenerationalStepTakenBoolForm>::value &&
413+
!HasGenerationalStepTaken<CallbackType, MOOTypedForms<OptimizerType,
414+
FunctionType, MatType, ObjectivesVecType, IndicesType>::
415+
template GenerationalStepTakenVoidForm>::value;
416+
417+
const static bool hasVoid =
418+
!HasGenerationalStepTaken<CallbackType, MOOTypedForms<OptimizerType,
419+
FunctionType, MatType, ObjectivesVecType, IndicesType>::
420+
template GenerationalStepTakenBoolForm>::value &&
421+
HasGenerationalStepTaken<CallbackType, MOOTypedForms<OptimizerType,
422+
FunctionType, MatType, ObjectivesVecType, IndicesType>::
423+
template GenerationalStepTakenVoidForm>::value;
424+
425+
const static bool hasNone =
426+
!HasGenerationalStepTaken<CallbackType, MOOTypedForms<OptimizerType,
427+
FunctionType, MatType, ObjectivesVecType, IndicesType>::
428+
template GenerationalStepTakenBoolForm>::value &&
429+
!HasGenerationalStepTaken<CallbackType, MOOTypedForms<OptimizerType,
430+
FunctionType, MatType, ObjectivesVecType, IndicesType>::
431+
template GenerationalStepTakenVoidForm>::value;
432+
};
368433
} // namespace traits
369434
} // namespace callbacks
370435
} // namespace ens

inst/include/ensmallen_bits/cmaes/cmaes.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ class CMAES
9797
MatType& iterate,
9898
CallbackTypes&&... callbacks);
9999

100-
//! Get the step size.
100+
//! Get the population size.
101101
size_t PopulationSize() const { return lambda; }
102-
//! Modify the step size.
102+
//! Modify the population size.
103103
size_t& PopulationSize() { return lambda; }
104104

105105
//! Get the lower bound of decision variables.

0 commit comments

Comments
 (0)