From de40851b5a57710c6d62ee0766682f5a81685d07 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Tue, 19 Mar 2019 19:44:19 +0100 Subject: [PATCH] Fix corner cases in calibration --- src/Data/Statistics/Calibration.hs | 5 +++-- src/GEval/Core.hs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Data/Statistics/Calibration.hs b/src/Data/Statistics/Calibration.hs index 42ae3ab..76b353e 100644 --- a/src/Data/Statistics/Calibration.hs +++ b/src/Data/Statistics/Calibration.hs @@ -35,8 +35,9 @@ softCalibration _ [] = error "too few probabilities in calibration" softCalibration results probs | band probs < minBand = handleNarrowBand results probs | otherwise = 1.0 - (min 1.0 (2.0 * (integrate (lowest, highest) (\x -> abs ((loess (DVU.fromList probs) (DVU.fromList results) x) - x))) / (highest - lowest))) - where lowest = minimum probs - highest = maximum probs + where lowest = (minimum probs) + epsilon -- integrating loess gets crazy at edges + highest = (maximum probs) - epsilon + epsilon = 0.0001 handleNarrowBand :: [Double] -> [Double] -> Double handleNarrowBand results probs = 1.0 - deviation diff --git a/src/GEval/Core.hs b/src/GEval/Core.hs index 5008778..ab1d255 100644 --- a/src/GEval/Core.hs +++ b/src/GEval/Core.hs @@ -755,7 +755,7 @@ gevalCore' (ProbabilisticSoftFMeasure beta) _ = gevalCoreWithoutInput parseAnnot probabilisticSoftAgg = CC.foldl probabilisticSoftFolder ([], [], fromInteger 0, 0) probabilisticSoftFolder (r1, p1, g1, e1) (r2, p2, g2, e2) = (r1 ++ r2, p1 ++ p2, g1 + g2, e1 + e2) loessGraph :: ([Double], [Double], Double, Int) -> Maybe GraphSeries - loessGraph (results, probs, _, _) = Just $ GraphSeries $ Prelude.map (\x -> (x, loess probs' results' x)) $ Prelude.filter (\p -> p >= lowest && p <= highest) $ Prelude.map (\d -> 0.01 * (fromIntegral d)) [1..99] + loessGraph (results, probs, _, _) = Just $ GraphSeries $ Prelude.map (\x -> (x, loess probs' results' x)) $ Prelude.filter (\p -> p > lowest && p < highest) $ Prelude.map (\d -> 0.01 * (fromIntegral d)) [1..99] where results' = DVU.fromList results probs' = DVU.fromList probs lowest = Data.List.minimum probs