packages feed

BiobaseTypes 0.0.2.1 → 0.0.2.2

raw patch · 2 files changed

+40/−8 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Biobase.Types.Partition: expm1 :: Double -> Double
+ Biobase.Types.Partition: log1p :: Double -> Double
+ Biobase.Types.Partition: logSum :: Double -> Double -> Double
+ Biobase.Types.Partition: mkPartition :: Double -> Partition
+ Biobase.Types.Partition: unPartition' :: Partition -> Double

Files

Biobase/Types/Partition.hs view
@@ -1,4 +1,5 @@ +{-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}@@ -17,23 +18,33 @@ -- | Some default instances. Left out the Num one, so that you have to -- explicitly instanciate if you want to go around the Ring structure. -newtype Partition = Partition {unPartition :: Double}+newtype Partition = Partition {unPartition' :: Double}   deriving (Show, Read, Eq, Ord) +-- | +mkPartition :: Double -> Partition+mkPartition x+  | x < 0     = error $ "mkPartition: prob <0: " ++ show x+  | x > 1     = error $ "mkPartition: prob >1: " ++ show x+  | otherwise = Partition $ log x +unPartition :: Partition -> Double+unPartition (Partition x) = exp x++ -- | Ring operations over Partition values.  instance Ring Partition where-  (Partition a) .+. (Partition b) = Partition $ a + b+  (Partition a) .+. (Partition b) = Partition $ logSum a b   {-# INLINE (.+.) #-}-  (Partition a) .*. (Partition b) = Partition $ a * b+  (Partition a) .*. (Partition b) = Partition $ a + b   {-# INLINE (.*.) #-}-  (Partition a) .^. k = Partition $ a ^ k+  (Partition a) .^. k = Partition $ a * fromIntegral k   {-# INLINE (.^.) #-}   (Partition a) .^^. k = error ".^^. not defined for Partition" -- Partition $ a ^^ k   {-# INLINE (.^^.) #-}-  neg (Partition a) = Partition $ negate a+  neg (Partition a) = error $ "negate partition? " ++ show a -- Partition $ negate a   {-# INLINE neg #-}   one = Partition 1   {-# INLINE one #-}@@ -42,11 +53,32 @@   isZero (Partition a) = a == 0 -- TODO use some epsilon?   {-# INLINE isZero #-} +logSum :: Double -> Double -> Double+logSum a b+  | a>b       = f a b+  | otherwise = f b a+  where+    f x y = x + log1p (exp $ y - x)+    {-# INLINE f #-}+{-# INLINE logSum #-}  --- * Vector instances. +-- * Vector (and Prim) instances.+ deriving instance VGM.MVector VU.MVector Partition deriving instance VG.Vector VU.Vector Partition deriving instance VU.Unbox Partition deriving instance Prim Partition++++-- * math.h function for log/exp on pm1 are /much/ more efficient (what is+-- haskell doing?)++foreign import ccall unsafe "math.h log1p"+    log1p :: Double -> Double++foreign import ccall unsafe "math.h expm1"+    expm1 :: Double -> Double+
BiobaseTypes.cabal view
@@ -1,10 +1,10 @@ name:           BiobaseTypes-version:        0.0.2.1+version:        0.0.2.2 author:         Christian Hoener zu Siederdissen maintainer:     choener@tbi.univie.ac.at copyright:      Christian Hoener zu Siederdissen, 2010 category:       Bioinformatics-synopsis:       Ring class, with several instances.+synopsis:       (deprecated) Ring class, with several instances. license:        GPL-3 license-file:   LICENSE build-type:     Simple