boltzmann-samplers-0.1.1.0: Uniform random generators

Boltzmann.Data.Data

Description

Internal module

Derive Boltzmann samplers for SYB-generic types.

Synopsis

# Documentation

data SG r Source #

Sized generator.

Constructors

 SG FieldsminSize :: Size maxSizeM :: Maybe Size runSG :: Points -> Maybe Double -> r runSmallG :: Points -> r

Instances

 Source # Methodsfmap :: (a -> b) -> SG a -> SG b #(<\$) :: a -> SG b -> SG a #

type Points = Int Source #

Number of pointing iterations.

applySG :: SG r -> Points -> Maybe Double -> r Source #

For documentation.

# Helper functions

make :: (Data a, MonadRandomLike m) => [Alias m] -> proxy a -> SG (m a) Source #

makeR :: (Data a, MonadRandomLike m) => [AliasR m] -> proxy a -> SG ((Size, Size) -> m a) Source #

type Size' = Int Source #

The size of a value is its number of constructors.

Here, however, the Size' type is interpreted differently to make better use of QuickCheck's size parameter provided by the sized combinator, so that we generate non-trivial data even at very small size values.

For infinite types, with objects of unbounded sizes > minSize, given a parameter delta :: Size', the produced values have an average size close to minSize + delta.

For example, values of type Either () [Bool] have at least two constructors, so

  generator delta :: Gen (Either () [Bool])


will target sizes close to 2 + delta; the offset becomes less noticeable as delta grows to infinity.

For finite types with sizes in [minSize, maxSize], the target expected size is obtained by clamping a Size' to [0, 99] and applying an affine mapping.

apply :: SG r -> Points -> Maybe Size' -> r Source #

applyR :: SG ((Size, Size) -> r) -> Points -> Maybe Size' -> (Size', Size') -> r Source #

'epsilon' = 0.1

Default approximation ratio.

tolerance :: Double -> Int -> (Int, Int) Source #

(size * (1 - epsilon), size * (1 + epsilon))

# Auxiliary definitions

memo :: (t -> [t2] -> SG r) -> (SG r -> t1 -> Maybe Int -> a) -> t -> t1 -> Int -> a Source #

sparseSized :: (Int -> a) -> Maybe Int -> Int -> a Source #