Commit 8265ea59c0a955a1916c4e751f1b503510082a14

Add chi-square distribution.

Commit diff

chisq.lisp

 
1(in-package :randist)
2
3(declaim (optimize (speed 3) (debug 0) (safety 1)))
4
5;; /* The chisq distribution has the form
6
7;; p(x) dx = (1/(2*Gamma(nu/2))) (x/2)^(nu/2 - 1) exp(-x/2) dx
8
9;; for x = 0 ... +infty */
10
11;; double
12;; gsl_ran_chisq (const gsl_rng * r, const double nu)
13;; {
14;; double chisq = 2 * gsl_ran_gamma (r, nu / 2, 1.0);
15;; return chisq;
16;; }
17
18
19(declaim (ftype (function (double-float) double-float) random-chi-square)
20 (inline random-chi-square))
21
22(defun random-chi-square (nu)
23 (declare (type double-float nu))
24 (* 2d0 (random-gamma (/ nu 2d0))))
toggle raw diff

cl-randist.asd

 
2222 (:file "exponential")
2323 (:file "f")
2424 (:file "pareto")
25 (:file "chisq")
2526 (:file "cut-point")
2627 (:file "desc-stat")
2728 (:file "tests")))
toggle raw diff

packages.lisp

 
2323 random-multinomial
2424 random-f
2525 random-pareto
26
27 ;;random-logistic (untested)
28
29 random-chi-square
30
2631 ;; Alias method for discrete distributions
2732 make-discrete-random-var))
toggle raw diff