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
ef3411f5
Commit
ef3411f5
authored
Sep 20, 2016
by
Konstantinos Chatzilygeroudis
Browse files
First try for enabling acquisition optimization with gradients
parent
ca836aeb
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/examples/obs_multi_auto_mean.cpp
View file @
ef3411f5
...
...
@@ -105,13 +105,13 @@ public:
size_t
dim_out
()
const
{
return
_model
.
dim_out
();
}
template
<
typename
AggregatorFunction
>
double
operator
()(
const
Eigen
::
VectorXd
&
v
,
const
AggregatorFunction
&
afun
)
const
limbo
::
opt
::
eval_t
operator
()(
const
Eigen
::
VectorXd
&
v
,
const
AggregatorFunction
&
afun
)
const
{
// double mu, sigma;
// std::tie(mu, sigma) = _model.query(v);
// return (mu + Params::ucb::alpha() * sqrt(sigma));
return
(
sqrt
(
_model
.
sigma
(
v
)));
return
limbo
::
opt
::
no_grad
(
std
::
sqrt
(
_model
.
sigma
(
v
)));
}
protected:
...
...
src/limbo/acqui/ei.hpp
View file @
ef3411f5
...
...
@@ -50,6 +50,7 @@
#include
<Eigen/Core>
#include
<limbo/tools/macros.hpp>
#include
<limbo/opt/optimizer.hpp>
namespace
limbo
{
namespace
defaults
{
...
...
@@ -80,7 +81,7 @@ namespace limbo {
size_t
dim_out
()
const
{
return
_model
.
dim_out
();
}
template
<
typename
AggregatorFunction
>
double
operator
()(
const
Eigen
::
VectorXd
&
v
,
const
AggregatorFunction
&
afun
)
const
opt
::
eval_t
operator
()(
const
Eigen
::
VectorXd
&
v
,
const
AggregatorFunction
&
afun
)
const
{
Eigen
::
VectorXd
mu
;
double
sigma_sq
;
...
...
@@ -89,7 +90,7 @@ namespace limbo {
// If \sigma(x) = 0 or we do not have any observation yet we return 0
if
(
sigma
<
1e-10
||
_model
.
samples
().
size
()
<
1
)
return
0.0
;
return
opt
::
no_grad
(
0.0
)
;
// Compute EI(x)
// First find the best so far (predicted) observation
...
...
@@ -104,7 +105,7 @@ namespace limbo {
double
phi
=
std
::
exp
(
-
0.5
*
std
::
pow
(
Z
,
2.0
))
/
std
::
sqrt
(
2.0
*
M_PI
);
double
Phi
=
0.5
*
std
::
erfc
(
-
Z
/
std
::
sqrt
(
2
));
//0.5 * (1.0 + std::erf(Z / std::sqrt(2)));
return
X
*
Phi
+
sigma
*
phi
;
return
opt
::
no_grad
(
X
*
Phi
+
sigma
*
phi
)
;
}
protected:
...
...
src/limbo/acqui/gp_ucb.hpp
View file @
ef3411f5
...
...
@@ -48,6 +48,7 @@
#include
<Eigen/Core>
#include
<limbo/tools/macros.hpp>
#include
<limbo/opt/optimizer.hpp>
namespace
limbo
{
namespace
defaults
{
...
...
@@ -91,12 +92,12 @@ namespace limbo {
size_t
dim_out
()
const
{
return
_model
.
dim_out
();
}
template
<
typename
AggregatorFunction
>
double
operator
()(
const
Eigen
::
VectorXd
&
v
,
const
AggregatorFunction
&
afun
)
const
opt
::
eval_t
operator
()(
const
Eigen
::
VectorXd
&
v
,
const
AggregatorFunction
&
afun
)
const
{
Eigen
::
VectorXd
mu
;
double
sigma
;
std
::
tie
(
mu
,
sigma
)
=
_model
.
query
(
v
);
return
(
afun
(
mu
)
+
_beta
*
std
::
sqrt
(
sigma
));
return
opt
::
no_grad
(
afun
(
mu
)
+
_beta
*
std
::
sqrt
(
sigma
));
}
protected:
...
...
src/limbo/acqui/ucb.hpp
View file @
ef3411f5
...
...
@@ -48,6 +48,7 @@
#include
<Eigen/Core>
#include
<limbo/tools/macros.hpp>
#include
<limbo/opt/optimizer.hpp>
namespace
limbo
{
namespace
defaults
{
...
...
@@ -78,12 +79,12 @@ namespace limbo {
size_t
dim_out
()
const
{
return
_model
.
dim_out
();
}
template
<
typename
AggregatorFunction
>
double
operator
()(
const
Eigen
::
VectorXd
&
v
,
const
AggregatorFunction
&
afun
)
const
opt
::
eval_t
operator
()(
const
Eigen
::
VectorXd
&
v
,
const
AggregatorFunction
&
afun
)
const
{
Eigen
::
VectorXd
mu
;
double
sigma
;
std
::
tie
(
mu
,
sigma
)
=
_model
.
query
(
v
);
return
(
afun
(
mu
)
+
Params
::
acqui_ucb
::
alpha
()
*
sqrt
(
sigma
));
return
opt
::
no_grad
(
afun
(
mu
)
+
Params
::
acqui_ucb
::
alpha
()
*
sqrt
(
sigma
));
}
protected:
...
...
src/limbo/bayes_opt/boptimizer.hpp
View file @
ef3411f5
...
...
@@ -151,9 +151,8 @@ namespace limbo {
while
(
!
this
->
_stop
(
*
this
,
afun
))
{
acquisition_function_t
acqui
(
_model
,
this
->
_current_iteration
);
// we do not have gradient in our current acquisition function
auto
acqui_optimization
=
[
&
](
const
Eigen
::
VectorXd
&
x
,
bool
g
)
{
return
opt
::
no_grad
(
acqui
(
x
,
afun
)
)
;
};
[
&
](
const
Eigen
::
VectorXd
&
x
,
bool
g
)
{
return
acqui
(
x
,
afun
);
};
Eigen
::
VectorXd
starting_point
=
tools
::
random_vector
(
StateFunction
::
dim_in
);
Eigen
::
VectorXd
new_sample
=
acqui_optimizer
(
acqui_optimization
,
starting_point
,
true
);
bool
blacklisted
=
!
this
->
eval_and_add
(
sfun
,
new_sample
);
...
...
src/limbo/stat/gp.hpp
View file @
ef3411f5
...
...
@@ -80,7 +80,7 @@ namespace limbo {
point
[
dim_in
]
=
x
;
if
(
dim_in
==
current
.
size
()
-
1
)
{
auto
q
=
bo
.
model
().
query
(
point
);
double
acqui
=
typename
BO
::
acquisition_function_t
(
bo
.
model
(),
bo
.
current_iteration
())(
point
,
afun
);
double
acqui
=
std
::
get
<
0
>
(
typename
BO
::
acquisition_function_t
(
bo
.
model
(),
bo
.
current_iteration
())(
point
,
afun
)
)
;
ofs
<<
point
.
transpose
()
<<
" "
<<
std
::
get
<
0
>
(
q
).
transpose
()
<<
" "
<<
std
::
get
<
1
>
(
q
)
<<
" "
...
...
src/limbo/stat/gp_acquisitions.hpp
View file @
ef3411f5
...
...
@@ -71,11 +71,11 @@ namespace limbo {
if
(
!
blacklisted
&&
!
bo
.
samples
().
empty
())
{
std
::
tie
(
mu
,
sigma
)
=
bo
.
model
().
query
(
bo
.
samples
().
back
());
acqui
=
typename
BO
::
acquisition_function_t
(
bo
.
model
(),
bo
.
current_iteration
())(
bo
.
samples
().
back
(),
afun
);
acqui
=
std
::
get
<
0
>
(
typename
BO
::
acquisition_function_t
(
bo
.
model
(),
bo
.
current_iteration
())(
bo
.
samples
().
back
(),
afun
)
)
;
}
else
if
(
!
bo
.
bl_samples
().
empty
())
{
std
::
tie
(
mu
,
sigma
)
=
bo
.
model
().
query
(
bo
.
bl_samples
().
back
());
acqui
=
typename
BO
::
acquisition_function_t
(
bo
.
model
(),
bo
.
current_iteration
())(
bo
.
bl_samples
().
back
(),
afun
);
acqui
=
std
::
get
<
0
>
(
typename
BO
::
acquisition_function_t
(
bo
.
model
(),
bo
.
current_iteration
())(
bo
.
bl_samples
().
back
(),
afun
)
)
;
}
else
return
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment