Refactor - introducte Probability file
This commit is contained in:
parent
3266919da9
commit
e5efd90bc3
@ -26,6 +26,7 @@ library
|
|||||||
, GEval.PrecisionRecall
|
, GEval.PrecisionRecall
|
||||||
, GEval.ClusteringMetrics
|
, GEval.ClusteringMetrics
|
||||||
, GEval.Common
|
, GEval.Common
|
||||||
|
, GEval.Probability
|
||||||
, GEval.LogLossHashed
|
, GEval.LogLossHashed
|
||||||
, GEval.CharMatch
|
, GEval.CharMatch
|
||||||
, GEval.LineByLine
|
, GEval.LineByLine
|
||||||
|
@ -7,24 +7,7 @@ module GEval.ProbList
|
|||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
|
||||||
import GEval.Common
|
import GEval.Common
|
||||||
|
import GEval.Probability
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
data ProbList = ProbList [WordWithProb]
|
data ProbList = ProbList [WordWithProb]
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
21
src/GEval/Probability.hs
Normal file
21
src/GEval/Probability.hs
Normal 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
|
Loading…
Reference in New Issue
Block a user