Skip to content
Browse files

Describe how shlould cumulative be evaluated at infinities

  • Loading branch information...
1 parent 5d7e5ee commit b662c32b1d9d4492107aabe08f2a48390f3fe9f9 @Shimuuar Shimuuar committed
Showing with 18 additions and 2 deletions.
  1. +6 −2 Statistics/Distribution.hs
  2. +12 −0 tests/Tests/Distribution.hs
View
8 Statistics/Distribution.hs
@@ -43,7 +43,11 @@ import System.Random.MWC
class Distribution d where
-- | Cumulative distribution function. The probability that a
-- random variable /X/ is less or equal than /x/,
- -- i.e. P(/X/≤/x/).
+ -- i.e. P(/X/≤/x/). Cumulative should be defined for
+ -- infinities as well:
+ --
+ -- > cumulative d +∞ = 1
+ -- > cumulative d -∞ = 0
cumulative :: d -> Double -> Double
-- | One's complement of cumulative distibution:
@@ -53,7 +57,7 @@ class Distribution d where
-- It's useful when one is interested in P(/X/≥/x/) and
-- expression on the right side begin to lose precision. This
-- function have default implementation but implementors are
- -- encouraged to provide more precise implementation
+ -- encouraged to provide more precise implementation.
complCumulative :: d -> Double -> Double
complCumulative d x = 1 - cumulative d x
View
12 tests/Tests/Distribution.hs
@@ -90,6 +90,8 @@ cdfTests t =
[ testProperty "C.D.F. sanity" $ cdfSanityCheck t
, testProperty "CDF limit at +∞" $ cdfLimitAtPosInfinity t
, testProperty "CDF limit at -∞" $ cdfLimitAtNegInfinity t
+ , testProperty "CDF at +∞ = 1" $ cdfAtPosInfinity t
+ , testProperty "CDF at -∞ = 1" $ cdfAtNegInfinity t
, testProperty "CDF is nondecreasing" $ cdfIsNondecreasing t
, testProperty "1-CDF is correct" $ cdfComplementIsCorrect t
]
@@ -104,6 +106,16 @@ cdfSanityCheck _ d x = c >= 0 && c <= 1
cdfIsNondecreasing :: (Distribution d) => T d -> d -> Double -> Double -> Bool
cdfIsNondecreasing _ d = monotonicallyIncreasesIEEE $ cumulative d
+-- cumulative d +∞ = 1
+cdfAtPosInfinity :: (Param d, Distribution d) => T d -> d -> Bool
+cdfAtPosInfinity _ d
+ = cumulative d (1/0) == 1
+
+-- cumulative d - ∞ = 0
+cdfAtNegInfinity :: (Param d, Distribution d) => T d -> d -> Bool
+cdfAtNegInfinity _ d
+ = cumulative d (-1/0) == 0
+
-- CDF limit at +∞ is 1
cdfLimitAtPosInfinity :: (Param d, Distribution d) => T d -> d -> Property
cdfLimitAtPosInfinity _ d =

0 comments on commit b662c32

Please sign in to comment.
Something went wrong with that request. Please try again.