Commit d7e99d0e authored by Jean-Baptiste Mouret's avatar Jean-Baptiste Mouret
Browse files

use tools::random_vector() instead of Eigen::VectorXd::Random()

parent 50f8f5c2
......@@ -71,7 +71,7 @@ namespace limbo {
while (this->_samples.size() == 0 || !this->_stop(*this, afun)) {
acquisition_function_t acqui(_model, this->_current_iteration);
Eigen::VectorXd starting_point = (Eigen::VectorXd::Random(StateFunction::dim_in).array() + 1) / 2;
auto starting_point = tools::random_vector(StateFunction::dim_in);
auto acqui_optimization = AcquiOptimization<acquisition_function_t, AggregatorFunction>(acqui, afun, starting_point);
Eigen::VectorXd new_sample = acqui_optimizer(acqui_optimization, true);
bool blacklisted = false;
......
......@@ -18,11 +18,8 @@ namespace limbo {
template <typename StateFunction, typename AggregatorFunction, typename Opt>
void operator()(const StateFunction& seval, const AggregatorFunction&, Opt& opt) const
{
tools::rgen_double_t rgen(0.0, 1.0);
for (int i = 0; i < Params::init_randomsampling::samples(); i++) {
Eigen::VectorXd new_sample(StateFunction::dim_in);
for (size_t j = 0; j < StateFunction::dim_in; j++)
new_sample[j] = rgen.rand();
auto new_sample = tools::random_vector(StateFunction::dim_in);
opt.add_new_sample(new_sample, seval(new_sample));
}
}
......
......@@ -104,6 +104,7 @@ namespace limbo {
Eigen::VectorXd init() const
{
// Bug ?? used??
return (Eigen::VectorXd::Random(param_size()).array() - 1);
}
......
......@@ -112,6 +112,7 @@ namespace limbo {
Eigen::VectorXd init() const
{
// Bug ?? used??
return (Eigen::VectorXd::Random(param_size()).array() - 1);
}
......
......@@ -95,6 +95,7 @@ namespace limbo {
Eigen::VectorXd init() const
{
// Bug ?? used??
return (Eigen::VectorXd::Random(param_size()).array() - 1);
}
......
......@@ -2,6 +2,7 @@
#define LIMBO_OPT_RANDOM_POINT_HPP
#include <Eigen/Core>
#include <limbo/tools/random_generator.hpp>
namespace limbo {
namespace opt {
......@@ -12,10 +13,10 @@ namespace limbo {
{
// Random point does not support unbounded search
assert(bounded);
return (Eigen::VectorXd::Random(f.param_size()).array() + 1) / 2;
return tools::random_vector(f.param_size());
}
};
}
}
#endif
\ No newline at end of file
#endif
......@@ -8,6 +8,7 @@
#include <Eigen/Core>
#include <limbo/tools/macros.hpp>
#include <limbo/tools/random_generator.hpp>
namespace limbo {
namespace defaults {
......@@ -29,7 +30,7 @@ namespace limbo {
return false;
auto optimizer = _get_optimizer(typename BO::acqui_optimizer_t(), Optimizer());
Eigen::VectorXd starting_point = (Eigen::VectorXd::Random(bo.model().dim_in()).array() + 1) / 2;
auto starting_point = tools::random_vector(bo.model());
double val = afun(bo.model().mu(optimizer(_make_model_mean_optimization(bo.model(), afun, starting_point), true)));
if (bo.observations().size() == 0 || afun(bo.best_observation(afun)) <= Params::stop_maxpredictedvalue::ratio() * val)
......
......@@ -45,6 +45,13 @@
namespace limbo {
namespace tools {
// random vector in [0, 1]
Eigen::VectorXd random_vector(int size)
{
// Eigen returns in [-1:1] (??)
return ((Eigen::VectorXd::Random(size)).array() + 1.0) / 2.0;
}
// usage :
// rgen_double_t(0.0, 1.0);
// double r = rgen.rand();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment