From 15946b89dbe9e0a491c66a5e49c28dfd00d7bcbf Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Tue, 28 Jan 2020 23:06:38 +0100 Subject: [PATCH] Add helper function for Gonito --- geval.cabal | 2 +- src/GEval/Formatting.hs | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/geval.cabal b/geval.cabal index 615790a..8d8ffe4 100644 --- a/geval.cabal +++ b/geval.cabal @@ -1,5 +1,5 @@ name: geval -version: 1.31.0.0 +version: 1.31.1.0 synopsis: Machine learning evaluation tools description: Please see README.md homepage: http://github.com/name/project diff --git a/src/GEval/Formatting.hs b/src/GEval/Formatting.hs index 62667ca..149c1b9 100644 --- a/src/GEval/Formatting.hs +++ b/src/GEval/Formatting.hs @@ -1,5 +1,5 @@ module GEval.Formatting - (formatTheResult, formatSimpleResult) + (formatTheResult, formatSimpleResult, formatTheResultWithErrorBounds) where import GEval.Common @@ -9,13 +9,17 @@ import Text.Printf formatTheResult :: Maybe Int -> MetricResult -> String formatTheResult mPrecision (SimpleRun val) = formatSimpleResult mPrecision val -formatTheResult mPrecision (BootstrapResampling vals) = (formatSimpleResult correctedPrecision pointEstimate) - ++ "±" - ++ (formatSimpleResult correctedPrecision errorBound) - where pointEstimate = (upperBound + lowerBound) / 2.0 - errorBound = (upperBound - lowerBound) / 2.0 - (lowerBound, upperBound) = getConfidenceBounds defaultConfidenceLevel vals - errorBoundMagnitude = (floor (logBase 10.0 errorBound)) - 1 +formatTheResult mPrecision (BootstrapResampling vals) = formatTheResultWithErrorBounds mPrecision pointEstimate (Just errorBound) + where pointEstimate = (upperBound + lowerBound) / 2.0 + errorBound = (upperBound - lowerBound) / 2.0 + (lowerBound, upperBound) = getConfidenceBounds defaultConfidenceLevel vals + +formatTheResultWithErrorBounds :: Maybe Int -> MetricValue -> Maybe MetricValue -> String +formatTheResultWithErrorBounds mPrecision pointEstimate Nothing = formatSimpleResult mPrecision pointEstimate +formatTheResultWithErrorBounds mPrecision pointEstimate (Just errorBound) = (formatSimpleResult correctedPrecision pointEstimate) + ++ "±" + ++ (formatSimpleResult correctedPrecision errorBound) + where errorBoundMagnitude = (floor (logBase 10.0 errorBound)) - 1 correctedPrecision = Just $ selectLowerPrecision (max (-errorBoundMagnitude) 0) mPrecision formatSimpleResult :: Maybe Int -> MetricValue -> String