Lumiera  0.pre.03
»edit your freedom«
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 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
 
LazyInitoperator= (LazyInit const &ref)
 
LazyInitoperator= (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)
 

Constructor & Destructor Documentation

◆ RandomDraw()

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 286 of file random-draw.hpp.

Member Function Documentation

◆ limited()

Tar limited ( double  val)
inlineprivate

quantise into limited result value

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

◆ asRand()

double asRand ( size_t  hash)
inlineprivate

draw from source of randomness

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

◆ drawLimited()

Tar drawLimited ( size_t  hash)
inlineprivate

core operation: draw and quantise into limited value

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

◆ installAdapted()

void installAdapted ( FUN &&  fun)
inlineprivate

adapt a function and install it to control drawing and mapping

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

◆ adaptIn()

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 369 of file random-draw.hpp.

◆ adaptOut()

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 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 400 of file random-draw.hpp.

+ Inheritance diagram for RandomDraw< POL >:
+ Collaboration diagram for RandomDraw< POL >:

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