Refactor - introducte Probability file

This commit is contained in:
Filip Gralinski 2019-09-07 12:34:45 +02:00
parent 3266919da9
commit e5efd90bc3
3 changed files with 23 additions and 18 deletions

View File

@ -26,6 +26,7 @@ library
, GEval.PrecisionRecall
, GEval.ClusteringMetrics
, GEval.Common
, GEval.Probability
, GEval.LogLossHashed
, GEval.CharMatch
, GEval.LineByLine

View File

@ -7,24 +7,7 @@ module GEval.ProbList
import qualified Data.Text as T
import GEval.Common
newtype Probability = P { getP :: Double }
deriving (Eq,Ord,Show)
isProbability :: Double -> Bool
isProbability p = 0.0 <= p && p <= 1.0
mkProbability :: Double -> Probability
mkProbability p
| isProbability p = P p
| otherwise = error $ show p ++ " is not in [0, 1]"
probabilityOne :: Probability
probabilityOne = mkProbability 1.0
probabilityZero :: Probability
probabilityZero = mkProbability 0.0
import GEval.Probability
data ProbList = ProbList [WordWithProb]
deriving (Show)

21
src/GEval/Probability.hs Normal file
View File

@ -0,0 +1,21 @@
module GEval.Probability
(Probability, getP, isProbability, mkProbability, probabilityOne, probabilityZero)
where
newtype Probability = P { getP :: Double }
deriving (Eq, Ord, Show)
isProbability :: Double -> Bool
isProbability p = 0.0 <= p && p <= 1.0
mkProbability :: Double -> Probability
mkProbability p
| isProbability p = P p
| otherwise = error $ show p ++ " is not in [0, 1]"
probabilityOne :: Probability
probabilityOne = mkProbability 1.0
probabilityZero :: Probability
probabilityZero = mkProbability 0.0