Add helper function for Gonito

This commit is contained in:
Filip Gralinski 2020-01-28 23:06:38 +01:00
parent 9198c38b1b
commit 15946b89db
2 changed files with 13 additions and 9 deletions

View File

@ -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

View File

@ -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