symbolic-regression 0.1.0.1 → 0.1.0.2
raw patch · 4 files changed
+34/−15 lines, 4 filesdep ~directorydep ~srtreedep ~time
Dependency ranges changed: directory, srtree, time
Files
- CHANGELOG.md +5/−0
- cabal.project +0/−10
- src/Symbolic/Regression.hs +24/−1
- symbolic-regression.cabal +5/−4
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for symbolic-regression +## 0.1.0.2++* Add some unary functions+* Update srtree to 2.0.1.6+ ## 0.1.0.0 * Basic integration with srtree
cabal.project view
@@ -2,16 +2,6 @@ allow-newer: table-layout:*, haskeline:*, aeson:*,mwc-random:* allow-older: base -source-repository-package- type: git- location: https://github.com/haskell/mwc-random- tag: 2cce257158befe52417433d1e7717f11ce718aec--source-repository-package- type: git- location: https://github.com/folivetti/srtree- tag: e0663d9da630fc7d17fdeb08485a546a6a634afd- package * extra-include-dirs: /opt/homebrew/include extra-lib-dirs: /opt/homebrew/lib
src/Symbolic/Regression.hs view
@@ -1,6 +1,9 @@ {-# LANGUAGE BlockArguments #-}+{-# LANGUAGE ExplicitNamespaces #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {- |@@ -101,6 +104,8 @@ import qualified Data.SRTree.Internal as SI import Data.SRTree.Print import Data.SRTree.Random+import Data.Type.Equality (TestEquality (testEquality), type (:~:) (Refl))+import Type.Reflection (typeRep) import Algorithm.EqSat (runEqSat) import Algorithm.EqSat.SearchSR@@ -189,7 +194,7 @@ , tournamentSize = 3 , crossoverProbability = 0.95 , mutationProbability = 0.3- , unaryFunctions = []+ , unaryFunctions = [(`F.pow` 2), (`F.pow` 3), log, (1 /)] , binaryFunctions = [(+), (-), (*), (/)] , numParams = -1 , generational = False@@ -274,6 +279,12 @@ toExpr :: D.DataFrame -> Fix SRTree -> Expr Double toExpr _ (Fix (Const value)) = Lit value toExpr df (Fix (Var ix)) = Col (D.columnNames df !! ix)+toExpr df (Fix (Uni f value)) = case f of+ SI.Square -> F.pow (toExpr df value) 2+ SI.Cube -> F.pow (toExpr df value) 3+ SI.Log -> log (toExpr df value)+ SI.Recip -> F.lit 1 / toExpr df value+ treeOp -> error ("UNIMPLEMENTED OPERATION: " ++ show treeOp) toExpr df (Fix (Bin op left right)) = case op of SI.Add -> toExpr df left + toExpr df right SI.Sub -> toExpr df left - toExpr df right@@ -286,7 +297,19 @@ toNonTerminal (BinaryOp "add" _ _ _) = "add" toNonTerminal (BinaryOp "sub" _ _ _) = "sub" toNonTerminal (BinaryOp "mult" _ _ _) = "mul"+toNonTerminal (BinaryOp "divide" _ (Lit n :: Expr b) _) = case testEquality (typeRep @b) (typeRep @Double) of+ Nothing -> error "[Internal Error] - Reciprocal of non-double"+ Just Refl -> case n of+ 1 -> "recip"+ _ -> error "Unknown reciprocal" toNonTerminal (BinaryOp "divide" _ _ _) = "div"+toNonTerminal (BinaryOp "pow" _ _ (e :: Expr b)) = case testEquality (typeRep @b) (typeRep @Int) of+ Nothing -> error "Impossible: Raised to non-int power"+ Just Refl -> case e of+ (Lit 2) -> "square"+ (Lit 3) -> "cube"+ _ -> error "Unknown power"+toNonTerminal (UnaryOp "log" _ _) = "log" toNonTerminal e = error ("Unsupported operation: " ++ show e) egraphGP ::
symbolic-regression.cabal view
@@ -1,7 +1,8 @@ cabal-version: 3.0 name: symbolic-regression-version: 0.1.0.1+version: 0.1.0.2 synopsis: Symbolic Regression in Haskell+description: Automatically discover mathematical expressions that best fit your data using genetic programming with e-graph optimization. license: MIT license-file: LICENSE author: DataHaskell@@ -39,7 +40,7 @@ , random >=1.2 && <1.4 , scheduler >=2.0.0.1 && <3 , split >=0.2.5 && <0.3- , srtree >= 2.0.1.5 && < 3+ , srtree >= 2.0.1.6 && < 3 , statistics >=0.16.2.1 && <0.17 , transformers >=0.6.1.0 && <0.7 , unliftio >=0.2.10 && <1@@ -48,8 +49,8 @@ , text >= 2.0 && < 3 , vector >=0.12 && <0.14 , zlib >=0.6.3 && <0.8- , directory- , time+ , directory >= 1.3.0.0 && < 2+ , time >= 1.12 && < 2 hs-source-dirs: src default-language: Haskell2010