Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions HReg.cabal

This file was deleted.

1 change: 0 additions & 1 deletion TimeTest

This file was deleted.

15 changes: 11 additions & 4 deletions input
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
0.01 2.46 0.88 2.33 2.28 2.24 2.21 2.17 2.14 2.11 2.08 2.03 2.02 2.04 1.99 1.95 1.91 1.87
0.02 4.98 1.73 4.6 4.45 4.31 4.15 4.07 3.97 3.86 3.78 3.7 3.62 3.5 3.39 3.29 3.2 3.13
0.03 7.45 2.49 6.84 6.47 6.2 5.97 5.76 5.56 5.41 5.27 5.13 5 4.81 4.65 4.5 4.37 4.27
0.04 9.99 3.26 8.88 8.32 7.9 7.53 7.23 6.97 6.75 6.55 6.36 6.21 5.95 5.73 5.55 5.42 5.29
t 10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0 110.0 120.0
0.01 0.05 0.06 0.06 0.15 0.17 0.23 0.54 1.23 5.32 4.23 5.02 7.03 kappa0=15.0 kappaInf=14.0
0.02 0.05 0.06 0.06 0.15 0.17 0.23 0.54 1.23 5.32 4.23 5.02 7.03 kappa0=15.0 kappaInf=14.0
0.03 0.05 0.06 0.06 0.15 0.17 0.23 0.54 1.23 5.32 4.23 5.02 7.03 kappa0=15.0 kappaInf=14.0
0.04 0.05 0.06 0.06 0.15 0.17 0.23 0.54 1.23 5.32 4.23 5.02 7.03 kappa0=15.0 kappaInf=14.0

t 10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0 110.0 120.0
0.01 0.05 0.06 0.06 0.15 0.17 0.23 0.54 1.23 5.32 4.23 5.02 7.03 kappa0=15.0 kappaInf=14.0
0.02 0.05 0.06 0.06 0.15 0.17 0.23 0.54 1.23 5.32 4.23 5.02 7.03 kappa0=15.0 kappaInf=14.0
0.03 0.05 0.06 0.06 0.15 0.17 0.23 0.54 1.23 5.32 4.23 5.02 7.03 kappa0=15.0 kappaInf=14.0
0.04 0.05 0.06 0.06 0.15 0.17 0.23 0.54 1.23 5.32 4.23 5.02 7.03 kappa0=15.0 kappaInf=14.0
57 changes: 57 additions & 0 deletions linreg.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.31.1.
--
-- see: https://github.com/sol/hpack
--
-- hash: fa0bf8bdd10e604d4f1906b3674014839def0801ad2d850159658cec73d30778

name: linreg
version: 0.1.0.0
description: Fitting ester hydrolysis kinetics correctly
homepage: https://github.com/ptrab/linreg#readme
bug-reports: https://github.com/ptrab/linreg/issues
author: Philipp Traber
maintainer: phillip.traber@uni-jena.de
copyright: 2019 Philipp Traber
license: GPL-3
license-file: LICENSE
build-type: Simple
extra-source-files:
LICENSE

source-repository head
type: git
location: https://github.com/ptrab/linreg

library
exposed-modules:
Linreg.Numeric
Linreg.Parser
Linreg.Types
other-modules:
Paths_linreg
hs-source-dirs:
src/lib
ghc-options: -optP-Wno-nonportable-include-path -O2 -Wall -Wno-unused-top-binds -Wno-unused-local-binds -Wno-type-defaults
build-depends:
attoparsec >=0.13.2.2
, base >=4.7 && <5
, text >=1.2.3.1
, time >=1.8.0.2
default-language: Haskell2010

executable exckel
main-is: linreg.hs
other-modules:
Paths_linreg
hs-source-dirs:
src/app
ghc-options: -threaded -rtsopts -with-rtsopts=-N -optP-Wno-nonportable-include-path -O2 -Wall -Wno-unused-top-binds -Wno-unused-local-binds -Wno-type-defaults
build-depends:
attoparsec >=0.13.2.2
, base >=4.7 && <5
, linreg
, text >=1.2.3.1
, time >=1.8.0.2
default-language: Haskell2010
62 changes: 62 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: linreg
version: 0.1.0.0
github: "ptrab/linreg"
license: GPL-3
author: "Philipp Traber"
maintainer: "phillip.traber@uni-jena.de"
copyright: "2019 Philipp Traber"

extra-source-files:
- LICENSE

# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Fitting ester hydrolysis kinetics correctly

dependencies:
- base >= 4.7 && < 5
- text >= 1.2.3.1
- attoparsec >= 0.13.2.2
- time >= 1.8.0.2

library:
source-dirs: src/lib
ghc-options:
- -optP-Wno-nonportable-include-path
- -O2
- -Wall
- -Wno-unused-top-binds
- -Wno-unused-local-binds
- -Wno-type-defaults
# - -static
# - -fPIC
# - -optl-static
# - -optl-pthread
#- -optc-static

executables:
exckel:
main: linreg.hs
source-dirs: src/app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -optP-Wno-nonportable-include-path
- -O2
- -Wall
- -Wno-unused-top-binds
- -Wno-unused-local-binds
- -Wno-type-defaults
# - -static
# - -fPIC
# - -optl-static
# - -optl-pthread
#- -optc-static
dependencies:
- linreg
6 changes: 3 additions & 3 deletions src/app/HReg.hs → src/app/linreg.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Data.Attoparsec.Text.Lazy
import qualified Data.Text.IO as T
import HReg.Numeric
import HReg.Parser
import Linreg.Numeric
import Linreg.Parser
import System.Environment

main :: IO ()
main = do
inputFilePath <- head <$> getArgs
rawVals <- T.readFile inputFilePath
let vals = parseOnly (many1 parse_LinRegValues) rawVals
let vals = concat <$> parseOnly (many1 linRegValues) rawVals
results = regression <$> vals
case results of
Right (Just x) -> putStr $ show x
Expand Down
59 changes: 0 additions & 59 deletions src/lib/HReg/Parser.hs

This file was deleted.

21 changes: 8 additions & 13 deletions src/lib/HReg/Numeric.hs → src/lib/Linreg/Numeric.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module HReg.Numeric
module Linreg.Numeric
( regression
) where
import Data.List
import Data.Maybe
import Data.Time
import HReg.Types
import Linreg.Types

--------------------------------------------------------------------------------
-- helper functions
Expand All @@ -31,7 +30,7 @@ genT i
-- regression logic
--------------------------------------------------------------------------------
-- | calculate c0/c = (kappa0 - kappaInf) / (kappaT - kappaInf)
c0pc :: LinRegValues -> [(Maybe DiffTime, Double)]
c0pc :: LinRegValues -> [(DiffTime, Double)]
c0pc vals =
[ (fst i, (kappa0' - kappaInf') / (snd i - kappaInf'))
| i <- kappaT'
Expand All @@ -49,17 +48,17 @@ sumY y = sum . concat $ y
-- | Calculates the sum over the c*x products
-- | sum_i^n sum_j^m c_j x_i
sumCX :: (Num a) => [a] -> [a] -> a
sumCX c x = sum $ (*) <$> c <*> x
sumCX c' x = sum $ (*) <$> c' <*> x

-- | Sum of all squared c and x values
-- | sum_i^n sum_j^m c_j^2 x_i^2
sumC2X2 :: (Num a) => [a] -> [a] -> a
sumC2X2 c x = sum $ (*) <$> map (^2) c <*> map (^2) x
sumC2X2 c' x = sum $ (*) <$> map (^2) c' <*> map (^2) x

-- | Zipping products
-- | sum_i^n sum_j^m c_j x_i y_ij
sumCXY :: (Num a) => [a] -> [a] -> [[a]] -> a
sumCXY c x y = sum $ zipWith (*) ((*) <$> c <*> x) (concat y)
sumCXY c' x y = sum $ zipWith (*) ((*) <$> c' <*> x) (concat y)

-- | Mean of a list
-- | sum_i^n x_i / n
Expand Down Expand Up @@ -103,14 +102,10 @@ regression vals
--
c' = map c vals
mVals = map c0pc vals
t' = nub . map (map $ fmap ((/10^12) . fromIntegral . diffTimeToPicoseconds) . fst) $ mVals
t' = nub . map (map $ (/10^12) . fromIntegral . diffTimeToPicoseconds . fst) $ mVals
timesAllTheSame = length t' == 1
t'' = head t'
t''' =
[ fromMaybe (genT i) (t'' !! i)
| i <- [0 .. length t'' - 1]
]
x' = t'''
x' = t''
y' = map (map snd) mVals
sCX = sumCX c' x'
sCXY = sumCXY c' x' y'
Expand Down
54 changes: 54 additions & 0 deletions src/lib/Linreg/Parser.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{-# LANGUAGE OverloadedStrings #-}
module Linreg.Parser
( linRegValues
) where
import Data.Attoparsec.Text.Lazy
import Data.Time
import Linreg.Types
import Prelude hiding (takeWhile)

-- | Parsing a single block with same "t" as shown in this repository (see "input" file).
linRegValues :: Parser [LinRegValues]
linRegValues = do
-- Parse first line of a block, starting with a "t", followed by many times in seconds
timeSeries <- do
skipSpace
_ <- string "t"
_ <- takeWhile isHorizontalSpace
times <- many1 $ do
time <- double
_ <- takeWhile isHorizontalSpace
return time
endOfLine
return times
-- Parse multiple lines of concentration series. First number is c0, then followed by
-- (length times) concentrations corresponding to the times and then kappa0 and kappaInf
linregSeries <- many1 $ do
_ <- takeWhile isHorizontalSpace
c' <- double
_ <- takeWhile isHorizontalSpace
kappaT' <- count (length timeSeries) $ do
cAtTime <- double
_ <- takeWhile isHorizontalSpace
return cAtTime
_ <- takeWhile isHorizontalSpace
_ <- string "kappa0"
_ <- takeWhile isHorizontalSpace
_ <- string "="
_ <- takeWhile isHorizontalSpace
kappa0' <- double
_ <- takeWhile isHorizontalSpace
_ <- string "kappaInf"
_ <- takeWhile isHorizontalSpace
_ <- string "="
_ <- takeWhile isHorizontalSpace
kappaInf' <- double
_ <- takeWhile isHorizontalSpace
endOfLine
return LinRegValues
{ c = c'
, kappa0 = kappa0'
, kappaInf = kappaInf'
, kappaT = zip (map (picosecondsToDiffTime . (* 10^12) . round) $ timeSeries) kappaT'
}
return linregSeries
6 changes: 2 additions & 4 deletions src/lib/HReg/Types.hs → src/lib/Linreg/Types.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
module HReg.Types
module Linreg.Types
( LinRegValues(..)
, RegressionResult(..)
) where
import Data.Time
import Data.Text
import Text.Printf

-- | what we get from the measurements
data LinRegValues = LinRegValues
{ c :: Double -- concentration of this series
, kappa0 :: Double
, kappaInf :: Double
, kappaT :: [(Maybe DiffTime, Double)] -- the optional time and corresping
-- kappa_t
, kappaT :: [(DiffTime, Double)] -- the time and corresping kappa_t
}

-- | what we calculate by regression from the measurements
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-12.1
resolver: lts-13.14

# User packages to be built.
# Various formats can be used as shown in the example below.
Expand Down