57 using param_base_class::param_base_class;
69 std::vector<double> _weights;
70 const std::vector<coord_type> &_space;
74 template <
typename F>
auto compute_weights(std::vector<coord_type>
const &space, F f)
const
76 std::vector<double> w(space.size(), 0);
77 std::transform(space.cbegin(), space.cend(), w.begin(), f);
82 template <
typename F1>
84 : _weights(compute_weights(space, f)), _space(space), _population_size(pop_size), _param(n)
89 param_type param()
const
94 void param(
unsigned int n)
96 _param = param_type(n);
112 template <
typename Generator>
auto operator()(Generator &gen)
const
114 std::discrete_distribution<size_t> dist(_weights.begin(), _weights.end());
115 std::map<coord_type, unsigned int> sample;
117 unsigned int nb_try = 0;
118 while (i < _param.sampling_size() && nb_try < 10 * (_param.sampling_size()))
121 if (sample[_space[
id]] < _population_size(_space[
id]))
123 sample[_space[id]] += 1;
130 throw std::logic_error(
"Sampling scheme unable to populate a sample.");
144 return constrained_sampling<X, N>(space, f, pop_size, n);
155 return constrained_sampling<X, N>(space, uniform_weighting, pop_size, n);