Skip to content

(under development) PIT Metric (Port of Jive) #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/scores/emerging/__scaffolding/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**CAUTION:** This is a highly volatile space for scaffolding code
56 changes: 56 additions & 0 deletions src/scores/emerging/__scaffolding/pit/pit.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env cabal
{- cabal:
build-depends:
base,
-}

import GHC.Float
import GHC.Float.RealFracMethods
import Debug.Trace

-- extents of a real space containing the domain (min, max)
-- e.g. for determining support of a function
newtype Extent = Extent (Float, Float) deriving (Show, Eq)

makeExtent :: Float -> Float -> Extent
makeExtent x y
| x <= y = Extent (x, y)
| otherwise = Extent (y, x)

-- parameters used for the underlying beta-distribution
-- https://en.wikipedia.org/wiki/Beta_distribution
data BetaParams = BetaParams
{ _betaA :: Rational,
_betaB :: Rational
}

gammaHalf :: Float
gammaHalf = 1.772

-- only takes values 1/2, 1, or positive integers
gammaFunc :: Rational -> Float
gammaFunc n
| n == (1 / 2) = gammaHalf
| n == 1 = 1
| n >= 2 =
int2Float $
product [1 .. float2Int (fromRational n - 1)]
| otherwise = error "Unsupported input"

-- probability distribution function for a beta distribution
-- Note: this is a crude approximation for testing only
betaPdf :: BetaParams -> Float -> Float
betaPdf (BetaParams _a _b) x = (n1 * n2) * d3 / (d1 * d2)
where
_f1 = map gammaFunc [_a, _b, _a + _b]
_f2 =
zipWith
(\n' p' -> n' `powerFloat` fromRat p')
[x, 1 - x]
[_a - 1, _b - 1]
[d1, d2, d3] = trace ("gammaOut: [d1, d2, d3] = " ++ show _f1) _f1
[n1, n2] = trace ("betaFunc: [n1, n2] = " ++ show _f2) _f2

main :: IO ()
main = do
print $ betaPdf (BetaParams (1/2) (1/2)) 0.01
1 change: 1 addition & 0 deletions src/scores/probability/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
crps_cdf_brier_decomposition,
crps_for_ensemble,
)
from scores.probability.pit import pit
from scores.probability.roc_impl import roc_curve_data
from scores.processing.isoreg_impl import isotonic_fit

Expand Down
Loading
Loading