Skip to content

Commit 1ac0467

Browse files
committed
working python binding
1 parent a27b929 commit 1ac0467

13 files changed

Lines changed: 183 additions & 96 deletions

include/matrix_adaptation.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ namespace matrix_adaptation
2727
virtual void adapt_evolution_paths_inner(const Population& pop, const parameters::Weights& w,
2828
const parameters::Stats& stats, size_t mu, size_t lambda) = 0;
2929

30-
virtual bool adapt_matrix(const parameters::Weights& w, const parameters::Modules& m, const Population& pop,
30+
virtual bool adapt_matrix(
31+
const parameters::Weights& w, const parameters::Modules& m, const Population& pop,
3132
size_t mu, const parameters::Settings& settings, parameters::Stats& stats) = 0;
3233

3334
virtual Vector compute_y(const Vector&) = 0;
@@ -79,7 +80,6 @@ namespace matrix_adaptation
7980
Matrix inv_root_C;
8081
bool hs = true;
8182

82-
8383
CovarianceAdaptation(const size_t dim, const Vector& x0, const Float expected_length_z) : Adaptation(dim, x0, Vector::Zero(dim), expected_length_z),
8484
pc(Vector::Zero(dim)),
8585
d(Vector::Ones(dim)),

include/mutation.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,11 @@ namespace mutation
101101
virtual void mutate(FunctionType& objective, const size_t n_offspring, parameters::Parameters& p);
102102

103103
virtual void adapt(const parameters::Weights& w, std::shared_ptr<matrix_adaptation::Adaptation> adaptation, Population& pop,
104-
const Population& old_pop, const parameters::Stats& stats, const size_t lambda) = 0;
104+
const Population& old_pop, const parameters::Stats& stats, const size_t lambda) {};
105105
};
106106

107107
struct CSA : Strategy
108108
{
109-
110109
using Strategy::Strategy;
111110

112111
void adapt(const parameters::Weights& w, std::shared_ptr<matrix_adaptation::Adaptation> adaptation, Population& pop,

include/population.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ struct Population
1515
size_t n;
1616

1717
Population(const size_t d, const size_t n)
18-
: X(d, n), Z(d, n), Y(d, n), f(Vector::Constant(n, std::numeric_limits<Float>::infinity())), s(n), d(d), n(n), t(n) {}
18+
: X(d, n), Z(d, n), Y(d, n), f(Vector::Constant(n, std::numeric_limits<Float>::infinity())), s(n), t(n), d(d), n(n) {}
1919

2020
Population(const Matrix &X, const Matrix &Z, const Matrix &Y, const Vector &f, const Vector &s)
21-
: X(X), Z(Z), Y(Y), f(f), s(s), d(X.rows()), n(X.cols()) {}
21+
: X(X), Z(Z), Y(Y), f(f), s(s), t(f.rows()), d(X.rows()), n(X.cols()) {}
2222

2323
Population() : Population(0, 0) {}
2424

include/sampling.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ namespace sampling
263263

264264
[[nodiscard]] inline Vector box_muller(const Vector& u)
265265
{
266-
int n = u.size();
267-
int m = n / 2;
266+
size_t n = u.size();
267+
size_t m = n / 2;
268268

269269
Vector z(n);
270270
for (size_t i = 0; i < m; ++i) {

include/weights.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#pragma once
22

3-
43
#include "settings.hpp"
54

65
namespace parameters
76
{
8-
struct Weights
7+
struct Weights
98
{
109
Vector weights;
1110
Vector positive;
@@ -20,7 +19,8 @@ namespace parameters
2019
Float expected_length_ps;
2120
Float beta;
2221

23-
Weights(const size_t dim, const size_t mu, const size_t lambda, const Settings &settings, const Float expected_length_z);
22+
Weights(const size_t dim, const size_t mu, const size_t lambda, const Settings &settings,
23+
const Float expected_length_z);
2424

2525
void weights_default(const size_t mu, const size_t lambda);
2626

modcma/c_maes/cmaescpp/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Population:
3434
f: numpy.ndarray
3535
n: int
3636
s: numpy.ndarray
37+
t: numpy.ndarray
3738
@overload
3839
def __init__(self, dimension: int, n: int) -> None: ...
3940
@overload

modcma/c_maes/cmaescpp/matrix_adaptation.pyi

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,26 @@ class OnePlusOneAdaptation(CovarianceAdaptation):
4040
def __init__(self, dimension: int, x0: numpy.ndarray, expected_length_z: float) -> None: ...
4141

4242
class SeperableAdaptation(CovarianceAdaptation):
43+
c: numpy.ndarray
44+
pc: numpy.ndarray
45+
d: numpy.ndarray
46+
def __init__(self, dimension: int, x0: numpy.ndarray, expected_length_z: float) -> None: ...
47+
48+
class CovarainceNoEigvAdaptation(CovarainceNoEigvAdaptation):
49+
def __init__(self, dimension: int, x0: numpy.ndarray, expected_length_z: float) -> None: ...
50+
51+
class CholeskyAdaptation(Adaptation):
52+
A: numpy.ndarray
53+
pc: numpy.ndarray
54+
def __init__(self, dimension: int, x0: numpy.ndarray, expected_length_z: float) -> None: ...
55+
56+
class SelfAdaptation(Adaptation):
57+
A: numpy.ndarray
58+
C: numpy.ndarray
4359
def __init__(self, dimension: int, x0: numpy.ndarray, expected_length_z: float) -> None: ...
60+
61+
class NaturalGradientAdaptation(Adaptation):
62+
A: numpy.ndarray
63+
G: numpy.ndarray
64+
A_inv: numpy.ndarray
65+
def __init__(self, dimension: int, x0: numpy.ndarray, expected_length_z: float) -> None: ...

modcma/c_maes/cmaescpp/mutation.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ class SigmaSampler:
9797
beta: float
9898
def __init__(self, dimension: float) -> None: ...
9999
def sample(
100-
self, sigma: float, population: modcma.c_maes.cmaescpp.Population
100+
self, sigma: float, population: modcma.c_maes.cmaescpp.Population, beta: float
101101
) -> None: ...
102102

103103
class Strategy:
104-
cs: float
105104
s: float
106105
sequential_selection: SequentialSelection
107106
sigma: float

modcma/c_maes/cmaescpp/options.pyi

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,16 @@ class CorrectionMethod:
112112

113113
class MatrixAdaptationType:
114114
__members__: ClassVar[dict] = ... # read-only
115+
NONE: ClassVar[MatrixAdaptationType] = ...
115116
COVARIANCE: ClassVar[MatrixAdaptationType] = ...
116117
MATRIX: ClassVar[MatrixAdaptationType] = ...
117-
NONE: ClassVar[MatrixAdaptationType] = ...
118118
SEPERABLE: ClassVar[MatrixAdaptationType] = ...
119+
ONEPLUSONE: ClassVar[MatrixAdaptationType] = ...
120+
CHOLESKY: ClassVar[MatrixAdaptationType] = ...
121+
CMSA: ClassVar[MatrixAdaptationType] = ...
122+
COVARIANCE_NO_EIGV: ClassVar[MatrixAdaptationType] = ...
123+
NATURAL_GRADIENT: ClassVar[MatrixAdaptationType] = ...
124+
119125
__entries: ClassVar[dict] = ...
120126
def __init__(self, value: int) -> None: ...
121127
def __eq__(self, other: object) -> bool: ...
@@ -184,12 +190,15 @@ class RestartStrategy:
184190
class StepSizeAdaptation:
185191
__members__: ClassVar[dict] = ... # read-only
186192
CSA: ClassVar[StepSizeAdaptation] = ...
187-
LPXNES: ClassVar[StepSizeAdaptation] = ...
193+
TPA: ClassVar[StepSizeAdaptation] = ...
188194
MSR: ClassVar[StepSizeAdaptation] = ...
195+
XNES: ClassVar[StepSizeAdaptation] = ...
189196
MXNES: ClassVar[StepSizeAdaptation] = ...
197+
LPXNES: ClassVar[StepSizeAdaptation] = ...
190198
PSR: ClassVar[StepSizeAdaptation] = ...
191-
TPA: ClassVar[StepSizeAdaptation] = ...
192-
XNES: ClassVar[StepSizeAdaptation] = ...
199+
SR: ClassVar[StepSizeAdaptation] = ...
200+
SA: ClassVar[StepSizeAdaptation] = ...
201+
193202
__entries: ClassVar[dict] = ...
194203
def __init__(self, value: int) -> None: ...
195204
def __eq__(self, other: object) -> bool: ...

modcma/c_maes/cmaescpp/parameters.pyi

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Settings:
5656
cmu: float | None = ...,
5757
c1: float | None = ...,
5858
verbose: bool = ...,
59+
always_compute_eigv: bool | False = ...
5960
) -> None: ...
6061

6162
class Solution:
@@ -66,23 +67,34 @@ class Solution:
6667
def __init__(self) -> None: ...
6768

6869
class Stats:
69-
centers: list[Solution]
70-
current_avg: float
71-
current_best: Solution
70+
t: int
7271
evaluations: int
72+
current_avg: float
73+
solutions: list[Solution]
74+
centers: list[Solution]
7375
global_best: Solution
76+
current_best: Solution
7477
has_improved: bool
75-
solutions: list[Solution]
7678
success_ratio: float
77-
t: int
79+
cs: float
80+
last_update: int
81+
n_updates: int
7882
def __init__(self) -> None: ...
7983

8084
class Weights:
81-
c1: float
82-
cc: float
83-
cmu: float
8485
mueff: float
8586
mueff_neg: float
87+
c1: float
88+
cmu: float
89+
cc: float
90+
cs: float
91+
damps: float
92+
sqrt_cc_mueff: float
93+
sqrt_cs_mueff: float
94+
lazy_update_interval: float
95+
expected_length_z: float
96+
expected_length_ps: float
97+
beta: float
8698
negative: numpy.ndarray
8799
positive: numpy.ndarray
88100
weights: numpy.ndarray

0 commit comments

Comments
 (0)