random_sampling.hpp 1.05 KB
Newer Older
1
2
#ifndef LIMBO_INIT_RANDOM_SAMPLING_HPP
#define LIMBO_INIT_RANDOM_SAMPLING_HPP
3
4

#include <Eigen/Core>
5

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

namespace limbo {
10
11
12
13
14
    namespace defaults {
        struct init_randomsampling {
            BO_PARAM(int, samples, 10);
        };
    }
15
    namespace init {
16
17
        template <typename Params>
        struct RandomSampling {
18
19
            template <typename StateFunction, typename AggregatorFunction, typename Opt>
            void operator()(const StateFunction& seval, const AggregatorFunction&, Opt& opt) const
20
            {
21
                auto rgen = tools::make_rgen(0.0, 1.0);
22
                for (int i = 0; i < Params::init_randomsampling::samples(); i++) {
23
                    Eigen::VectorXd new_sample(StateFunction::dim_in);
24
                    for (size_t j = 0; j < StateFunction::dim_in; j++)
25
                        new_sample[j] = tools::rand_double(rgen);
26
                    opt.add_new_sample(new_sample, seval(new_sample));
27
28
29
30
31
                }
            }
        };
    }
}
32

33
#endif