9.2 Distribution Types and Operations
syntax
(PDF In)
syntax
(Sample Out)
syntax
(CDF In)
syntax
(Inverse-CDF Out)
struct
(struct distribution (pdf sample))
pdf : (PDF In) sample : (Sample Out)
Examples: | ||||||||
|
struct
(struct ordered-dist distribution (cdf inv-cdf min max median))
cdf : (CDF In) inv-cdf : (Inverse-CDF Out) min : Out max : Out median : (Promise Out)
Similarly to distribution, the In type parameter is the data type an ordered distribution accepts as arguments to its pdf, and the Out type parameter is the data type an ordered distribution returns as random samples. Additionally, its cdf accepts values of type In, and its inverse cdf returns values of type Out.
Examples: | ||||
|
The median is stored in an ordered-dist to allow interval probabilities to be computed accurately. For example, for d = (normal-dist), whose median is 0.0, (real-dist-prob d -2.0 -1.0) is computed using lower-tail probabilities, and (real-dist-prob d 1.0 2.0) is computed using upper-tail probabilities.
syntax
Examples: | ||||
|
procedure
(sample d) → Out
d : (dist In Out) (sample d n) → (Listof Out) d : (dist In Out) n : Integer
Examples: | ||||
|
procedure
d : (ordered-dist In Out) v : In log? : Any = #f 1-p? : Any = #f
When log? is #f, cdf returns a probability; otherwise, it returns a log probability.
When 1-p? is #f, cdf returns a lower-tail probability or log probability (depending on log?); otherwise, it returns an upper-tail probability or log-probability.
procedure
(inv-cdf d p [log? 1-p?]) → Out
d : (ordered-dist In Out) p : Real log? : Any = #f 1-p? : Any = #f
When log? is #f, inv-cdf interprets p as a probability; otherwise, it interprets p as a log probability.
When 1-p? is #f, inv-cdf interprets p as a lower-tail probability or log probability (depending on log?); otherwise, it interprets p as an upper-tail probability or log probability.
procedure
(real-dist-prob d a b [log? 1-p?]) → Flonum
d : Real-Dist a : Real b : Real log? : Any = #f 1-p? : Any = #f
procedure
(real-dist-hpd-interval d p) → (Values Flonum Flonum)
d : Real-Dist p : Real
Examples: | |||||||||||||||
|