Copyright | (c) Fabricio Olivetti 2021 - 2024 |
---|---|
License | BSD3 |
Maintainer | fabricio.olivetti@gmail.com |
Stability | experimental |
Portability | FlexibleInstances, DeriveFunctor, ScopedTypeVariables, ConstraintKinds |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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]
- 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
- constsToParam :: Fix SRTree -> (Fix SRTree, [Double])
- floatConstsToParam :: Fix SRTree -> (Fix SRTree, [Double])
- paramsToConst :: [Double] -> Fix SRTree -> Fix SRTree
- newtype Fix f = Fix {}
Documentation
Tree structure to be used with Symbolic Regression algorithms. This structure is a fixed point of a n-ary tree.
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
Instances
Enum Function # | |
Read Function # | |
Show Function # | |
Eq Function # | |
Ord Function # | |
Defined in Data.SRTree.Internal |
getChildren :: Fix SRTree -> [Fix SRTree] #
Get the children of a node. Returns an empty list in case of a leaf node.
>>>
map showExpr . getChildren $ "x0" + 2
["x0", 2]
countNodes :: Num a => Fix SRTree -> a #
Count the number of nodes in a tree.
>>>
countNodes $ "x0" + 2
3
countVarNodes :: Num a => Fix SRTree -> a #
Count the number of Var
nodes
>>>
countVarNodes $ "x0" + 2 * ("x0" - sin "x1")
3
countConsts :: Num a => Fix SRTree -> a #
Count the number of const nodes
>>>
countConsts $ "x0"* 2 + 3 * sin "x0"
2
countParams :: Num a => Fix SRTree -> a #
Count the number of Param
nodes
>>>
countParams $ "x0" + "t0" * sin ("t1" + "x1") - "t0"
3
countOccurrences :: Num a => Int -> Fix SRTree -> a #
Count the occurrences of variable indexed as ix
>>>
countOccurrences 0 $ "x0"* 2 + 3 * sin "x0" + "x1"
2
countUniqueTokens :: Num a => Fix SRTree -> a #
counts the number of unique tokens
>>>
countUniqueTokens $ "x0" + ("x1" * "x0" - sin ("x0" ** 2))
8
numberOfVars :: Num a => Fix SRTree -> a #
return the number of unique variables
>>>
numberOfVars $ "x0" + 2 * ("x0" - sin "x1")
2
getIntConsts :: Fix SRTree -> [Double] #
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 #
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]) #
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]) #
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 #
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)