Lumiera
0.pre.03
»edit your freedom«
|
#include "lib/random-draw.hpp"
A component and builder to draw limited parameter values based on some source of randomness (or hash input).
Effectively this is a function which "draws" on invocation. Probabilities and ranges can be configured by builder API.
POL | configuration policy baseclass |
Definition at line 182 of file random-draw.hpp.
Public Member Functions | |
RandomDraw () | |
Drawing is disabled by default, always yielding "zero". | |
template<class FUN , typename = disable_if_self<RandomDraw, FUN>> | |
RandomDraw (FUN &&fun) | |
Build a RandomDraw by attaching a value-processing function, which is adapted to accept the nominal input type. More... | |
RandomDraw && | fixedVal (Tar v) |
template<class FUN > | |
RandomDraw && | mapping (FUN &&fun) |
RandomDraw && | maxVal (Tar m) |
RandomDraw && | minVal (Tar m) |
RandomDraw && | probability (double p) |
RandomDraw && | shuffle (size_t seed=55) |
Public Member Functions inherited from LazyInit< POL > | |
LazyInit (std::function< SIG > &targetFunctor, INI &&initialiser, ARGS &&...parentCtorArgs) | |
prepare an initialiser to be activated on first use | |
LazyInit (LazyInit const &ref) | |
LazyInit (LazyInit &&rref) | |
void | installEmptyInitialiser () |
void | installInitialiser (std::function< SIG > &targetFunctor, INI &&initialiser) |
bool | isInit () const |
LazyInit & | operator= (LazyInit const &ref) |
LazyInit & | operator= (LazyInit &&rref) |
Private Types | |
using | Disabled = typename Lazy::MarkDisabled |
using | Fun = function< Sig > |
using | Lazy = LazyInit< POL > |
using | Sig = typename _Fun< POL >::Sig |
using | Tar = typename _Fun< POL >::Ret |
Private Member Functions | |
template<class FUN > | |
auto | adaptIn (FUN &&fun) |
template<class FUN > | |
auto | adaptOut (FUN &&fun) |
double | asRand (size_t hash) |
Tar | drawLimited (size_t hash) |
template<class FUN > | |
void | installAdapted (FUN &&fun) |
Tar | limited (double val) |
Private Attributes | |
Tar | maxResult_ {Tar::maxVal()} |
maximum result val actually to produce < max | |
Tar | minResult_ {Tar::minVal()} |
minimum result val actually to produce > min | |
double | probability_ {0} |
probability that value is in [min .. max] \ neutral | |
size_t | shuffle_ {0} |
statefull additional randomisation to inject into hash | |
Static Private Attributes | |
static double constexpr | CAP_EPSILON = 1/(2.0 * QUANTISER) |
static size_t constexpr | QUANTISER = 1 << 4 + util::ilog2 (Tar::maxVal()-Tar::minVal()) |
Additional Inherited Members | |
Protected Member Functions inherited from LazyInit< POL > | |
LazyInit (MarkDisabled, ARGS &&...parentCtorArgs) | |
|
inline |
Build a RandomDraw by attaching a value-processing function, which is adapted to accept the nominal input type.
The effect of the given function is determined by its output value...
size_t
: the function output is used as source of randomnessdouble
: output is directly used as draw value [0.0..1.0[
void(RandomDraw&, ...)
: the function manipulates the current instance, to control parameters dynamically, based on input. Definition at line 286 of file random-draw.hpp.
|
inlineprivate |
quantise into limited result value
Definition at line 200 of file random-draw.hpp.
|
inlineprivate |
draw from source of randomness
Definition at line 251 of file random-draw.hpp.
|
inlineprivate |
core operation: draw and quantise into limited value
Definition at line 260 of file random-draw.hpp.
|
inlineprivate |
adapt a function and install it to control drawing and mapping
Definition at line 357 of file random-draw.hpp.
|
inlineprivate |
adapt input side of a given function to conform to the global input arguments as defined in the Policy base function.
Definition at line 369 of file random-draw.hpp.
|
inlineprivate |
adapt output side of a given function, allowing to handle it's results
size_t
result is assumed be a hash and passed into drawLimiteddouble
is assumed to be already a random val to be limitedRandomDraw
instance by value; such a function is assumed to set some parametrisation based on the input data, allowing to change parameters dynamically. Definition at line 400 of file random-draw.hpp.