Commit ef3411f5 by Konstantinos Chatzilygeroudis

### First try for enabling acquisition optimization with gradients

parent ca836aeb
 ... ... @@ -105,13 +105,13 @@ public: size_t dim_out() const { return _model.dim_out(); } template 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: ... ...
 ... ... @@ -50,6 +50,7 @@ #include #include #include namespace limbo { namespace defaults { ... ... @@ -80,7 +81,7 @@ namespace limbo { size_t dim_out() const { return _model.dim_out(); } template 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: ... ...
 ... ... @@ -48,6 +48,7 @@ #include #include #include namespace limbo { namespace defaults { ... ... @@ -91,12 +92,12 @@ namespace limbo { size_t dim_out() const { return _model.dim_out(); } template 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: ... ...
 ... ... @@ -48,6 +48,7 @@ #include #include #include namespace limbo { namespace defaults { ... ... @@ -78,12 +79,12 @@ namespace limbo { size_t dim_out() const { return _model.dim_out(); } template 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: ... ...
 ... ... @@ -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); ... ...
 ... ... @@ -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) << " " ... ...
 ... ... @@ -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; ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!