10 #include <boost/algorithm/string/erase.hpp>
11 #include <boost/tokenizer.hpp>
37 = decltype(std::declval<T>()
38 .power(std::declval<typename T::value_t>(), 0));
46 template <
typename WeightSet>
50 using typename super_t::value_t;
53 using super_t::super_t;
59 template <
typename... Ts>
64 using swallow =
int[];
75 template <
typename WS = super_t>
77 -> std::enable_if_t<detail::has_power_mem_fn<WS>{},
value_t>
79 return super_t::power(e, n);
84 template <
typename WS = super_t>
86 -> std::enable_if_t<!detail::has_power_mem_fn<WS>{},
value_t>
89 if (!super_t::is_one(e))
100 return power_<WeightSet>(e, n);
111 typename RandomGenerator = std::default_random_engine>
142 using tokenizer = boost::tokenizer<boost::char_separator<char>>;
143 auto sep = boost::char_separator<char>{
","};
144 auto tok = tokenizer(weights, sep);
145 for (
auto it = tok.begin(); it != tok.end(); ++it)
147 auto tok_arg = std::string{*it};
148 auto eq = tok_arg.find_first_of(
'=');
149 auto weight = tok_arg.substr(0, eq);
150 boost::algorithm::erase_all(
weight,
" ");
157 float value = (eq != std::string::npos)
158 ? value = detail::lexical_cast<float>(tok_arg.substr(eq + 1))
204 template <
typename WeightSet,
typename RandomGenerator>
210 template <
typename T>
constant< type_t::one, Context > one
Generic declaration of the class which is specialized in each weightset.
discrete_chooser< RandomGenerator > chooser_it_
virtual void parse_param_(const std::string &weights)
value_impl< detail::weight_tag > weight
Functor to compare Values of ValueSets.
decltype(std::declval< T >().power(std::declval< typename T::value_t >(), 0)) power_mem_fn_t
The signature of power.
random_weight_base(RandomGenerator &gen, const WeightSet &ws)
value_t mul(const Ts &...ts) const
A variadic multiplication.
Abstract class for random weight generation.
Provide a variadic mul on top of a binary mul(), and one().
auto power_(value_t e, unsigned n) const -> std::enable_if_t<!detail::has_power_mem_fn< WS >
Case where the weightset T does not feature a power(value_t, unsigned) member function.
weight_t print_random_weight_() const
A random weight.
value_t power(value_t e, unsigned n) const
Repeated multiplication.
Request the map implementation.
std::vector< float > weight_weight_t
void parse_param(const std::string ¶m)
auto transform(const Container &c, Fun &&fun)
Map a unary function on a container of values, and return the vector the results. ...
RandomGenerator randomGenerator_t
static bool choose_map(const std::vector< float > &map, RandomGenerator &gen=RandomGenerator())
Choose whether to pick an element from a map or not.
weight_map_t weight_
Elements given by the user and their associated probabilities (weight_weight_).
variadic< type_t::mul, Context > mul
auto power_(value_t e, unsigned n) const -> std::enable_if_t< detail::has_power_mem_fn< WS >
Case where the weightset T features a power(value_t, unsigned) member function.
typename zmin::value_t weight_t
virtual weight_t pick_value_() const =0
std::map< typename zmin::value_t, float, vcsn::less< zmin >> weight_map_t
auto conv(const ValueSet &vs, const std::string &str, Args &&...args) -> decltype(vs.conv(std::declval< std::istream & >(), std::forward< Args >(args)...))
Parse str via vs.conv.
weight_t min_
The min and the max given by the user.
weight_weight_t weight_weight_
weight_t generate_random_weight() const
Random selector on container, using discrete distribution.