Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthias Mayr
limbo
Commits
00638372
Commit
00638372
authored
Oct 15, 2015
by
Konstantinos Chatzilygeroudis
Browse files
Switched to Stroustrup break braces version
parent
086bd2a4
Changes
45
Show whitespace changes
Inline
Side-by-side
src/benchmarks/multi.cpp
View file @
00638372
...
...
@@ -5,43 +5,41 @@
using
namespace
limbo
;
struct
Params
{
struct
boptimizer
{
struct
Params
{
struct
boptimizer
{
BO_PARAM
(
double
,
noise
,
0.01
);
BO_PARAM
(
int
,
dump_period
,
1
);
};
struct
init
{
struct
init
{
BO_PARAM
(
int
,
nb_samples
,
10
);
// calandra: number of dimensions * 5
// knowles : 11 * dim - 1
};
struct
parego
:
public
defaults
::
parego
{
struct
parego
:
public
defaults
::
parego
{
};
struct
maxiterations
{
struct
maxiterations
{
BO_PARAM
(
int
,
n_iterations
,
30
);
};
struct
ucb
:
public
defaults
::
ucb
{
struct
ucb
:
public
defaults
::
ucb
{
};
struct
gp_ucb
:
public
defaults
::
gp_ucb
{
struct
gp_ucb
:
public
defaults
::
gp_ucb
{
};
struct
cmaes
:
public
defaults
::
cmaes
{
struct
cmaes
:
public
defaults
::
cmaes
{
};
struct
gp_auto
:
public
defaults
::
gp_auto
{
struct
gp_auto
:
public
defaults
::
gp_auto
{
};
struct
meanconstant
:
public
defaults
::
meanconstant
{
struct
meanconstant
:
public
defaults
::
meanconstant
{
};
struct
ehvi
{
struct
ehvi
{
BO_PARAM
(
double
,
x_ref
,
-
11
);
BO_PARAM
(
double
,
y_ref
,
-
11
);
};
...
...
@@ -55,8 +53,7 @@ struct Params
#define ZDT_DIM 30
#endif
struct
zdt1
{
struct
zdt1
{
static
constexpr
size_t
dim
=
ZDT_DIM
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
...
...
@@ -73,8 +70,7 @@ struct zdt1
}
};
struct
zdt2
{
struct
zdt2
{
static
constexpr
size_t
dim
=
ZDT_DIM
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
...
...
@@ -91,8 +87,7 @@ struct zdt2
}
};
struct
zdt3
{
struct
zdt3
{
static
constexpr
size_t
dim
=
ZDT_DIM
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
...
...
@@ -109,8 +104,7 @@ struct zdt3
}
};
struct
mop2
{
struct
mop2
{
static
constexpr
size_t
dim
=
2
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
...
...
@@ -129,13 +123,12 @@ struct mop2
}
};
namespace
limbo
{
namespace
stat
{
namespace
limbo
{
namespace
stat
{
template
<
typename
F
>
struct
ParetoBenchmark
{
struct
ParetoBenchmark
{
template
<
typename
BO
>
void
operator
()(
BO
&
opt
)
{
...
...
src/cmaes/boundary_transformation.c
View file @
00638372
...
...
@@ -28,8 +28,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
t
->
lower_bounds
=
default_lower
;
if
(
upper_bounds
==
NULL
&&
len_of_bounds
<=
1
)
t
->
upper_bounds
=
default_upper
;
if
(
len_of_bounds
==
0
)
{
if
(
len_of_bounds
==
0
)
{
t
->
lower_bounds
=
default_lower
;
t
->
upper_bounds
=
default_upper
;
t
->
len_of_bounds
=
1
;
...
...
@@ -47,8 +46,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
lb
=
t
->
lower_bounds
;
ub
=
t
->
upper_bounds
;
for
(
i
=
0
;
i
<
t
->
len_of_bounds
;
++
i
)
{
for
(
i
=
0
;
i
<
t
->
len_of_bounds
;
++
i
)
{
if
(
lb
[
i
]
==
ub
[
i
])
_FatalError
(
"in _init: lower and upper bounds must be different in all "
"variables"
);
...
...
@@ -71,8 +69,7 @@ void boundary_transformation(boundary_transformation_t* t, double const* x,
double
lb
,
ub
,
al
,
au
;
unsigned
long
i
;
boundary_transformation_shift_into_feasible_preimage
(
t
,
x
,
y
,
len
);
for
(
i
=
0
;
i
<
len
;
++
i
)
{
for
(
i
=
0
;
i
<
len
;
++
i
)
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
...
@@ -92,8 +89,7 @@ void boundary_transformation_discrete(boundary_transformation_t* t,
unsigned
long
i
;
// boundary_transformation_shift_into_feasible_preimage(t, x, y, len);
for
(
i
=
0
;
i
<
len
;
++
i
)
{
for
(
i
=
0
;
i
<
len
;
++
i
)
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
...
@@ -114,8 +110,7 @@ void boundary_transformation_shift_into_feasible_preimage(
double
lb
,
ub
,
al
,
au
,
r
,
xlow
,
xup
;
unsigned
long
i
;
for
(
i
=
0
;
i
<
len
;
++
i
)
{
for
(
i
=
0
;
i
<
len
;
++
i
)
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
...
@@ -126,12 +121,10 @@ void boundary_transformation_shift_into_feasible_preimage(
y
[
i
]
=
x
[
i
];
if
(
y
[
i
]
<
xlow
)
{
/* shift up */
if
(
y
[
i
]
<
xlow
)
{
/* shift up */
y
[
i
]
+=
r
*
(
1
+
(
int
)((
xlow
-
y
[
i
])
/
r
));
}
if
(
y
[
i
]
>
xup
)
{
/* shift down */
if
(
y
[
i
]
>
xup
)
{
/* shift down */
y
[
i
]
-=
r
*
(
1
+
(
int
)((
y
[
i
]
-
xup
)
/
r
));
/* printf(" \n%f\n", fmod(y[i] - ub - au, r)); */
}
...
...
@@ -140,8 +133,7 @@ void boundary_transformation_shift_into_feasible_preimage(
if
(
y
[
i
]
>
ub
+
au
)
y
[
i
]
-=
2
*
(
y
[
i
]
-
ub
-
au
);
if
((
y
[
i
]
<
lb
-
al
-
1e-15
)
||
(
y
[
i
]
>
ub
+
au
+
1e-15
))
{
if
((
y
[
i
]
<
lb
-
al
-
1e-15
)
||
(
y
[
i
]
>
ub
+
au
+
1e-15
))
{
printf
(
"BUG in boundary_transformation_shift_into_feasible_preimage: "
"lb=%f, ub=%f, al=%f au=%f, y=%f
\n
"
,
lb
,
ub
,
al
,
au
,
y
[
i
]);
...
...
@@ -156,8 +148,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
double
lb
,
ub
,
al
,
au
;
unsigned
long
i
;
for
(
i
=
0
;
i
<
len
;
++
i
)
{
for
(
i
=
0
;
i
<
len
;
++
i
)
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
...
@@ -168,8 +159,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
else
if
(
y
[
i
]
>
ub
-
au
)
y
[
i
]
=
(
ub
+
au
)
-
2
*
sqrt
(
au
*
(
ub
-
y
[
i
]));
}
if
(
11
<
3
||
do_assertions
)
{
if
(
11
<
3
||
do_assertions
)
{
double
*
z
=
calloc
(
len
,
sizeof
(
double
));
for
(
i
=
0
;
i
<
len
;
++
i
)
z
[
i
]
=
y
[
i
];
...
...
src/cmaes/boundary_transformation.h
View file @
00638372
...
...
@@ -26,7 +26,7 @@ extern "C" {
*/
typedef
struct
{
{
double
const
*
lower_bounds
;
/* array of size len_of_bounds */
double
const
*
upper_bounds
;
/* array of size len_of_bounds */
unsigned
long
len_of_bounds
;
/* in case, last value is recycled */
...
...
src/cmaes/cmaes.c
View file @
00638372
...
...
@@ -312,8 +312,7 @@ use cmaes_exit first\n");
t
->
arFuncValueHist
[
0
]
=
(
double
)(
10
+
(
int
)
ceil
(
3
.
*
10
.
*
N
/
t
->
sp
.
lambda
));
t
->
arFuncValueHist
++
;
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
t
->
C
[
i
]
=
new_double
(
i
+
1
);
t
->
B
[
i
]
=
new_double
(
N
);
}
...
...
@@ -321,8 +320,7 @@ use cmaes_exit first\n");
for
(
i
=
0
;
i
<
t
->
sp
.
lambda
;
++
i
)
t
->
index
[
i
]
=
i
;
/* should not be necessary */
t
->
rgrgx
=
(
double
**
)
new_void
(
t
->
sp
.
lambda
,
sizeof
(
double
*
));
for
(
i
=
0
;
i
<
t
->
sp
.
lambda
;
++
i
)
{
for
(
i
=
0
;
i
<
t
->
sp
.
lambda
;
++
i
)
{
t
->
rgrgx
[
i
]
=
new_double
(
N
+
2
);
t
->
rgrgx
[
i
][
0
]
=
N
;
t
->
rgrgx
[
i
]
++
;
...
...
@@ -334,8 +332,7 @@ use cmaes_exit first\n");
for
(
j
=
0
;
j
<
i
;
++
j
)
t
->
C
[
i
][
j
]
=
t
->
B
[
i
][
j
]
=
t
->
B
[
j
][
i
]
=
0
.;
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
t
->
B
[
i
][
i
]
=
1
.;
t
->
C
[
i
][
i
]
=
t
->
rgD
[
i
]
=
t
->
sp
.
rgInitialStds
[
i
]
*
sqrt
(
N
/
trace
);
t
->
C
[
i
][
i
]
*=
t
->
C
[
i
][
i
];
...
...
@@ -379,8 +376,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
int
i
,
j
,
res
,
n
;
double
d
;
FILE
*
fp
=
fopen
(
filename
,
"r"
);
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
ERRORMESSAGE
(
"cmaes_resume_distribution(): could not open '"
,
filename
,
"'"
,
0
);
return
;
...
...
@@ -388,8 +384,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
/* count number of "resume" entries */
i
=
0
;
res
=
0
;
while
(
1
)
{
while
(
1
)
{
if
((
res
=
fscanf
(
fp
,
" resume %lg"
,
&
d
))
==
EOF
)
break
;
else
if
(
res
==
0
)
...
...
@@ -403,8 +398,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
i
=
0
;
res
=
0
;
rewind
(
fp
);
while
(
i
<
n
)
{
while
(
i
<
n
)
{
if
((
res
=
fscanf
(
fp
,
" resume %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): Unexpected error, bug"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
...
...
@@ -417,8 +411,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
0
);
/* find next "xmean" entry */
while
(
1
)
{
while
(
1
)
{
if
((
res
=
fscanf
(
fp
,
" xmean %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'xmean' not found"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
...
...
@@ -436,8 +429,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
FATAL
(
"cmaes_resume_distribution(): xmean: dimensions differ"
,
0
,
0
,
0
);
/* find next "path for sigma" entry */
while
(
1
)
{
while
(
1
)
{
if
((
res
=
fscanf
(
fp
,
" path for sigma %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'path for sigma' not found"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
...
...
@@ -455,8 +447,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
FATAL
(
"cmaes_resume_distribution(): ps: dimensions differ"
,
0
,
0
,
0
);
/* find next "path for C" entry */
while
(
1
)
{
while
(
1
)
{
if
((
res
=
fscanf
(
fp
,
" path for C %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'path for C' not found"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
...
...
@@ -473,8 +464,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
FATAL
(
"cmaes_resume_distribution(): pc: dimensions differ"
,
0
,
0
,
0
);
/* find next "sigma" entry */
while
(
1
)
{
while
(
1
)
{
if
((
res
=
fscanf
(
fp
,
" sigma %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'sigma' not found"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
...
...
@@ -485,8 +475,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
t
->
sigma
=
d
;
/* find next entry "covariance matrix" */
while
(
1
)
{
while
(
1
)
{
if
((
res
=
fscanf
(
fp
,
" covariance matrix %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'covariance matrix' not found"
,
0
,
0
,
0
);
...
...
@@ -528,8 +517,7 @@ void cmaes_exit(cmaes_t* t)
free
(
--
t
->
rgxbestever
);
free
(
--
t
->
rgout
);
free
(
t
->
rgD
);
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
free
(
t
->
C
[
i
]);
free
(
t
->
B
[
i
]);
}
...
...
@@ -581,12 +569,10 @@ double* const* cmaes_SamplePopulation(cmaes_t* t)
/* cmaes_SetMean(t, xmean); * xmean could be changed at this point */
/* calculate eigensystem */
if
(
!
t
->
flgEigensysIsUptodate
)
{
if
(
!
t
->
flgEigensysIsUptodate
)
{
if
(
!
flgdiag
)
cmaes_UpdateEigensystem
(
t
,
0
);
else
{
else
{
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgD
[
i
]
=
sqrt
(
t
->
C
[
i
][
i
]);
t
->
minEW
=
douSquare
(
rgdouMin
(
t
->
rgD
,
N
));
...
...
@@ -599,8 +585,7 @@ double* const* cmaes_SamplePopulation(cmaes_t* t)
/* treat minimal standard deviations and numeric problems */
TestMinStdDevs
(
t
);
for
(
iNk
=
0
;
iNk
<
t
->
sp
.
lambda
;
++
iNk
)
{
for
(
iNk
=
0
;
iNk
<
t
->
sp
.
lambda
;
++
iNk
)
{
/* generate scaled random vector (D * z) */
for
(
i
=
0
;
i
<
N
;
++
i
)
if
(
flgdiag
)
...
...
@@ -609,8 +594,7 @@ double* const* cmaes_SamplePopulation(cmaes_t* t)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
if
(
!
flgdiag
)
/* add mutation (sigma * B * (D*z)) */
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
t
->
rgrgx
[
iNk
][
i
]
=
xmean
[
i
]
+
t
->
sigma
*
sum
;
...
...
@@ -636,8 +620,7 @@ double const* cmaes_ReSampleSingle_old(cmaes_t* t, double* rgx)
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
/* add mutation (sigma * B * (D*z)) */
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
rgx
[
i
]
=
t
->
rgxmean
[
i
]
+
t
->
sigma
*
sum
;
...
...
@@ -654,8 +637,7 @@ double* const* cmaes_ReSampleSingle(cmaes_t* t, int iindex)
double
sum
;
static
char
s
[
99
];
if
(
iindex
<
0
||
iindex
>=
t
->
sp
.
lambda
)
{
if
(
iindex
<
0
||
iindex
>=
t
->
sp
.
lambda
)
{
sprintf
(
s
,
"index==%d must be between 0 and %d"
,
iindex
,
t
->
sp
.
lambda
);
FATAL
(
"cmaes_ReSampleSingle(): Population member "
,
s
,
0
,
0
);
}
...
...
@@ -664,8 +646,7 @@ double* const* cmaes_ReSampleSingle(cmaes_t* t, int iindex)
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
/* add mutation (sigma * B * (D*z)) */
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
rgx
[
i
]
=
t
->
rgxmean
[
i
]
+
t
->
sigma
*
sum
;
...
...
@@ -686,8 +667,7 @@ double* cmaes_SampleSingleInto(cmaes_t* t, double* rgx)
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
/* add mutation (sigma * B * (D*z)) */
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
rgx
[
i
]
=
t
->
rgxmean
[
i
]
+
t
->
sigma
*
sum
;
...
...
@@ -711,8 +691,7 @@ double* cmaes_PerturbSolutionInto(cmaes_t* t, double* rgx, double const* xmean,
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
/* add mutation (sigma * B * (D*z)) */
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
rgx
[
i
]
=
xmean
[
i
]
+
eps
*
t
->
sigma
*
sum
;
...
...
@@ -733,14 +712,12 @@ const double* cmaes_Optimize(cmaes_t* evo,
int
i
;
long
startiter
=
evo
->
gen
;
while
(
!
(
stop
=
cmaes_TestForTermination
(
evo
))
&&
(
evo
->
gen
<
startiter
+
iterations
||
!
iterations
))
{
while
(
!
(
stop
=
cmaes_TestForTermination
(
evo
))
&&
(
evo
->
gen
<
startiter
+
iterations
||
!
iterations
))
{
/* Generate population of new candidate solutions */
pop
=
cmaes_SamplePopulation
(
evo
);
/* do not change content of pop */
/* Compute fitness value for each candidate solution */
for
(
i
=
0
;
i
<
cmaes_Get
(
evo
,
"popsize"
);
++
i
)
{
for
(
i
=
0
;
i
<
cmaes_Get
(
evo
,
"popsize"
);
++
i
)
{
evo
->
publicFitness
[
i
]
=
(
*
pFun
)(
pop
[
i
],
evo
->
sp
.
N
);
}
...
...
@@ -788,8 +765,7 @@ double* cmaes_UpdateDistribution(cmaes_t* t, const double* rgFunVal)
Sorted_index
(
rgFunVal
,
t
->
index
,
t
->
sp
.
lambda
);
/* Test if function values are identical, escape flat fitness */
if
(
t
->
rgFuncValue
[
t
->
index
[
0
]]
==
t
->
rgFuncValue
[
t
->
index
[(
int
)
t
->
sp
.
lambda
/
2
]])
{
if
(
t
->
rgFuncValue
[
t
->
index
[
0
]]
==
t
->
rgFuncValue
[
t
->
index
[(
int
)
t
->
sp
.
lambda
/
2
]])
{
t
->
sigma
*=
exp
(
0
.
2
+
t
->
sp
.
cs
/
t
->
sp
.
damps
);
ERRORMESSAGE
(
"Warning: sigma increased due to equal function values
\n
"
,
" Reconsider the formulation of the objective function"
,
0
,
...
...
@@ -804,15 +780,13 @@ double* cmaes_UpdateDistribution(cmaes_t* t, const double* rgFunVal)
/* update xbestever */
if
(
t
->
rgxbestever
[
N
]
>
t
->
rgrgx
[
t
->
index
[
0
]][
N
]
||
t
->
gen
==
1
)
for
(
i
=
0
;
i
<=
N
;
++
i
)
{
for
(
i
=
0
;
i
<=
N
;
++
i
)
{
t
->
rgxbestever
[
i
]
=
t
->
rgrgx
[
t
->
index
[
0
]][
i
];
t
->
rgxbestever
[
N
+
1
]
=
t
->
countevals
;
}
/* calculate xmean and rgBDz~N(0,C) */
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
t
->
rgxold
[
i
]
=
t
->
rgxmean
[
i
];
t
->
rgxmean
[
i
]
=
0
.;
for
(
iNk
=
0
;
iNk
<
t
->
sp
.
mu
;
++
iNk
)
...
...
@@ -821,8 +795,7 @@ double* cmaes_UpdateDistribution(cmaes_t* t, const double* rgFunVal)
}
/* calculate z := D^(-1) * B^(-1) * rgBDz into rgdTmp */
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
if
(
!
flgdiag
)
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
j
][
i
]
*
t
->
rgBDz
[
j
];
...
...
@@ -845,8 +818,7 @@ double* cmaes_UpdateDistribution(cmaes_t* t, const double* rgFunVal)
*/
/* cumulation for sigma (ps) using B*z */
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
if
(
!
flgdiag
)
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
...
...
@@ -861,14 +833,12 @@ double* cmaes_UpdateDistribution(cmaes_t* t, const double* rgFunVal)
/* cumulation for covariance matrix (pc) using B*D*z~N(0,C) */
hsig
=
sqrt
(
psxps
)
/
sqrt
(
1
.
-
pow
(
1
.
-
t
->
sp
.
cs
,
2
*
t
->
gen
))
/
t
->
chiN
<
1
.
4
+
2
.
/
(
N
+
1
);
for
(
i
=
0
;
i
<
N
;
++
i
)
{
for
(
i
=
0
;
i
<
N
;
++
i
)
{
t
->
rgpc
[
i
]
=
(
1
.
-
t
->
sp
.
ccumcov
)
*
t
->
rgpc
[
i
]
+
hsig
*
sqrt
(
t
->
sp
.
ccumcov
*
(
2
.
-
t
->
sp
.
ccumcov
))
*
t
->
rgBDz
[
i
];
}
/* stop initial phase */
if
(
t
->
flgIniphase
&&
t
->
gen
>
douMin
(
1
/
t
->
sp
.
cs
,
1
+
N
/
t
->
sp
.
mucov
))
{
if
(
t
->
flgIniphase
&&
t
->
gen
>
douMin
(
1
/
t
->
sp
.
cs
,
1
+
N
/
t
->
sp
.
mucov
))
{
if
(
psxps
/
t
->
sp
.
damps
/
(
1
.
-
pow
((
1
.
-
t
->
sp
.
cs
),
t
->
gen
))
<
N
*
1
.
05
)
t
->
flgIniphase
=
0
;
}
...
...
@@ -930,8 +900,7 @@ static void Adapt_C2(cmaes_t* t, int hsig)
int
i
,
j
,
k
,
N
=
t
->
sp
.
N
;
int
flgdiag
=
((
t
->
sp
.
diagonalCov
==
1
)
||
(
t
->
sp
.
diagonalCov
>=
t
->
gen
));
if
(
t
->
sp
.
ccov
!=
0
.
&&
t
->
flgIniphase
==
0
)
{
if
(
t
->
sp
.
ccov
!=
0
.
&&
t
->
flgIniphase
==
0
)
{
/* definitions for speeding up inner-most loop */
double
ccov1
=
douMin
(
...
...
@@ -944,18 +913,15 @@ static void Adapt_C2(cmaes_t* t, int hsig)
/* update covariance matrix */
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
j
=
flgdiag
?
i
:
0
;
j
<=
i
;
++
j
)
{
for
(
j
=
flgdiag
?
i
:
0
;
j
<=
i
;
++
j
)
{
t
->
C
[
i
][
j
]
=
(
1
-
ccov1
-
ccovmu
)
*
t
->
C
[
i
][
j
]
+
ccov1
*
(
t
->
rgpc
[
i
]
*
t
->
rgpc
[
j
]
+
(
1
-
hsig
)
*
t
->
sp
.
ccumcov
*
(
2
.
-
t
->
sp
.
ccumcov
)
*
t
->
C
[
i
][
j
]);
for
(
k
=
0
;
k
<
t
->
sp
.
mu
;
++
k
)
{
/* additional rank mu update */
for
(
k
=
0
;
k
<
t
->
sp
.
mu
;
++
k
)
{
/* additional rank mu update */
t
->
C
[
i
][
j
]
+=
ccovmu
*
t
->
sp
.
weights
[
k
]
*
(
t
->
rgrgx
[
t
->
index
[
k
]][
i
]
-
t
->
rgxold
[
i
])
*
(
t
->
rgrgx
[
t
->
index
[
k
]][
j
]
-
t
->
rgxold
[
j
])
/
sigmasquare
;
}
}
/* update maximal and minimal diagonal value */
t
->
maxdiagC
=
t
->
mindiagC
=
t
->
C
[
0
][
0
];
for
(
i
=
1
;
i
<
N
;
++
i
)
{
for
(
i
=
1
;
i
<
N
;
++
i
)
{
if
(
t
->
maxdiagC
<
t
->
C
[
i
][
i
])
t
->
maxdiagC
=
t
->
C
[
i
][
i
];
else
if
(
t
->
mindiagC
>
t
->
C
[
i
][
i
])
...
...
@@ -999,15 +965,13 @@ void cmaes_WriteToFileAW(cmaes_t* t, const char* key, const char* name,
fp
=
fopen
(
name
,
appendwrite
);
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
ERRORMESSAGE
(
"cmaes_WriteToFile(): could not open '"
,
name
,
"' with flag "
,
appendwrite
);
return
;
}
if
(
appendwrite
[
0
]
==
'w'
)
{
if
(
appendwrite
[
0
]
==
'w'
)
{
/* write a header line, very rudimentary */
fprintf
(
fp
,
"%% # %s (randomSeed=%d, %s)
\n
"
,
key
,
t
->
sp
.
seed
,
getTimeStr
());
}
...
...
@@ -1037,17 +1001,14 @@ void cmaes_WriteToFilePtr(cmaes_t* t, const char* key, FILE* fp)
/* keystart = key; for debugging purpose */
keyend
=
key
+
strlen
(
key
);
while
(
key
<
keyend
)
{
if
(
strncmp
(
key
,
"axisratio"
,
9
)
==
0
)
{
while
(
key
<
keyend
)
{
if
(
strncmp
(
key
,
"axisratio"
,
9
)
==
0
)
{
fprintf
(
fp
,
"%.2e"
,
sqrt
(
t
->
maxEW
/
t
->
minEW
));
while
(
*
key
!=
'+'
&&
*
key
!=
'\0'
&&
key
<
keyend
)
++
key
;
fprintf
(
fp
,
"%c"
,
(
*
key
==
'+'
)
?
'\t'
:
'\n'
);
}
if
(
strncmp
(
key
,
"idxminSD"
,
8
)
==
0
)
{
if
(
strncmp
(
key
,
"idxminSD"
,
8
)
==
0
)
{
int
mini
=
0
;
for
(
i
=
N
-
1
;
i
>
0
;
--
i
)
if
(
t
->
mindiagC
==
t
->
C
[
i
][
i
])
...
...
@@ -1057,8 +1018,7 @@ void cmaes_WriteToFilePtr(cmaes_t* t, const char* key, FILE* fp)
++
key
;
fprintf
(
fp
,
"%c"
,
(
*
key
==
'+'
)
?
'\t'
:
'\n'
);
}
if
(
strncmp
(
key
,
"idxmaxSD"
,
8
)
==
0
)
{
if
(
strncmp
(
key
,
"idxmaxSD"
,
8
)
==
0
)
{
int
maxi
=
0
;
for
(
i
=
N
-
1
;
i
>
0
;
--
i
)
if
(
t
->
maxdiagC
==
t
->
C
[
i
][
i
])
...
...
@@ -1069,8 +1029,7 @@ void cmaes_WriteToFilePtr(cmaes_t* t, const char* key, FILE* fp)
fprintf
(
fp
,
"%c"
,
(
*
key
==
'+'
)
?
'\t'
:
'\n'
);
}
/* new coordinate system == all eigenvectors */
if
(
strncmp
(
key
,
"B"
,
1
)
==
0
)
{
if
(
strncmp
(
key
,
"B"
,
1
)
==
0
)
{
/* int j, index[N]; */
int
j
,
*
iindex
=
(
int
*
)(
new_void
(
N
,
sizeof
(
int
)));
/* MT */
Sorted_index
(
t
->
rgD
,
iindex
,
...
...
@@ -1084,8 +1043,7 @@ void cmaes_WriteToFilePtr(cmaes_t* t, const char* key, FILE* fp)
free
(
iindex
);
/* MT */
}
/* covariance matrix */
if
(
strncmp
(
key
,
"C"
,
1
)
==
0
)
{
if
(
strncmp
(
key
,
"C"
,
1
)
==
0
)
{
int
j
;
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
j
=
0
;
j
<=
i
;
++
j
)
...
...
@@ -1093,8 +1051,7 @@ void cmaes_WriteToFilePtr(cmaes_t* t, const char* key, FILE* fp)
++
key
;
}
/* (processor) time (used) since begin of execution */
if
(
strncmp
(
key
,
"clock"
,
4
)
==
0
)
{
if
(
strncmp
(
key
,
"clock"
,
4
)
==
0
)
{