Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
RandomDraw< POL > Class Template Reference

#include "lib/random-draw.hpp"

Description

template<class POL>
class lib::RandomDraw< POL >

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.

Template Parameters
POLconfiguration 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)
 
LazyInitoperator= (LazyInit const &ref)
 
LazyInitoperator= (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)
 

Constructor & Destructor Documentation

◆ RandomDraw() [1/2]

template<class POL >
RandomDraw ( )
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:

◆ RandomDraw() [2/2]

template<class POL >
template<class FUN , typename = disable_if_self<RandomDraw, FUN>>
RandomDraw ( FUN &&  fun)
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 randomness
  • double: 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:

Member Typedef Documentation

◆ Lazy

template<class POL >
using Lazy = LazyInit<POL>
private

Definition at line 178 of file random-draw.hpp.

◆ Disabled

template<class POL >
using Disabled = Lazy::MarkDisabled
private

Definition at line 179 of file random-draw.hpp.

◆ Sig

template<class POL >
using Sig = _Fun<POL>::Sig
private

Definition at line 181 of file random-draw.hpp.

◆ Fun

template<class POL >
using Fun = function<Sig>
private

Definition at line 182 of file random-draw.hpp.

◆ Tar

template<class POL >
using Tar = _Fun<POL>::Ret
private

Definition at line 183 of file random-draw.hpp.

Member Function Documentation

◆ limited()

template<class POL >
Tar limited ( double  val)
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:

◆ asRand()

template<class POL >
double asRand ( size_t  hash)
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:

◆ drawLimited()

template<class POL >
Tar drawLimited ( size_t  hash)
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:

◆ probability()

template<class POL >
RandomDraw && probability ( double  p)
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:

◆ maxVal()

template<class POL >
RandomDraw && maxVal ( Tar  m)
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:

◆ minVal()

template<class POL >
RandomDraw && minVal ( Tar  m)
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:

◆ shuffle()

template<class POL >
RandomDraw && shuffle ( size_t  seed = 55)
inline

Definition at line 316 of file random-draw.hpp.

References RandomDraw< POL >::shuffle_.

◆ fixedVal()

template<class POL >
RandomDraw && fixedVal ( Tar  v)
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:

◆ mapping()

template<class POL >
template<class FUN >
RandomDraw && mapping ( FUN &&  fun)
inline

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:

◆ installAdapted()

template<class POL >
template<class FUN >
void installAdapted ( FUN &&  fun)
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:

◆ adaptIn()

template<class POL >
template<class FUN >
auto adaptIn ( FUN &&  fun)
inlineprivate

adapt input side of a given function to conform to the global input arguments as defined in the Policy base function.

Returns
a function pre-fitted with a suitable Adapter from the Policy

Definition at line 362 of file random-draw.hpp.

Referenced by RandomDraw< POL >::installAdapted().

+ Here is the caller graph for this function:

◆ adaptOut()

template<class POL >
template<class FUN >
auto adaptOut ( FUN &&  fun)
inlineprivate

adapt output side of a given function, allowing to handle it's results

  • a function producing the overall result-type is installed as-is
  • a size_t result is assumed to be a hash and passed into drawLimited
  • likewise a double is assumed to be already a random val to be limited
  • special treatment is given to a function returning a RandomDraw instance by value; such a function is assumed to set some parametrisation based on the input data, allowing to change parameters dynamically.
    Returns
    adapted function which produces a result value of type Tar

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:

Member Data Documentation

◆ maxResult_

template<class POL >
Tar maxResult_ {Tar::maxVal()}
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().

◆ minResult_

template<class POL >
Tar minResult_ {Tar::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().

◆ probability_

template<class POL >
double probability_ {0}
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().

◆ shuffle_

template<class POL >
size_t shuffle_ {0}
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().

◆ QUANTISER

template<class POL >
constexpr size_t QUANTISER = 1 << 4 + util::ilog2 (Tar::maxVal()-Tar::minVal())
staticconstexprprivate

Definition at line 238 of file random-draw.hpp.

Referenced by RandomDraw< POL >::asRand().

◆ CAP_EPSILON

template<class POL >
constexpr double CAP_EPSILON = 1/(2.0 * QUANTISER)
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 >:

The documentation for this class was generated from the following file: