random_sampling_grid.hpp 1.18 KB
Newer Older
1
2
#ifndef LIMBO_INIT_RANDOM_SAMPLING_GRID_HPP
#define LIMBO_INIT_RANDOM_SAMPLING_GRID_HPP
3
4
5

#include <Eigen/Core>

6
#include <limbo/tools/macros.hpp>
7
#include <limbo/tools/random_generator.hpp>
8

9
namespace limbo {
10
11
12
13
14
15
    namespace defaults {
        struct init_randomsamplinggrid {
            BO_PARAM(int, samples, 10);
            BO_PARAM(int, bins, 5);
        };
    }
16
    namespace init {
17
18
        template <typename Params>
        struct RandomSamplingGrid {
19
20
            template <typename StateFunction, typename AggregatorFunction, typename Opt>
            void operator()(const StateFunction& seval, const AggregatorFunction&, Opt& opt) const
21
            {
22
                tools::rgen_int_t rgen(0, Params::init_randomsamplinggrid::bins());
23
                for (int i = 0; i < Params::init_randomsamplinggrid::samples(); i++) {
24
25
                    Eigen::VectorXd new_sample(StateFunction::dim_in);
                    for (size_t i = 0; i < StateFunction::dim_in; i++)
26
                        new_sample[i] = rgen.rand() / double(Params::init_randomsamplinggrid::bins());
27
                    opt.add_new_sample(new_sample, seval(new_sample));
28
29
30
31
32
                }
            }
        };
    }
}
33

34
#endif