| Copyright | (c) Fabricio Olivetti 2021 - 2024 |
|---|---|
| License | BSD3 |
| Maintainer | fabricio.olivetti@gmail.com |
| Stability | experimental |
| Portability | FlexibleInstances, DeriveFunctor, ScopedTypeVariables |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Data.SRTree.Internal
Description
Expression tree for Symbolic Regression
Synopsis
- data SRTree val
- data Function
- data Op
- param :: Int -> Fix SRTree
- var :: Int -> Fix SRTree
- constv :: Double -> Fix SRTree
- arity :: Fix SRTree -> Int
- getChildren :: Fix SRTree -> [Fix SRTree]
- childrenOf :: SRTree a -> [a]
- replaceChildren :: [a] -> SRTree b -> SRTree a
- getOperator :: SRTree a -> SRTree ()
- countNodes :: Num a => Fix SRTree -> a
- countVarNodes :: Num a => Fix SRTree -> a
- countConsts :: Num a => Fix SRTree -> a
- countParams :: Num a => Fix SRTree -> a
- countOccurrences :: Num a => Int -> Fix SRTree -> a
- countUniqueTokens :: Num a => Fix SRTree -> a
- numberOfVars :: Num a => Fix SRTree -> a
- getIntConsts :: Fix SRTree -> [Double]
- relabelParams :: Fix SRTree -> Fix SRTree
- relabelVars :: Fix SRTree -> Fix SRTree
- constsToParam :: Fix SRTree -> (Fix SRTree, [Double])
- floatConstsToParam :: Fix SRTree -> (Fix SRTree, [Double])
- paramsToConst :: [Double] -> Fix SRTree -> Fix SRTree
- newtype Fix (f :: Type -> Type) = Fix {}
Documentation
Tree structure to be used with Symbolic Regression algorithms. This structure is a fixed point of a n-ary tree.
Constructors
| Var Int | index of the variables |
| Param Int | index of the parameter |
| Const Double | constant value, can be converted to a parameter | IConst Int -- TODO: integer constant | RConst Ratio -- TODO: rational constant |
| Uni Function val | univariate function |
| Bin Op val val | binary operator |
Instances
Supported functions
Constructors
| Id | |
| Abs | |
| Sin | |
| Cos | |
| Tan | |
| Sinh | |
| Cosh | |
| Tanh | |
| ASin | |
| ACos | |
| ATan | |
| ASinh | |
| ACosh | |
| ATanh | |
| Sqrt | |
| SqrtAbs | |
| Cbrt | |
| Square | |
| Log | |
| LogAbs | |
| Exp | |
| Recip | |
| Cube |
Instances
| Enum Function Source # | |
Defined in Data.SRTree.Internal | |
| Read Function Source # | |
| Show Function Source # | |
| Eq Function Source # | |
| Ord Function Source # | |
Defined in Data.SRTree.Internal | |
Supported operators
constv :: Double -> Fix SRTree Source #
create a tree with a single node representing a constant value
getChildren :: Fix SRTree -> [Fix SRTree] Source #
Get the children of a node. Returns an empty list in case of a leaf node.
>>>map showExpr . getChildren $ "x0" + 2["x0", 2]
childrenOf :: SRTree a -> [a] Source #
Get the children of an unfixed node
replaceChildren :: [a] -> SRTree b -> SRTree a Source #
replaces the children with elements from a list
getOperator :: SRTree a -> SRTree () Source #
returns a node containing the operator and () as children
countNodes :: Num a => Fix SRTree -> a Source #
Count the number of nodes in a tree.
>>>countNodes $ "x0" + 23
countVarNodes :: Num a => Fix SRTree -> a Source #
Count the number of Var nodes
>>>countVarNodes $ "x0" + 2 * ("x0" - sin "x1")3
countConsts :: Num a => Fix SRTree -> a Source #
Count the number of const nodes
>>>countConsts $ "x0"* 2 + 3 * sin "x0"2
countParams :: Num a => Fix SRTree -> a Source #
Count the number of Param nodes
>>>countParams $ "x0" + "t0" * sin ("t1" + "x1") - "t0"3
countOccurrences :: Num a => Int -> Fix SRTree -> a Source #
Count the occurrences of variable indexed as ix
>>>countOccurrences 0 $ "x0"* 2 + 3 * sin "x0" + "x1"2
countUniqueTokens :: Num a => Fix SRTree -> a Source #
counts the number of unique tokens
>>>countUniqueTokens $ "x0" + ("x1" * "x0" - sin ("x0" ** 2))8
numberOfVars :: Num a => Fix SRTree -> a Source #
return the number of unique variables
>>>numberOfVars $ "x0" + 2 * ("x0" - sin "x1")2
getIntConsts :: Fix SRTree -> [Double] Source #
returns the integer constants. We assume an integer constant as those values in which `floor x == ceiling x`.
>>>getIntConsts $ "x0" + 2 * "x1" ** 3 - 3.14[2.0,3.0]
relabelParams :: Fix SRTree -> Fix SRTree Source #
Relabel the parameters indices incrementaly starting from 0
>>>showExpr . relabelParams $ "x0" + "t0" * sin ("t1" + "x1") - "t0""x0" + "t0" * sin ("t1" + "x1") - "t2"
relabelVars :: Fix SRTree -> Fix SRTree Source #
Relabel the parameters indices incrementaly starting from 0
>>>showExpr . relabelParams $ "x0" + "t0" * sin ("t1" + "x1") - "t0""x0" + "t0" * sin ("t1" + "x1") - "t2"
constsToParam :: Fix SRTree -> (Fix SRTree, [Double]) Source #
Change constant values to a parameter, returning the changed tree and a list of parameter values
>>>snd . constsToParam $ "x0" * 2 + 3.14 * sin (5 * "x1")[2.0,3.14,5.0]
floatConstsToParam :: Fix SRTree -> (Fix SRTree, [Double]) Source #
Same as constsToParam but does not change constant values that
can be converted to integer without loss of precision
>>>snd . floatConstsToParam $ "x0" * 2 + 3.14 * sin (5 * "x1")[3.14]
paramsToConst :: [Double] -> Fix SRTree -> Fix SRTree Source #
Convert the parameters into constants in the tree
>>>showExpr . paramsToConst [1.1, 2.2, 3.3] $ "x0" + "t0" * sin ("t1" * "x0" - "t2")x0 + 1.1 * sin(2.2 * x0 - 3.3)
newtype Fix (f :: Type -> Type) Source #