| Copyright | (c) Fabricio Olivetti 2021 - 2024 |
|---|---|
| License | BSD3 |
| Maintainer | fabricio.olivetti@gmail.com |
| Stability | experimental |
| Portability | ConstraintKinds |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.SRTree.Random
Description
Functions to generate random trees and nodes.
Synopsis
- class HasVars p
- class HasVals p
- class HasFuns p
- type HasEverything p = (HasVars p, HasVals p, HasExps p, HasFuns p)
- data FullParams = P [Int] (Double, Double) (Int, Int) [Function]
- type RndTree (m :: Type -> Type) p = ReaderT p (StateT StdGen m) (Fix SRTree)
- type Rng (m :: Type -> Type) a = StateT StdGen m a
- randomVar :: forall (m :: Type -> Type) p. (Monad m, HasVars p) => RndTree m p
- randomConst :: forall p (m :: Type -> Type). (HasVals p, Monad m) => RndTree m p
- randomPow :: forall p (m :: Type -> Type). (HasExps p, Monad m) => RndTree m p
- randomFunction :: forall p (m :: Type -> Type). (HasFuns p, Monad m) => RndTree m p
- randomNode :: forall p (m :: Type -> Type). (HasEverything p, Monad m) => RndTree m p
- randomNonTerminal :: forall p (m :: Type -> Type). (HasEverything p, Monad m) => RndTree m p
- randomRange :: forall val (m :: Type -> Type). (Ord val, Random val, Monad m) => (val, val) -> Rng m val
- randomTreeTemplate :: forall p (m :: Type -> Type). (HasEverything p, Monad m) => Int -> RndTree m p
- randomTree :: forall (m :: Type -> Type). Monad m => Int -> Int -> Int -> Rng m (Fix SRTree) -> Rng m (SRTree ()) -> Bool -> Rng m (Fix SRTree)
- randomTreeBalanced :: forall p (m :: Type -> Type). (HasEverything p, Monad m) => Int -> RndTree m p
- toss :: forall (m :: Type -> Type). Monad m => Rng m Bool
- tossBiased :: forall (m :: Type -> Type). Monad m => Double -> Rng m Bool
- randomVal :: forall (m :: Type -> Type). Monad m => Rng m Double
- randomVec :: forall (m :: Type -> Type). Monad m => Int -> Rng m PVector
- randomFrom :: forall (m :: Type -> Type) a. Monad m => [a] -> Rng m a
Documentation
Minimal complete definition
_vars
Instances
| HasVars FullParams Source # | |
Defined in Data.SRTree.Random Methods _vars :: FullParams -> [Int] | |
Minimal complete definition
_range
Instances
| HasVals FullParams Source # | |
Defined in Data.SRTree.Random Methods _range :: FullParams -> (Double, Double) | |
Minimal complete definition
_funs
Instances
| HasFuns FullParams Source # | |
Defined in Data.SRTree.Random Methods _funs :: FullParams -> [Function] | |
type HasEverything p = (HasVars p, HasVals p, HasExps p, HasFuns p) Source #
Constraint synonym for all properties.
data FullParams Source #
A structure with every property
Instances
| HasFuns FullParams Source # | |
Defined in Data.SRTree.Random Methods _funs :: FullParams -> [Function] | |
| HasVals FullParams Source # | |
Defined in Data.SRTree.Random Methods _range :: FullParams -> (Double, Double) | |
| HasVars FullParams Source # | |
Defined in Data.SRTree.Random Methods _vars :: FullParams -> [Int] | |
type RndTree (m :: Type -> Type) p = ReaderT p (StateT StdGen m) (Fix SRTree) Source #
RndTree is a Monad Transformer to generate random trees of type `SRTree ix val`
given the parameters `p ix val` using the random number generator StdGen.
randomVar :: forall (m :: Type -> Type) p. (Monad m, HasVars p) => RndTree m p Source #
Returns a random variable, the parameter p must have the HasVars property
randomConst :: forall p (m :: Type -> Type). (HasVals p, Monad m) => RndTree m p Source #
Returns a random constant, the parameter p must have the HasConst property
randomPow :: forall p (m :: Type -> Type). (HasExps p, Monad m) => RndTree m p Source #
Returns a random integer power node, the parameter p must have the HasExps property
randomFunction :: forall p (m :: Type -> Type). (HasFuns p, Monad m) => RndTree m p Source #
Returns a random function, the parameter p must have the HasFuns property
randomNode :: forall p (m :: Type -> Type). (HasEverything p, Monad m) => RndTree m p Source #
Returns a random node, the parameter p must have every property.
randomNonTerminal :: forall p (m :: Type -> Type). (HasEverything p, Monad m) => RndTree m p Source #
Returns a random non-terminal node, the parameter p must have every property.
randomRange :: forall val (m :: Type -> Type). (Ord val, Random val, Monad m) => (val, val) -> Rng m val Source #
randomTreeTemplate :: forall p (m :: Type -> Type). (HasEverything p, Monad m) => Int -> RndTree m p Source #
Returns a random tree with a limited budget, the parameter p must have every property.
>>>let treeGen = runReaderT (randomTree 12) (P [0,1] (-10, 10) (2, 3) [Log, Exp])>>>tree <- evalStateT treeGen (mkStdGen 52)>>>showExpr tree"(-2.7631152121655838 / Exp((x0 / ((x0 * -7.681722660704317) - Log(3.378309080134594)))))"
randomTree :: forall (m :: Type -> Type). Monad m => Int -> Int -> Int -> Rng m (Fix SRTree) -> Rng m (SRTree ()) -> Bool -> Rng m (Fix SRTree) Source #
randomTreeBalanced :: forall p (m :: Type -> Type). (HasEverything p, Monad m) => Int -> RndTree m p Source #
Returns a random tree with a approximately a number n of nodes, the parameter p must have every property.
>>>let treeGen = runReaderT (randomTreeBalanced 10) (P [0,1] (-10, 10) (2, 3) [Log, Exp])>>>tree <- evalStateT treeGen (mkStdGen 42)>>>showExpr tree"Exp(Log((((7.784360517385774 * x0) - (3.6412224491658223 ^ x1)) ^ ((x0 ^ -4.09764995657091) + Log(-7.710216839988497)))))"