srtree-2.0.1.6: A general library to work with Symbolic Regression expression trees.
Copyright(c) Fabricio Olivetti 2021 - 2024
LicenseBSD3
Maintainerfabricio.olivetti@gmail.com
Stabilityexperimental
PortabilityConstraintKinds
Safe HaskellNone
LanguageHaskell2010

Data.SRTree.Random

Description

Functions to generate random trees and nodes.

Synopsis

Documentation

class HasVars p Source #

Minimal complete definition

_vars

Instances

Instances details
HasVars FullParams Source # 
Instance details

Defined in Data.SRTree.Random

Methods

_vars :: FullParams -> [Int]

class HasVals p Source #

Minimal complete definition

_range

Instances

Instances details
HasVals FullParams Source # 
Instance details

Defined in Data.SRTree.Random

Methods

_range :: FullParams -> (Double, Double)

class HasFuns p Source #

Minimal complete definition

_funs

Instances

Instances details
HasFuns FullParams Source # 
Instance details

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

Constructors

P [Int] (Double, Double) (Int, Int) [Function] 

Instances

Instances details
HasFuns FullParams Source # 
Instance details

Defined in Data.SRTree.Random

Methods

_funs :: FullParams -> [Function]

HasVals FullParams Source # 
Instance details

Defined in Data.SRTree.Random

Methods

_range :: FullParams -> (Double, Double)

HasVars FullParams Source # 
Instance details

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.

type Rng (m :: Type -> Type) a = StateT StdGen m a Source #

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)))))"

toss :: forall (m :: Type -> Type). Monad m => Rng m Bool Source #

tossBiased :: forall (m :: Type -> Type). Monad m => Double -> Rng m Bool Source #

randomVal :: forall (m :: Type -> Type). Monad m => Rng m Double Source #

randomVec :: forall (m :: Type -> Type). Monad m => Int -> Rng m PVector Source #

randomFrom :: forall (m :: Type -> Type) a. Monad m => [a] -> Rng m a Source #