implement mean absolute error
This commit is contained in:
parent
1073407760
commit
012578f32a
@ -5,6 +5,7 @@
|
|||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
|
||||||
|
|
||||||
module GEval.Core
|
module GEval.Core
|
||||||
( geval,
|
( geval,
|
||||||
gevalCore,
|
gevalCore,
|
||||||
@ -88,7 +89,7 @@ defaultLogLossHashedSize = 10
|
|||||||
-- | evaluation metric
|
-- | evaluation metric
|
||||||
data Metric = RMSE | MSE | BLEU | Accuracy | ClippEU | FMeasure Double | NMI
|
data Metric = RMSE | MSE | BLEU | Accuracy | ClippEU | FMeasure Double | NMI
|
||||||
| LogLossHashed Word32 | CharMatch | MAP | LogLoss | Likelihood
|
| LogLossHashed Word32 | CharMatch | MAP | LogLoss | Likelihood
|
||||||
| BIOF1 | BIOF1Labels | LikelihoodHashed Word32
|
| BIOF1 | BIOF1Labels | LikelihoodHashed Word32 | MAE
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
instance Show Metric where
|
instance Show Metric where
|
||||||
@ -117,6 +118,9 @@ instance Show Metric where
|
|||||||
show Likelihood = "Likelihood"
|
show Likelihood = "Likelihood"
|
||||||
show BIOF1 = "BIO-F1"
|
show BIOF1 = "BIO-F1"
|
||||||
show BIOF1Labels = "BIO-F1-Labels"
|
show BIOF1Labels = "BIO-F1-Labels"
|
||||||
|
show MAE = "MAE"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
instance Read Metric where
|
instance Read Metric where
|
||||||
readsPrec _ ('R':'M':'S':'E':theRest) = [(RMSE, theRest)]
|
readsPrec _ ('R':'M':'S':'E':theRest) = [(RMSE, theRest)]
|
||||||
@ -140,6 +144,7 @@ instance Read Metric where
|
|||||||
readsPrec _ ('M':'A':'P':theRest) = [(MAP, theRest)]
|
readsPrec _ ('M':'A':'P':theRest) = [(MAP, theRest)]
|
||||||
readsPrec _ ('B':'I':'O':'-':'F':'1':'-':'L':'a':'b':'e':'l':'s':theRest) = [(BIOF1Labels, theRest)]
|
readsPrec _ ('B':'I':'O':'-':'F':'1':'-':'L':'a':'b':'e':'l':'s':theRest) = [(BIOF1Labels, theRest)]
|
||||||
readsPrec _ ('B':'I':'O':'-':'F':'1':theRest) = [(BIOF1, theRest)]
|
readsPrec _ ('B':'I':'O':'-':'F':'1':theRest) = [(BIOF1, theRest)]
|
||||||
|
readsPrec _ ('M':'A':'E':theRest) = [(MAE, theRest)]
|
||||||
|
|
||||||
data MetricOrdering = TheLowerTheBetter | TheHigherTheBetter
|
data MetricOrdering = TheLowerTheBetter | TheHigherTheBetter
|
||||||
|
|
||||||
@ -160,6 +165,7 @@ getMetricOrdering LogLoss = TheLowerTheBetter
|
|||||||
getMetricOrdering Likelihood = TheHigherTheBetter
|
getMetricOrdering Likelihood = TheHigherTheBetter
|
||||||
getMetricOrdering BIOF1 = TheHigherTheBetter
|
getMetricOrdering BIOF1 = TheHigherTheBetter
|
||||||
getMetricOrdering BIOF1Labels = TheHigherTheBetter
|
getMetricOrdering BIOF1Labels = TheHigherTheBetter
|
||||||
|
getMetricOrdering MAE = TheLowerTheBetter
|
||||||
|
|
||||||
isInputNeeded :: Metric -> Bool
|
isInputNeeded :: Metric -> Bool
|
||||||
isInputNeeded CharMatch = True
|
isInputNeeded CharMatch = True
|
||||||
@ -403,9 +409,13 @@ gevalCore' :: (MonadIO m, MonadThrow m, MonadUnliftIO m) =>
|
|||||||
-> LineSource (ResourceT m) -- ^ source to read the expected output
|
-> LineSource (ResourceT m) -- ^ source to read the expected output
|
||||||
-> LineSource (ResourceT m) -- ^ source to read the output
|
-> LineSource (ResourceT m) -- ^ source to read the output
|
||||||
-> m (MetricValue) -- ^ metric values for the output against the expected output
|
-> m (MetricValue) -- ^ metric values for the output against the expected output
|
||||||
gevalCore' MSE _ = gevalCoreWithoutInput outParser outParser itemError averageC id
|
gevalCore' MSE _ = gevalCoreWithoutInput outParser outParser itemSquaredError averageC id
|
||||||
where outParser = getValue . TR.double
|
where outParser = getValue . TR.double
|
||||||
|
|
||||||
|
gevalCore' MAE _ = gevalCoreWithoutInput outParser outParser itemAbsoluteError averageC id
|
||||||
|
where outParser = getValue . TR.double
|
||||||
|
|
||||||
|
|
||||||
gevalCore' LogLoss _ = gevalCoreWithoutInput outParser outParser itemLogLossError averageC id
|
gevalCore' LogLoss _ = gevalCoreWithoutInput outParser outParser itemLogLossError averageC id
|
||||||
where outParser = getValue . TR.double
|
where outParser = getValue . TR.double
|
||||||
|
|
||||||
@ -660,8 +670,12 @@ items (LineSource lineSource _ _) parser =
|
|||||||
where toItem (Right x) = Got x
|
where toItem (Right x) = Got x
|
||||||
toItem (Left m) = Wrong m
|
toItem (Left m) = Wrong m
|
||||||
|
|
||||||
itemError :: (Double, Double) -> Double
|
itemAbsoluteError :: (Double, Double) -> Double
|
||||||
itemError (exp, out) = (exp-out)**2
|
itemAbsoluteError (exp, out) = abs (exp-out)
|
||||||
|
|
||||||
|
itemSquaredError :: (Double, Double) -> Double
|
||||||
|
itemSquaredError (exp, out) = (exp-out)**2
|
||||||
|
|
||||||
|
|
||||||
itemLogLossError :: (Double, Double) -> Double
|
itemLogLossError :: (Double, Double) -> Double
|
||||||
itemLogLossError (exp, out)
|
itemLogLossError (exp, out)
|
||||||
|
@ -51,6 +51,9 @@ main = hspec $ do
|
|||||||
describe "mean square error" $ do
|
describe "mean square error" $ do
|
||||||
it "simple test with arguments" $
|
it "simple test with arguments" $
|
||||||
runGEvalTest "mse-simple" `shouldReturnAlmost` 0.4166666666666667
|
runGEvalTest "mse-simple" `shouldReturnAlmost` 0.4166666666666667
|
||||||
|
describe "mean absolute error" $ do
|
||||||
|
it "simple test with arguments" $
|
||||||
|
runGEvalTest "mae-simple" `shouldReturnAlmost` 1.5
|
||||||
describe "BLEU" $ do
|
describe "BLEU" $ do
|
||||||
it "trivial example from Wikipedia" $
|
it "trivial example from Wikipedia" $
|
||||||
runGEvalTest "bleu-trivial" `shouldReturnAlmost` 0.0
|
runGEvalTest "bleu-trivial" `shouldReturnAlmost` 0.0
|
||||||
|
3
test/mae-simple/mae-simple-solution/test-A/out.tsv
Normal file
3
test/mae-simple/mae-simple-solution/test-A/out.tsv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
34.0
|
||||||
|
26.0
|
||||||
|
18.5
|
|
1
test/mae-simple/mae-simple/config.txt
Normal file
1
test/mae-simple/mae-simple/config.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
--metric MAE
|
3
test/mae-simple/mae-simple/test-A/expected.tsv
Normal file
3
test/mae-simple/mae-simple/test-A/expected.tsv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
30.0
|
||||||
|
26.5
|
||||||
|
18.5
|
|
Loading…
Reference in New Issue
Block a user