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
Hide whitespace changes
Inline
Side-by-side
src/benchmarks/multi.cpp
View file @
00638372
...
@@ -5,43 +5,41 @@
...
@@ -5,43 +5,41 @@
using
namespace
limbo
;
using
namespace
limbo
;
struct
Params
struct
Params
{
{
struct
boptimizer
{
struct
boptimizer
{
BO_PARAM
(
double
,
noise
,
0.01
);
BO_PARAM
(
double
,
noise
,
0.01
);
BO_PARAM
(
int
,
dump_period
,
1
);
BO_PARAM
(
int
,
dump_period
,
1
);
};
};
struct
init
{
struct
init
{
BO_PARAM
(
int
,
nb_samples
,
10
);
BO_PARAM
(
int
,
nb_samples
,
10
);
// calandra: number of dimensions * 5
// calandra: number of dimensions * 5
// knowles : 11 * dim - 1
// knowles : 11 * dim - 1
};
};
struct
parego
:
public
defaults
::
parego
{
struct
parego
:
public
defaults
::
parego
{
};
};
struct
maxiterations
{
struct
maxiterations
{
BO_PARAM
(
int
,
n_iterations
,
30
);
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
,
x_ref
,
-
11
);
BO_PARAM
(
double
,
y_ref
,
-
11
);
BO_PARAM
(
double
,
y_ref
,
-
11
);
};
};
...
@@ -55,8 +53,7 @@ struct Params
...
@@ -55,8 +53,7 @@ struct Params
#define ZDT_DIM 30
#define ZDT_DIM 30
#endif
#endif
struct
zdt1
struct
zdt1
{
{
static
constexpr
size_t
dim
=
ZDT_DIM
;
static
constexpr
size_t
dim
=
ZDT_DIM
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
{
...
@@ -73,8 +70,7 @@ struct zdt1
...
@@ -73,8 +70,7 @@ struct zdt1
}
}
};
};
struct
zdt2
struct
zdt2
{
{
static
constexpr
size_t
dim
=
ZDT_DIM
;
static
constexpr
size_t
dim
=
ZDT_DIM
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
{
...
@@ -91,8 +87,7 @@ struct zdt2
...
@@ -91,8 +87,7 @@ struct zdt2
}
}
};
};
struct
zdt3
struct
zdt3
{
{
static
constexpr
size_t
dim
=
ZDT_DIM
;
static
constexpr
size_t
dim
=
ZDT_DIM
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
{
...
@@ -109,8 +104,7 @@ struct zdt3
...
@@ -109,8 +104,7 @@ struct zdt3
}
}
};
};
struct
mop2
struct
mop2
{
{
static
constexpr
size_t
dim
=
2
;
static
constexpr
size_t
dim
=
2
;
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
Eigen
::
VectorXd
operator
()(
const
Eigen
::
VectorXd
&
x
)
const
{
{
...
@@ -129,13 +123,12 @@ struct mop2
...
@@ -129,13 +123,12 @@ struct mop2
}
}
};
};
namespace
limbo
namespace
limbo
{
{
namespace
stat
{
namespace
stat
{
template
<
typename
F
>
template
<
typename
F
>
struct
ParetoBenchmark
struct
ParetoBenchmark
{
{
template
<
typename
BO
>
template
<
typename
BO
>
void
operator
()(
BO
&
opt
)
void
operator
()(
BO
&
opt
)
{
{
...
...
src/cmaes/boundary_transformation.c
View file @
00638372
...
@@ -28,8 +28,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
...
@@ -28,8 +28,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
t
->
lower_bounds
=
default_lower
;
t
->
lower_bounds
=
default_lower
;
if
(
upper_bounds
==
NULL
&&
len_of_bounds
<=
1
)
if
(
upper_bounds
==
NULL
&&
len_of_bounds
<=
1
)
t
->
upper_bounds
=
default_upper
;
t
->
upper_bounds
=
default_upper
;
if
(
len_of_bounds
==
0
)
if
(
len_of_bounds
==
0
)
{
{
t
->
lower_bounds
=
default_lower
;
t
->
lower_bounds
=
default_lower
;
t
->
upper_bounds
=
default_upper
;
t
->
upper_bounds
=
default_upper
;
t
->
len_of_bounds
=
1
;
t
->
len_of_bounds
=
1
;
...
@@ -47,8 +46,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
...
@@ -47,8 +46,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
lb
=
t
->
lower_bounds
;
lb
=
t
->
lower_bounds
;
ub
=
t
->
upper_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
])
if
(
lb
[
i
]
==
ub
[
i
])
_FatalError
(
"in _init: lower and upper bounds must be different in all "
_FatalError
(
"in _init: lower and upper bounds must be different in all "
"variables"
);
"variables"
);
...
@@ -71,8 +69,7 @@ void boundary_transformation(boundary_transformation_t* t, double const* x,
...
@@ -71,8 +69,7 @@ void boundary_transformation(boundary_transformation_t* t, double const* x,
double
lb
,
ub
,
al
,
au
;
double
lb
,
ub
,
al
,
au
;
unsigned
long
i
;
unsigned
long
i
;
boundary_transformation_shift_into_feasible_preimage
(
t
,
x
,
y
,
len
);
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
)];
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
@@ -92,8 +89,7 @@ void boundary_transformation_discrete(boundary_transformation_t* t,
...
@@ -92,8 +89,7 @@ void boundary_transformation_discrete(boundary_transformation_t* t,
unsigned
long
i
;
unsigned
long
i
;
// boundary_transformation_shift_into_feasible_preimage(t, x, y, len);
// 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
)];
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
@@ -114,8 +110,7 @@ void boundary_transformation_shift_into_feasible_preimage(
...
@@ -114,8 +110,7 @@ void boundary_transformation_shift_into_feasible_preimage(
double
lb
,
ub
,
al
,
au
,
r
,
xlow
,
xup
;
double
lb
,
ub
,
al
,
au
,
r
,
xlow
,
xup
;
unsigned
long
i
;
unsigned
long
i
;
for
(
i
=
0
;
i
<
len
;
++
i
)
for
(
i
=
0
;
i
<
len
;
++
i
)
{
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
@@ -126,12 +121,10 @@ void boundary_transformation_shift_into_feasible_preimage(
...
@@ -126,12 +121,10 @@ void boundary_transformation_shift_into_feasible_preimage(
y
[
i
]
=
x
[
i
];
y
[
i
]
=
x
[
i
];
if
(
y
[
i
]
<
xlow
)
if
(
y
[
i
]
<
xlow
)
{
/* shift up */
{
/* shift up */
y
[
i
]
+=
r
*
(
1
+
(
int
)((
xlow
-
y
[
i
])
/
r
));
y
[
i
]
+=
r
*
(
1
+
(
int
)((
xlow
-
y
[
i
])
/
r
));
}
}
if
(
y
[
i
]
>
xup
)
if
(
y
[
i
]
>
xup
)
{
/* shift down */
{
/* shift down */
y
[
i
]
-=
r
*
(
1
+
(
int
)((
y
[
i
]
-
xup
)
/
r
));
y
[
i
]
-=
r
*
(
1
+
(
int
)((
y
[
i
]
-
xup
)
/
r
));
/* printf(" \n%f\n", fmod(y[i] - ub - au, r)); */
/* printf(" \n%f\n", fmod(y[i] - ub - au, r)); */
}
}
...
@@ -140,8 +133,7 @@ void boundary_transformation_shift_into_feasible_preimage(
...
@@ -140,8 +133,7 @@ void boundary_transformation_shift_into_feasible_preimage(
if
(
y
[
i
]
>
ub
+
au
)
if
(
y
[
i
]
>
ub
+
au
)
y
[
i
]
-=
2
*
(
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: "
printf
(
"BUG in boundary_transformation_shift_into_feasible_preimage: "
"lb=%f, ub=%f, al=%f au=%f, y=%f
\n
"
,
"lb=%f, ub=%f, al=%f au=%f, y=%f
\n
"
,
lb
,
ub
,
al
,
au
,
y
[
i
]);
lb
,
ub
,
al
,
au
,
y
[
i
]);
...
@@ -156,8 +148,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
...
@@ -156,8 +148,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
double
lb
,
ub
,
al
,
au
;
double
lb
,
ub
,
al
,
au
;
unsigned
long
i
;
unsigned
long
i
;
for
(
i
=
0
;
i
<
len
;
++
i
)
for
(
i
=
0
;
i
<
len
;
++
i
)
{
{
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
lb
=
t
->
lower_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
ub
=
t
->
upper_bounds
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
al
=
t
->
al
[
_index
(
t
,
i
)];
...
@@ -168,8 +159,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
...
@@ -168,8 +159,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
else
if
(
y
[
i
]
>
ub
-
au
)
else
if
(
y
[
i
]
>
ub
-
au
)
y
[
i
]
=
(
ub
+
au
)
-
2
*
sqrt
(
au
*
(
ub
-
y
[
i
]));
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
));
double
*
z
=
calloc
(
len
,
sizeof
(
double
));
for
(
i
=
0
;
i
<
len
;
++
i
)
for
(
i
=
0
;
i
<
len
;
++
i
)
z
[
i
]
=
y
[
i
];
z
[
i
]
=
y
[
i
];
...
...
src/cmaes/boundary_transformation.h
View file @
00638372
...
@@ -26,7 +26,7 @@ extern "C" {
...
@@ -26,7 +26,7 @@ extern "C" {
*/
*/
typedef
struct
typedef
struct
{
{
double
const
*
lower_bounds
;
/* array of size len_of_bounds */
double
const
*
lower_bounds
;
/* array of size len_of_bounds */
double
const
*
upper_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 */
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");
...
@@ -312,8 +312,7 @@ use cmaes_exit first\n");
t
->
arFuncValueHist
[
0
]
=
(
double
)(
10
+
(
int
)
ceil
(
3
.
*
10
.
*
N
/
t
->
sp
.
lambda
));
t
->
arFuncValueHist
[
0
]
=
(
double
)(
10
+
(
int
)
ceil
(
3
.
*
10
.
*
N
/
t
->
sp
.
lambda
));
t
->
arFuncValueHist
++
;
t
->
arFuncValueHist
++
;
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
i
=
0
;
i
<
N
;
++
i
)
{
{
t
->
C
[
i
]
=
new_double
(
i
+
1
);
t
->
C
[
i
]
=
new_double
(
i
+
1
);
t
->
B
[
i
]
=
new_double
(
N
);
t
->
B
[
i
]
=
new_double
(
N
);
}
}
...
@@ -321,8 +320,7 @@ use cmaes_exit first\n");
...
@@ -321,8 +320,7 @@ use cmaes_exit first\n");
for
(
i
=
0
;
i
<
t
->
sp
.
lambda
;
++
i
)
for
(
i
=
0
;
i
<
t
->
sp
.
lambda
;
++
i
)
t
->
index
[
i
]
=
i
;
/* should not be necessary */
t
->
index
[
i
]
=
i
;
/* should not be necessary */
t
->
rgrgx
=
(
double
**
)
new_void
(
t
->
sp
.
lambda
,
sizeof
(
double
*
));
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
]
=
new_double
(
N
+
2
);
t
->
rgrgx
[
i
][
0
]
=
N
;
t
->
rgrgx
[
i
][
0
]
=
N
;
t
->
rgrgx
[
i
]
++
;
t
->
rgrgx
[
i
]
++
;
...
@@ -334,8 +332,7 @@ use cmaes_exit first\n");
...
@@ -334,8 +332,7 @@ use cmaes_exit first\n");
for
(
j
=
0
;
j
<
i
;
++
j
)
for
(
j
=
0
;
j
<
i
;
++
j
)
t
->
C
[
i
][
j
]
=
t
->
B
[
i
][
j
]
=
t
->
B
[
j
][
i
]
=
0
.;
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
->
B
[
i
][
i
]
=
1
.;
t
->
C
[
i
][
i
]
=
t
->
rgD
[
i
]
=
t
->
sp
.
rgInitialStds
[
i
]
*
sqrt
(
N
/
trace
);
t
->
C
[
i
][
i
]
=
t
->
rgD
[
i
]
=
t
->
sp
.
rgInitialStds
[
i
]
*
sqrt
(
N
/
trace
);
t
->
C
[
i
][
i
]
*=
t
->
C
[
i
][
i
];
t
->
C
[
i
][
i
]
*=
t
->
C
[
i
][
i
];
...
@@ -379,8 +376,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
...
@@ -379,8 +376,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
int
i
,
j
,
res
,
n
;
int
i
,
j
,
res
,
n
;
double
d
;
double
d
;
FILE
*
fp
=
fopen
(
filename
,
"r"
);
FILE
*
fp
=
fopen
(
filename
,
"r"
);
if
(
fp
==
NULL
)
if
(
fp
==
NULL
)
{
{
ERRORMESSAGE
(
"cmaes_resume_distribution(): could not open '"
,
filename
,
"'"
,
ERRORMESSAGE
(
"cmaes_resume_distribution(): could not open '"
,
filename
,
"'"
,
0
);
0
);
return
;
return
;
...
@@ -388,8 +384,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
...
@@ -388,8 +384,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
/* count number of "resume" entries */
/* count number of "resume" entries */
i
=
0
;
i
=
0
;
res
=
0
;
res
=
0
;
while
(
1
)
while
(
1
)
{
{
if
((
res
=
fscanf
(
fp
,
" resume %lg"
,
&
d
))
==
EOF
)
if
((
res
=
fscanf
(
fp
,
" resume %lg"
,
&
d
))
==
EOF
)
break
;
break
;
else
if
(
res
==
0
)
else
if
(
res
==
0
)
...
@@ -403,8 +398,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
...
@@ -403,8 +398,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
i
=
0
;
i
=
0
;
res
=
0
;
res
=
0
;
rewind
(
fp
);
rewind
(
fp
);
while
(
i
<
n
)
while
(
i
<
n
)
{
{
if
((
res
=
fscanf
(
fp
,
" resume %lg"
,
&
d
))
==
EOF
)
if
((
res
=
fscanf
(
fp
,
" resume %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): Unexpected error, bug"
,
0
,
0
,
0
);
FATAL
(
"cmaes_resume_distribution(): Unexpected error, bug"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
else
if
(
res
==
0
)
...
@@ -417,8 +411,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
...
@@ -417,8 +411,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
0
);
0
);
/* find next "xmean" entry */
/* find next "xmean" entry */
while
(
1
)
while
(
1
)
{
{
if
((
res
=
fscanf
(
fp
,
" xmean %lg"
,
&
d
))
==
EOF
)
if
((
res
=
fscanf
(
fp
,
" xmean %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'xmean' not found"
,
0
,
0
,
0
);
FATAL
(
"cmaes_resume_distribution(): 'xmean' not found"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
else
if
(
res
==
0
)
...
@@ -436,8 +429,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
...
@@ -436,8 +429,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
FATAL
(
"cmaes_resume_distribution(): xmean: dimensions differ"
,
0
,
0
,
0
);
FATAL
(
"cmaes_resume_distribution(): xmean: dimensions differ"
,
0
,
0
,
0
);
/* find next "path for sigma" entry */
/* find next "path for sigma" entry */
while
(
1
)
while
(
1
)
{
{
if
((
res
=
fscanf
(
fp
,
" path for sigma %lg"
,
&
d
))
==
EOF
)
if
((
res
=
fscanf
(
fp
,
" path for sigma %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'path for sigma' not found"
,
0
,
0
,
0
);
FATAL
(
"cmaes_resume_distribution(): 'path for sigma' not found"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
else
if
(
res
==
0
)
...
@@ -455,8 +447,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
...
@@ -455,8 +447,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
FATAL
(
"cmaes_resume_distribution(): ps: dimensions differ"
,
0
,
0
,
0
);
FATAL
(
"cmaes_resume_distribution(): ps: dimensions differ"
,
0
,
0
,
0
);
/* find next "path for C" entry */
/* find next "path for C" entry */
while
(
1
)
while
(
1
)
{
{
if
((
res
=
fscanf
(
fp
,
" path for C %lg"
,
&
d
))
==
EOF
)
if
((
res
=
fscanf
(
fp
,
" path for C %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'path for C' not found"
,
0
,
0
,
0
);
FATAL
(
"cmaes_resume_distribution(): 'path for C' not found"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
else
if
(
res
==
0
)
...
@@ -473,8 +464,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
...
@@ -473,8 +464,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
FATAL
(
"cmaes_resume_distribution(): pc: dimensions differ"
,
0
,
0
,
0
);
FATAL
(
"cmaes_resume_distribution(): pc: dimensions differ"
,
0
,
0
,
0
);
/* find next "sigma" entry */
/* find next "sigma" entry */
while
(
1
)
while
(
1
)
{
{
if
((
res
=
fscanf
(
fp
,
" sigma %lg"
,
&
d
))
==
EOF
)
if
((
res
=
fscanf
(
fp
,
" sigma %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'sigma' not found"
,
0
,
0
,
0
);
FATAL
(
"cmaes_resume_distribution(): 'sigma' not found"
,
0
,
0
,
0
);
else
if
(
res
==
0
)
else
if
(
res
==
0
)
...
@@ -485,8 +475,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
...
@@ -485,8 +475,7 @@ void cmaes_resume_distribution(cmaes_t* t, char* filename)
t
->
sigma
=
d
;
t
->
sigma
=
d
;
/* find next entry "covariance matrix" */
/* find next entry "covariance matrix" */
while
(
1
)
while
(
1
)
{
{
if
((
res
=
fscanf
(
fp
,
" covariance matrix %lg"
,
&
d
))
==
EOF
)
if
((
res
=
fscanf
(
fp
,
" covariance matrix %lg"
,
&
d
))
==
EOF
)
FATAL
(
"cmaes_resume_distribution(): 'covariance matrix' not found"
,
0
,
0
,
FATAL
(
"cmaes_resume_distribution(): 'covariance matrix' not found"
,
0
,
0
,
0
);
0
);
...
@@ -528,8 +517,7 @@ void cmaes_exit(cmaes_t* t)
...
@@ -528,8 +517,7 @@ void cmaes_exit(cmaes_t* t)
free
(
--
t
->
rgxbestever
);
free
(
--
t
->
rgxbestever
);
free
(
--
t
->
rgout
);
free
(
--
t
->
rgout
);
free
(
t
->
rgD
);
free
(
t
->
rgD
);
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
i
=
0
;
i
<
N
;
++
i
)
{
{
free
(
t
->
C
[
i
]);
free
(
t
->
C
[
i
]);
free
(
t
->
B
[
i
]);
free
(
t
->
B
[
i
]);
}
}
...
@@ -581,12 +569,10 @@ double* const* cmaes_SamplePopulation(cmaes_t* t)
...
@@ -581,12 +569,10 @@ double* const* cmaes_SamplePopulation(cmaes_t* t)
/* cmaes_SetMean(t, xmean); * xmean could be changed at this point */
/* cmaes_SetMean(t, xmean); * xmean could be changed at this point */
/* calculate eigensystem */
/* calculate eigensystem */
if
(
!
t
->
flgEigensysIsUptodate
)
if
(
!
t
->
flgEigensysIsUptodate
)
{
{
if
(
!
flgdiag
)
if
(
!
flgdiag
)
cmaes_UpdateEigensystem
(
t
,
0
);
cmaes_UpdateEigensystem
(
t
,
0
);
else
else
{
{
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgD
[
i
]
=
sqrt
(
t
->
C
[
i
][
i
]);
t
->
rgD
[
i
]
=
sqrt
(
t
->
C
[
i
][
i
]);
t
->
minEW
=
douSquare
(
rgdouMin
(
t
->
rgD
,
N
));
t
->
minEW
=
douSquare
(
rgdouMin
(
t
->
rgD
,
N
));
...
@@ -599,8 +585,7 @@ double* const* cmaes_SamplePopulation(cmaes_t* t)
...
@@ -599,8 +585,7 @@ double* const* cmaes_SamplePopulation(cmaes_t* t)
/* treat minimal standard deviations and numeric problems */
/* treat minimal standard deviations and numeric problems */
TestMinStdDevs
(
t
);
TestMinStdDevs
(
t
);
for
(
iNk
=
0
;
iNk
<
t
->
sp
.
lambda
;
++
iNk
)
for
(
iNk
=
0
;
iNk
<
t
->
sp
.
lambda
;
++
iNk
)
{
{
/* generate scaled random vector (D * z) */
/* generate scaled random vector (D * z) */
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
i
=
0
;
i
<
N
;
++
i
)
if
(
flgdiag
)
if
(
flgdiag
)
...
@@ -609,8 +594,7 @@ double* const* cmaes_SamplePopulation(cmaes_t* t)
...
@@ -609,8 +594,7 @@ double* const* cmaes_SamplePopulation(cmaes_t* t)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
if
(
!
flgdiag
)
if
(
!
flgdiag
)
/* add mutation (sigma * B * (D*z)) */
/* 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
)
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
t
->
rgrgx
[
iNk
][
i
]
=
xmean
[
i
]
+
t
->
sigma
*
sum
;
t
->
rgrgx
[
iNk
][
i
]
=
xmean
[
i
]
+
t
->
sigma
*
sum
;
...
@@ -636,8 +620,7 @@ double const* cmaes_ReSampleSingle_old(cmaes_t* t, double* rgx)
...
@@ -636,8 +620,7 @@ double const* cmaes_ReSampleSingle_old(cmaes_t* t, double* rgx)
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
/* add mutation (sigma * B * (D*z)) */
/* 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
)
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
rgx
[
i
]
=
t
->
rgxmean
[
i
]
+
t
->
sigma
*
sum
;
rgx
[
i
]
=
t
->
rgxmean
[
i
]
+
t
->
sigma
*
sum
;
...
@@ -654,8 +637,7 @@ double* const* cmaes_ReSampleSingle(cmaes_t* t, int iindex)
...
@@ -654,8 +637,7 @@ double* const* cmaes_ReSampleSingle(cmaes_t* t, int iindex)
double
sum
;
double
sum
;
static
char
s
[
99
];
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
);
sprintf
(
s
,
"index==%d must be between 0 and %d"
,
iindex
,
t
->
sp
.
lambda
);
FATAL
(
"cmaes_ReSampleSingle(): Population member "
,
s
,
0
,
0
);
FATAL
(
"cmaes_ReSampleSingle(): Population member "
,
s
,
0
,
0
);
}
}
...
@@ -664,8 +646,7 @@ double* const* cmaes_ReSampleSingle(cmaes_t* t, int iindex)
...
@@ -664,8 +646,7 @@ double* const* cmaes_ReSampleSingle(cmaes_t* t, int iindex)
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
/* add mutation (sigma * B * (D*z)) */
/* 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
)
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
rgx
[
i
]
=
t
->
rgxmean
[
i
]
+
t
->
sigma
*
sum
;
rgx
[
i
]
=
t
->
rgxmean
[
i
]
+
t
->
sigma
*
sum
;
...
@@ -686,8 +667,7 @@ double* cmaes_SampleSingleInto(cmaes_t* t, double* rgx)
...
@@ -686,8 +667,7 @@ double* cmaes_SampleSingleInto(cmaes_t* t, double* rgx)
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
/* add mutation (sigma * B * (D*z)) */
/* 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
)
for
(
j
=
0
,
sum
=
0
.;
j
<
N
;
++
j
)
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
sum
+=
t
->
B
[
i
][
j
]
*
t
->
rgdTmp
[
j
];
rgx
[
i
]
=
t
->
rgxmean
[
i
]
+
t
->
sigma
*
sum
;
rgx
[
i
]
=
t
->
rgxmean
[
i
]
+
t
->
sigma
*
sum
;
...
@@ -711,8 +691,7 @@ double* cmaes_PerturbSolutionInto(cmaes_t* t, double* rgx, double const* xmean,
...
@@ -711,8 +691,7 @@ double* cmaes_PerturbSolutionInto(cmaes_t* t, double* rgx, double const* xmean,
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
i
=
0
;
i
<
N
;
++
i
)
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
t
->
rgdTmp
[
i
]
=
t
->
rgD
[
i
]
*
random_Gauss
(
&
t
->
rand
);
/* add mutation (sigma * B * (D*z)) */
/* add mutation (sigma * B * (D*z)) */
for
(
i
=
0
;
i
<
N
;
++
i
)
for
(
i
=
0
;
i
<
N
;
++
i
)
{
<