![]() |
Lumiera 0.pre.04
»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 175 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. | |
| RandomDraw && | probability (double p) |
| RandomDraw && | maxVal (Tar m) |
| RandomDraw && | minVal (Tar m) |
| RandomDraw && | shuffle (size_t seed=55) |
| RandomDraw && | fixedVal (Tar v) |
| template<class FUN > | |
| RandomDraw && | mapping (FUN &&fun) |
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) | |
| LazyInit & | operator= (LazyInit const &ref) |
| LazyInit & | operator= (LazyInit &&rref) |
| bool | isInit () const |
| void | installEmptyInitialiser () |
| void | installInitialiser (std::function< SIG > &targetFunctor, INI &&initialiser) |
Private Types | |
| using | Lazy = LazyInit< POL > |
| using | Disabled = Lazy::MarkDisabled |
| using | Sig = _Fun< POL >::Sig |
| using | Fun = function< Sig > |
| using | Tar = _Fun< POL >::Ret |
Private Member Functions | |
| Tar | limited (double val) |
| double | asRand (size_t hash) |
| Tar | drawLimited (size_t hash) |
| template<class FUN > | |
| void | installAdapted (FUN &&fun) |
| template<class FUN > | |
| auto | adaptIn (FUN &&fun) |
| template<class FUN > | |
| auto | adaptOut (FUN &&fun) |
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 constexpr size_t | QUANTISER = 1 << 4 + util::ilog2 (Tar::maxVal()-Tar::minVal()) |
| static constexpr double | CAP_EPSILON = 1/(2.0 * QUANTISER) |
Additional Inherited Members | |
Protected Member Functions inherited from LazyInit< POL > | |
| LazyInit (MarkDisabled, ARGS &&...parentCtorArgs) | |
|
inline |
Drawing is disabled by default, always yielding "zero".
Definition at line 263 of file random-draw.hpp.
References RandomDraw< POL >::mapping().
Here is the call graph for this function:
|
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 279 of file random-draw.hpp.
References RandomDraw< POL >::mapping().
Here is the call graph for this function:Definition at line 178 of file random-draw.hpp.
|
private |
Definition at line 179 of file random-draw.hpp.
Definition at line 181 of file random-draw.hpp.
Definition at line 182 of file random-draw.hpp.
Definition at line 183 of file random-draw.hpp.
|
inlineprivate |
quantise into limited result value
Definition at line 193 of file random-draw.hpp.
References RandomDraw< POL >::CAP_EPSILON, RandomDraw< POL >::maxResult_, RandomDraw< POL >::minResult_, and RandomDraw< POL >::probability_.
Referenced by RandomDraw< POL >::adaptOut(), and RandomDraw< POL >::drawLimited().
Here is the caller graph for this function:
|
inlineprivate |
draw from source of randomness
Definition at line 244 of file random-draw.hpp.
References hash, RandomDraw< POL >::QUANTISER, and RandomDraw< POL >::shuffle_.
Referenced by RandomDraw< POL >::drawLimited().
Here is the caller graph for this function:
|
inlineprivate |
core operation: draw and quantise into limited value
Definition at line 253 of file random-draw.hpp.
References RandomDraw< POL >::asRand(), hash, and RandomDraw< POL >::limited().
Referenced by RandomDraw< POL >::adaptOut().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Definition at line 291 of file random-draw.hpp.
References util::limited(), and RandomDraw< POL >::probability_.
Referenced by TestChainLoad< maxFan >::rule_atJoin_else(), and RandomDraw_test::verify_policy().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Definition at line 298 of file random-draw.hpp.
References RandomDraw< POL >::maxResult_, util::min(), RandomDraw< POL >::minResult_, and RandomDraw< POL >::minVal().
Referenced by RandomDraw< POL >::minVal(), and TestChainLoad< maxFan >::rule_atJoin_else().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Definition at line 307 of file random-draw.hpp.
References util::max(), RandomDraw< POL >::maxResult_, RandomDraw< POL >::maxVal(), and RandomDraw< POL >::minResult_.
Referenced by RandomDraw< POL >::maxVal().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Definition at line 316 of file random-draw.hpp.
References RandomDraw< POL >::shuffle_.
|
inline |
Definition at line 323 of file random-draw.hpp.
References RandomDraw< POL >::mapping().
Referenced by TestChainLoad< maxFan >::rule_atJoin(), TestChainLoad< maxFan >::rule_atLink(), TestChainLoad< maxFan >::rule_atStart(), and TestChainLoad< maxFan >::value().
Here is the call graph for this function:
Here is the caller graph for this function:Definition at line 331 of file random-draw.hpp.
References RandomDraw< POL >::installAdapted(), and LazyInit< POL >::installInitialiser().
Referenced by RandomDraw< POL >::RandomDraw(), RandomDraw< POL >::RandomDraw(), RandomDraw< POL >::fixedVal(), TestChainLoad< maxFan >::rule_atJoin(), TestChainLoad< maxFan >::rule_atJoin_else(), TestChainLoad< maxFan >::rule_atLink(), and TestChainLoad< maxFan >::rule_atStart().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlineprivate |
adapt a function and install it to control drawing and mapping
Definition at line 350 of file random-draw.hpp.
References RandomDraw< POL >::adaptIn(), and RandomDraw< POL >::adaptOut().
Referenced by RandomDraw< POL >::mapping().
Here is the call graph for this function:
Here is the caller graph for this function:
|
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 362 of file random-draw.hpp.
Referenced by RandomDraw< POL >::installAdapted().
Here is the caller graph for this function:
|
inlineprivate |
adapt output side of a given function, allowing to handle it's results
size_t result is assumed to 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 392 of file random-draw.hpp.
References lib::meta::func::chained(), RandomDraw< POL >::drawLimited(), hash, and RandomDraw< POL >::limited().
Referenced by RandomDraw< POL >::installAdapted().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
maximum result val actually to produce < max
Definition at line 185 of file random-draw.hpp.
Referenced by RandomDraw< POL >::limited(), RandomDraw< POL >::maxVal(), and RandomDraw< POL >::minVal().
|
private |
minimum result val actually to produce > min
Definition at line 186 of file random-draw.hpp.
Referenced by RandomDraw< POL >::limited(), RandomDraw< POL >::maxVal(), and RandomDraw< POL >::minVal().
|
private |
probability that value is in [min .. max] \ neutral
Definition at line 187 of file random-draw.hpp.
Referenced by RandomDraw< POL >::limited(), and RandomDraw< POL >::probability().
|
private |
statefull additional randomisation to inject into hash
Definition at line 188 of file random-draw.hpp.
Referenced by RandomDraw< POL >::asRand(), and RandomDraw< POL >::shuffle().
|
staticconstexprprivate |
Definition at line 238 of file random-draw.hpp.
Referenced by RandomDraw< POL >::asRand().
|
staticconstexprprivate |
Definition at line 239 of file random-draw.hpp.
Referenced by RandomDraw< POL >::limited().
Inheritance diagram for RandomDraw< POL >:
Collaboration diagram for RandomDraw< POL >: