Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Active CMAES #367

Merged
merged 37 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
670ebb2
attempt to fix current cmaes inconsistencies
SuvarshaChennareddy Jan 2, 2023
f28fd18
update tests
SuvarshaChennareddy Jan 2, 2023
39feebb
fix style, add deprecated constructor, and update tests
SuvarshaChennareddy Jan 16, 2023
4a42820
change test name
SuvarshaChennareddy Jan 16, 2023
21e2e89
remove unused code
SuvarshaChennareddy Jan 19, 2023
43f5146
update documentation, add ens_deprecated, and fix errors
SuvarshaChennareddy Apr 27, 2023
5a00748
update HISTORY.md
SuvarshaChennareddy Apr 27, 2023
ac10206
Merge branch 'master' into cmaes-fix
zoq May 24, 2023
d42f985
Tiny style fix for name of function: initialStepSize -> InitialStepSize.
rcurtin May 29, 2023
c88e0c3
Remove some more tab characters I found...
rcurtin May 29, 2023
46565e7
Compilation fixes for tests.
rcurtin May 29, 2023
716cea6
fix bug and modify tests
SuvarshaChennareddy May 31, 2023
8baccf8
add implementation of active cmaes
SuvarshaChennareddy Jun 9, 2023
52c4d63
add tests
SuvarshaChennareddy Jun 12, 2023
3c9bcfb
fix implementation error and update tests
SuvarshaChennareddy Jun 12, 2023
c937e33
remove empty line
SuvarshaChennareddy Jun 12, 2023
9ae0e6d
update cmaes tests
SuvarshaChennareddy Jun 12, 2023
b518702
Merge branch 'active-cmaes' of https://github.com/SuvarshaChennareddy…
SuvarshaChennareddy Jun 12, 2023
a0843dc
update active cmaes tests
SuvarshaChennareddy Jun 12, 2023
0cc8d0c
update tests
SuvarshaChennareddy Jun 13, 2023
37b342c
update comments
SuvarshaChennareddy Jun 13, 2023
ef63966
Update hyperparameters used in tests
SuvarshaChennareddy Jun 14, 2023
0785776
add missing comment
SuvarshaChennareddy Jul 10, 2023
3eafed5
Merge branch 'master' into active-cmaes
SuvarshaChennareddy Jul 10, 2023
c8719fb
minor comment fix in callbacks_test.cpp
SuvarshaChennareddy Jul 10, 2023
ee7b695
add patience and update termination conditions
SuvarshaChennareddy Jul 12, 2023
caaa926
move NotEmptyTransformation to its own file
SuvarshaChennareddy Aug 7, 2023
5a145e8
Fix style issues and keep the constructor.
zoq Aug 16, 2023
4f6e312
Use the correct element type and style fixes.
zoq Aug 16, 2023
c92b48e
Indentation fixes.
zoq Aug 16, 2023
e4a843b
Use the correct element type and style fixes.
zoq Aug 16, 2023
a0a9400
Make the test more stable by testing multiple times before reporting …
zoq Aug 16, 2023
25ef5ff
Update HISTORY.md.
zoq Aug 16, 2023
7bdf982
Increase number of steps to make the tests more stable.
zoq Aug 17, 2023
e828442
add documentation
SuvarshaChennareddy Aug 18, 2023
9f71c1c
No need to depreciate the CMAES constructor.
zoq Aug 21, 2023
43c0cb3
Use the correct population size.
zoq Aug 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
### ensmallen ?.??.?: "???"
###### ????-??-??
* LBFGS: avoid generation of NaNs, and add checks for finite values
* Implementation of Active CMAES
([#367](https://github.com/mlpack/ensmallen/pull/367)).

* LBFGS: avoid generation of NaNs, and add checks for finite values
([#368](https://github.com/mlpack/ensmallen/pull/368)).

* Fix CNE test tolerances
* Fix CNE test tolerances
([#360](https://github.com/mlpack/ensmallen/pull/360)).

### ensmallen 2.19.1: "Eight Ball Deluxe"
Expand Down
131 changes: 118 additions & 13 deletions doc/optimizers.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,95 @@
## ActiveCMAES

*An optimizer for [separable functions](#separable-functions).*

Active CMA-ES is a variant of the stochastic search algorithm
CMA-ES - Covariance Matrix Adaptation Evolution Strategy.
Active CMA-ES actively reduces the uncertainty in unfavourable directions by
exploiting the information about bad mutations in the covariance matrix
update step. This isn't for the purpose of accelerating progress, but
instead for speeding up the adaptation of the covariance matrix (which, in
turn, will lead to faster progress).

#### Constructors

* `ActiveCMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>()`
* `ActiveCMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy`_`)`
* `ActiveCMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize`_`)`
* `ActiveCMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)`
* `ActiveCMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)`

The _`SelectionPolicyType`_ template parameter refers to the strategy used to
compute the (approximate) objective function. The `FullSelection` and
`RandomSelection` classes are available for use; custom behavior can be achieved
by implementing a class with the same method signatures.
The _`TransformationPolicyType`_ template parameter refers to transformation
strategy used to map decision variables to the desired domain during fitness
evaluation and optimization termination. The `EmptyTransformation` and
`BoundaryBoxConstraint` classes are available for use; custom behavior can be
achieved by implementing a class with the same method signatures.

For convenience the following types can be used:

* **`ActiveCMAES<>`** (equivalent to `ActiveCMAES<FullSelection, EmptyTransformation<>>`): uses all separable functions to compute objective
* **`ApproxActiveCMAES<>`** (equivalent to `ActiveCMAES<RandomSelection, EmptyTransformation<>>`): uses a small amount of separable functions to compute approximate objective

#### Attributes

| **type** | **name** | **description** | **default** |
|----------|----------|-----------------|-------------|
| `size_t` | **`lambda`** | The population size (0 uses a default size). | `0` |
| `TransformationPolicyType` | **`transformationPolicy`** | Instantiated transformation policy used to map the coordinates to the desired domain. | `TransformationPolicyType()` |
| `size_t` | **`batchSize`** | Batch size to use for the objective calculation. | `32` |
| `size_t` | **`maxIterations`** | Maximum number of iterations. | `1000` |
| `double` | **`tolerance`** | Maximum absolute tolerance to terminate algorithm. | `1e-5` |
| `SelectionPolicyType` | **`selectionPolicy`** | Instantiated selection policy used to calculate the objective. | `SelectionPolicyType()` |
| `size_t` | **`stepSize`** | Initial step size | `0` |

Attributes of the optimizer may also be changed via the member methods
`Lambda()`, `TransformationPolicy()`, `BatchSize()`, `MaxIterations()`,
`Tolerance()`, and `SelectionPolicy()`.

The `selectionPolicy` attribute allows an instantiated `SelectionPolicyType` to
be given. The `FullSelection` policy has no need to be instantiated and thus
the option is not relevant when the `ActiveCMAES<>` optimizer type is being used; the
`RandomSelection` policy has the constructor `RandomSelection(`_`fraction`_`)`
where _`fraction`_ specifies the percentage of separable functions to use to
estimate the objective function.
The `transformationPolicy` attribute allows an instantiated
`TransformationPolicyType` to be given. The `EmptyTransformation<`_`MatType`_`>`
has no need to be instantiated. `BoundaryBoxConstraint<`_`MatType`_`>` policy has
the constructor `BoundaryBoxConstraint(`_`lowerBound, upperBound`_`)`
where _`lowerBound`_ and _`lowerBound`_ are the lower bound and upper bound of
the coordinates respectively.

#### Examples:

<details open>
<summary>Click to collapse/expand example code.
</summary>

```c++
RosenbrockFunction f;
arma::mat coordinates = f.GetInitialPoint();

// ActiveCMAES with the FullSelection and BoundaryBoxConstraint policies.
BoundaryBoxConstraint b(-1, 1);
ActiveCMAES optimizer(0, b, 32, 200, 1e-4);
optimizer.Optimize(f, coordinates);

// ActiveCMAES with the RandomSelection and BoundaryBoxConstraint policies.
ApproxActiveCMAES<BoundaryBoxConstraint<>> cmaes(0, b, 32, 200, 1e-4);
approxOptimizer.Optimize(f, coordinates);
```

</details>

#### See also:

* [CMAES](#cmaes)
* [Improving Evolution Strategies through Active Covariance Matrix Adaptation](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.114.4239&rep=rep1&type=pdfn)
* [Evolution strategy in Wikipedia](https://en.wikipedia.org/wiki/Evolution_strategy)

## AdaBelief

*An optimizer for [differentiable separable functions](#differentiable-separable-functions).*
Expand Down Expand Up @@ -696,35 +788,41 @@ matrix within an iterative procedure using the covariance matrix.

#### Constructors

* `CMAES<`_`SelectionPolicyType`_`>()`
* `CMAES<`_`SelectionPolicyType`_`>(`_`lambda, lowerBound, upperBound`_`)`
* `CMAES<`_`SelectionPolicyType`_`>(`_`lambda, lowerBound, upperBound, batchSize`_`)`
* `CMAES<`_`SelectionPolicyType`_`>(`_`lambda, lowerBound, upperBound, batchSize, maxIterations, tolerance, selectionPolicy`_`)`
* `CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>()`
* `CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy`_`)`
* `CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize`_`)`
* `CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy`_`)`
* `CMAES<`_`SelectionPolicyType, TransformationPolicyType`_`>(`_`lambda, transformationPolicy, batchSize, maxIterations, tolerance, selectionPolicy, stepSize`_`)`

The _`SelectionPolicyType`_ template parameter refers to the strategy used to
compute the (approximate) objective function. The `FullSelection` and
`RandomSelection` classes are available for use; custom behavior can be achieved
by implementing a class with the same method signatures.
The _`TransformationPolicyType`_ template parameter refers to transformation
strategy used to map decision variables to the desired domain during fitness
evaluation and optimization termination. The `EmptyTransformation` and
`BoundaryBoxConstraint` classes are available for use; custom behavior can be
achieved by implementing a class with the same method signatures.

For convenience the following types can be used:

* **`CMAES<>`** (equivalent to `CMAES<FullSelection>`): uses all separable functions to compute objective
* **`ApproxCMAES`** (equivalent to `CMAES<RandomSelection>`): uses a small amount of separable functions to compute approximate objective
* **`CMAES<>`** (equivalent to `CMAES<FullSelection, EmptyTransformation<>>`): uses all separable functions to compute objective
* **`ApproxCMAES<>`** (equivalent to `CMAES<RandomSelection, EmptyTransformation<>>`): uses a small amount of separable functions to compute approximate objective

#### Attributes

| **type** | **name** | **description** | **default** |
|----------|----------|-----------------|-------------|
| `size_t` | **`lambda`** | The population size (0 uses a default size). | `0` |
| `double` | **`lowerBound`** | Lower bound of decision variables. | `-10.0` |
| `double` | **`upperBound`** | Upper bound of decision variables. | `10.0` |
| `TransformationPolicyType` | **`transformationPolicy`** | Instantiated transformation policy used to map the coordinates to the desired domain. | `TransformationPolicyType()` |
| `size_t` | **`batchSize`** | Batch size to use for the objective calculation. | `32` |
| `size_t` | **`maxIterations`** | Maximum number of iterations. | `1000` |
| `double` | **`tolerance`** | Maximum absolute tolerance to terminate algorithm. | `1e-5` |
| `SelectionPolicyType` | **`selectionPolicy`** | Instantiated selection policy used to calculate the objective. | `SelectionPolicyType()` |
| `size_t` | **`stepSize`** | Initial step size | `0` |

Attributes of the optimizer may also be changed via the member methods
`Lambda()`, `LowerBound()`, `UpperBound()`, `BatchSize()`, `MaxIterations()`,
`Lambda()`, `TransformationPolicy()`, `BatchSize()`, `MaxIterations()`,
`Tolerance()`, and `SelectionPolicy()`.

The `selectionPolicy` attribute allows an instantiated `SelectionPolicyType` to
Expand All @@ -733,6 +831,12 @@ the option is not relevant when the `CMAES<>` optimizer type is being used; the
`RandomSelection` policy has the constructor `RandomSelection(`_`fraction`_`)`
where _`fraction`_ specifies the percentage of separable functions to use to
estimate the objective function.
The `transformationPolicy` attribute allows an instantiated
`TransformationPolicyType` to be given. The `EmptyTransformation<`_`MatType`_`>`
has no need to be instantiated. `BoundaryBoxConstraint<`_`MatType`_`>` policy has
the constructor `BoundaryBoxConstraint(`_`lowerBound, upperBound`_`)`
where _`lowerBound`_ and _`lowerBound`_ are the lower bound and upper bound of
the coordinates respectively.

#### Examples:

Expand All @@ -744,12 +848,13 @@ estimate the objective function.
RosenbrockFunction f;
arma::mat coordinates = f.GetInitialPoint();

// CMAES with the FullSelection policy.
CMAES<> optimizer(0, -1, 1, 32, 200, 1e-4);
// CMAES with the FullSelection and BoundaryBoxConstraint policies.
BoundaryBoxConstraint b(-1, 1);
CMAES optimizer(0, b, 32, 200, 1e-4);
optimizer.Optimize(f, coordinates);

// CMAES with the RandomSelection policy.
ApproxCMAES<> approxOptimizer(0, -1, 1. 32, 200, 1e-4);
// CMAES with the RandomSelection and BoundaryBoxConstraint policies.
ApproxCMAES<BoundaryBoxConstraint<>> cmaes(0, b, 32, 200, 1e-4);
approxOptimizer.Optimize(f, coordinates);
```

Expand Down
1 change: 1 addition & 0 deletions include/ensmallen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
#include "ensmallen_bits/aug_lagrangian/aug_lagrangian.hpp"
#include "ensmallen_bits/bigbatch_sgd/bigbatch_sgd.hpp"
#include "ensmallen_bits/cmaes/cmaes.hpp"
#include "ensmallen_bits/cmaes/active_cmaes.hpp"
#include "ensmallen_bits/cne/cne.hpp"
#include "ensmallen_bits/de/de.hpp"
#include "ensmallen_bits/eve/eve.hpp"
Expand Down
Loading