Commit 8265ea59c0a955a1916c4e751f1b503510082a14
- Date: Sun Feb 24 04:21:05 +0000 2008
- Committer: Leonardo Varuzza (varuzza@gmail.com)
- Author: Leonardo Varuzza (varuzza@gmail.com)
- Commit SHA1: 8265ea59c0a955a1916c4e751f1b503510082a14
- Tree SHA1: 80e3e1939326b14a4e3e88e3dba4a73e31e631e2
Add chi-square distribution.
Commit diff
| |   |
| 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 |
--- /dev/null
+++ b/chisq.lisp
@@ -0,0 +1,24 @@
+(in-package :randist)
+
+(declaim (optimize (speed 3) (debug 0) (safety 1)))
+
+;; /* The chisq distribution has the form
+
+;; p(x) dx = (1/(2*Gamma(nu/2))) (x/2)^(nu/2 - 1) exp(-x/2) dx
+
+;; for x = 0 ... +infty */
+
+;; double
+;; gsl_ran_chisq (const gsl_rng * r, const double nu)
+;; {
+;; double chisq = 2 * gsl_ran_gamma (r, nu / 2, 1.0);
+;; return chisq;
+;; }
+
+
+(declaim (ftype (function (double-float) double-float) random-chi-square)
+ (inline random-chi-square))
+
+(defun random-chi-square (nu)
+ (declare (type double-float nu))
+ (* 2d0 (random-gamma (/ nu 2d0)))) |
| |   |
| 22 | 22 | (:file "exponential") |
| 23 | 23 | (:file "f") |
| 24 | 24 | (:file "pareto") |
| 25 | (:file "chisq") |
| 25 | 26 | (:file "cut-point") |
| 26 | 27 | (:file "desc-stat") |
| 27 | 28 | (:file "tests"))) |
| toggle raw diff |
--- a/cl-randist.asd
+++ b/cl-randist.asd
@@ -22,6 +22,7 @@
(:file "exponential")
(:file "f")
(:file "pareto")
+ (:file "chisq")
(:file "cut-point")
(:file "desc-stat")
(:file "tests"))) |
| |   |
| 23 | 23 | random-multinomial |
| 24 | 24 | random-f |
| 25 | 25 | random-pareto |
| 26 | |
| 27 | ;;random-logistic (untested) |
| 28 | |
| 29 | random-chi-square |
| 30 | |
| 26 | 31 | ;; Alias method for discrete distributions |
| 27 | 32 | make-discrete-random-var)) |
| toggle raw diff |
--- a/packages.lisp
+++ b/packages.lisp
@@ -23,5 +23,10 @@
random-multinomial
random-f
random-pareto
+
+ ;;random-logistic (untested)
+
+ random-chi-square
+
;; Alias method for discrete distributions
make-discrete-random-var)) |