srtree 0.1.1.0 → 0.1.2.0
raw patch · 5 files changed
+38/−4 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.SRTree: deriveParamBy :: (Eq ix, Eq val, Floating val, OptIntPow val) => ix -> SRTree ix val -> SRTree ix val
+ Data.SRTree.Internal: deriveParamBy :: (Eq ix, Eq val, Floating val, OptIntPow val) => ix -> SRTree ix val -> SRTree ix val
Files
- ChangeLog.md +4/−0
- README.md +1/−2
- src/Data/SRTree.hs +2/−0
- src/Data/SRTree/Internal.hs +29/−0
- srtree.cabal +2/−2
ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for srtree +## 0.1.2.0++Implemented `deriveParamBy` to calculate the derivative by the parameters indexed by `ix`+ ## 0.1.1.0 - Fixed compilation bug
README.md view
@@ -21,14 +21,13 @@ ## Other features: - simplification algorithm (`simplify`)-- derivative w.r.t. a variable (`deriveBy`)+- derivative w.r.t. a variable (`deriveBy`) and w.r.t. a parameter (`deriveParamBy`) - evaluation (`evalTree`) - relabel free parameters sequentially (`relabelParams`) - relabel variables couting their occurrence (`relabelOccurrences`, used with interval arithmetic) ## TODO: -- derivative w.r.t. free parameters - support more advanced functions - support conditional branching (`IF-THEN-ELSE`)
src/Data/SRTree.hs view
@@ -21,6 +21,7 @@ , countVarNodes , countOccurrences , deriveBy+ , deriveParamBy , simplify , derivative , evalFun@@ -44,6 +45,7 @@ , countVarNodes , countOccurrences , deriveBy+ , deriveParamBy , simplify , derivative , evalFun
src/Data/SRTree/Internal.hs view
@@ -24,6 +24,7 @@ , countVarNodes , countOccurrences , deriveBy+ , deriveParamBy , simplify , derivative , evalFun@@ -354,6 +355,34 @@ deriveBy dx (Power l r) = l ** (r-1) * (r * deriveBy dx l + l * log l * deriveBy dx r) deriveBy dx (LogBase l r) = deriveBy dx (log l / log r) {-# INLINE deriveBy #-}++-- | Creates an `SRTree` representing the partial derivative of the input by the parameter indexed by `ix`.+deriveParamBy :: (Eq ix, Eq val, Floating val, OptIntPow val) => ix -> SRTree ix val -> SRTree ix val+deriveParamBy _ Empty = Empty+deriveParamBy dx (Var ix) = 0+deriveParamBy dx (Param ix)+ | dx == ix = 1+ | otherwise = 0+deriveParamBy dx (Const val) = 0+deriveParamBy dx (Fun g t) =+ case deriveParamBy dx t of+ 0 -> 0+ 1 -> derivative g t+ t' -> derivative g t * t'+deriveParamBy dx (Pow t 0) = 0 +deriveParamBy dx (Pow t 1) = deriveParamBy dx t+deriveParamBy dx (Pow t k) = + case deriveParamBy dx t of+ 0 -> 0+ Const val -> Const (val * fromIntegral k) * (t ^. (k-1))+ t' -> fromIntegral k * (t ^. (k-1)) * t'+deriveParamBy dx (Add l r) = deriveParamBy dx l + deriveParamBy dx r+deriveParamBy dx (Sub l r) = deriveParamBy dx l - deriveParamBy dx r+deriveParamBy dx (Mul l r) = deriveParamBy dx l * r + l * deriveParamBy dx r+deriveParamBy dx (Div l r) = (deriveParamBy dx l * r - l * deriveParamBy dx r) / r ^. 2+deriveParamBy dx (Power l r) = l ** (r-1) * (r * deriveParamBy dx l + l * log l * deriveParamBy dx r)+deriveParamBy dx (LogBase l r) = deriveParamBy dx (log l / log r)+{-# INLINE deriveParamBy #-} -- | Simplifies the `SRTree`. simplify :: (Eq ix, Eq val, Floating val, OptIntPow val) => SRTree ix val -> SRTree ix val
srtree.cabal view
@@ -5,9 +5,9 @@ -- see: https://github.com/sol/hpack name: srtree-version: 0.1.1.0+version: 0.1.2.0 synopsis: A general framework to work with Symbolic Regression expression trees.-description: Please see the README on GitHub at <https://github.com/folivetti/srtree#readme>+description: A Symbolic Regression Tree data structure to work with mathematical expressions with support to first order derivative and simplification; category: Math, Data, Data Structures homepage: https://github.com/folivetti/srtree#readme bug-reports: https://github.com/folivetti/srtree/issues