File: Shifted.hs

package info (click to toggle)
bali-phy 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,392 kB
  • sloc: cpp: 120,442; xml: 13,966; haskell: 9,975; python: 2,936; yacc: 1,328; perl: 1,169; lex: 912; sh: 343; makefile: 26
file content (26 lines) | stat: -rw-r--r-- 1,093 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Probability.Distribution.Shifted where

import Probability.Random

data Shifted d = Shifted d (Result d)

instance (Dist d, Num (Result d)) => Dist (Shifted d) where
    type Result (Shifted d) = Result d
    dist_name (Shifted dist _) = "shifted " ++ dist_name dist

instance (IOSampleable d, Num (Result d)) => IOSampleable (Shifted d) where
    sampleIO (Shifted dist delta) = (+ delta) <$> sampleIO dist

instance (HasPdf d, Num (Result d)) => HasPdf (Shifted d) where
    pdf (Shifted dist delta) x = pdf dist (x - delta)

instance (Dist1D d, Result (Shifted d) ~ Double) => Dist1D (Shifted d) where
    cdf (Shifted dist delta) x = cdf dist (x - delta)
    lower_bound (Shifted dist delta) = fmap (+ delta) (lower_bound dist)
    upper_bound (Shifted dist delta) = fmap (+ delta) (upper_bound dist)

instance (ContDist1D d, Result (Shifted d) ~ Double) => ContDist1D (Shifted d) where
    quantile (Shifted dist delta) p = quantile dist p + delta

instance (Sampleable d, Num (Result d)) => Sampleable (Shifted d) where
    sample (Shifted dist delta) = (+ delta) <$> sample dist