2 ;;; Copyright (c) 2007, by A.J. Rossini <blindglobe@gmail.com>
3 ;;; See COPYRIGHT file for any additional restrictions (BSD license).
4 ;;; Since 1991, ANSI was finally finished. Edited for ANSI Common Lisp.
8 ;;; This is semi-external to lispstat core packages. The dependency
9 ;;; should be that lispstat packages are dependencies for the unit
10 ;;; tests. However, where they will end up is still to be
13 (defpackage #:lisp-stat-unittests
14 (:use
:lift
:lisp-stat
)
15 (:export run-ls-tests run-ls-test scoreboard
))
17 (in-package #:lisp-stat-unittests
)
21 ;; optimization-related functions not tested
22 ;;(lisp-stat-optimize:numgrad
23 ;;(lisp-stat-optimize:numhess
24 ;;(lisp-stat-optimize::minfo-maximize
26 ;; the rest return reasonable values, except BINOMIAL-QUANT:
27 ;; (lisp-stat-basics:binomial-quant 0.95 3 0.4) ;;; DOESN'T RETURN
28 ;; (lisp-stat-basics:binomial-quant 0 3 0.4) ;;; -2147483648
31 (deftestsuite ls-lin-alg
() ())
34 cholesky-decomposition
36 (lisp-stat-linalg:chol-decomp
#2A
((2 3 4) (1 2 4) (2 4 5)))
37 (#2A
((1.7888543819998317
0.0 0.0)
38 (1.6770509831248424
0.11180339887498929 0.0)
39 (2.23606797749979
2.23606797749979 3.332000937312528e-8))
45 (lisp-stat-linalg:lu-decomp
#2A
((2 3 4) (1 2 4) (2 4 5)))
46 (#2A
((2.0
3.0 4.0) (1.0
1.0 1.0) (0.5
0.5 1.5)) #(0 2 2) -
1.0 NIL
)))
51 (lisp-stat-linalg:lu-solve
52 (lisp-stat-linalg:lu-decomp
53 #2A
((2 3 4) (1 2 4) (2 4 5)))
55 #(-2.333333333333333
1.3333333333333335 0.6666666666666666)))
61 (lisp-stat-linalg:inverse
#2A
((2 3 4) (1 2 4) (2 4 5)))
62 #2A
((2.0 -
0.33333333333333326 -
1.3333333333333335)
63 (-1.0 -
0.6666666666666666 1.3333333333333333)
64 (0.0
0.6666666666666666 -
0.3333333333333333))))
69 (lisp-stat-linalg:sv-decomp
#2A
((2 3 4) (1 2 4) (2 4 5)))
70 (#2A
((-0.5536537653489974
0.34181191712789266 -
0.7593629708013371)
71 (-0.4653437312661058 -
0.8832095891230851 -
0.05827549615722014)
72 (-0.6905959164998124
0.3211003503429828 0.6480523475178517))
73 #(9.699290438141343
0.8971681569301373 0.3447525123483081)
74 #2A
((-0.30454218417339873
0.49334669582252344 -
0.8147779426198863)
75 (-0.5520024849987308
0.6057035911404464 0.5730762743603965)
76 (-0.7762392122368734 -
0.6242853493399995 -
0.08786630745236332))
82 (lisp-stat-linalg:qr-decomp
#2A
((2 3 4) (1 2 4) (2 4 5)))
83 (#2A
((-0.6666666666666665
0.7453559924999298 5.551115123125783e-17)
84 (-0.3333333333333333 -
0.2981423969999719 -
0.894427190999916)
85 (-0.6666666666666666 -
0.5962847939999439 0.44721359549995787))
86 #2A
((-3.0 -
5.333333333333334 -
7.333333333333332)
87 (0.0 -
0.7453559924999292 -
1.1925695879998877)
88 (0.0
0.0 -
1.3416407864998738))) ))
93 (lisp-stat-linalg:rcondest
#2A
((2 3 4) (1 2 4) (2 4 5)))
99 (lisp-stat-linalg:eigen
#2A
((2 3 4) (1 2 4) (2 4 5)))
100 (#(10.656854249492381 -
0.6568542494923802 -
0.9999999999999996)
101 (#(0.4999999999999998
0.4999999999999997 0.7071067811865475)
102 #(-0.49999999999999856 -
0.5000000000000011 0.7071067811865474)
103 #(0.7071067811865483 -
0.7071067811865466 -
1.2560739669470215e-15))
106 (addtest (ls-lin-alg)
109 (lisp-stat-linalg:spline
110 #(1.0
1.2 1.3 1.8 2.1 2.5)
111 #(1.2
2.0 2.1 2.0 1.1 2.8)
113 ((1.0
1.3 1.6 1.9 2.2 2.5)
114 (1.2
2.1 2.2750696543866313 1.6465231041904045 1.2186576148879609 2.8))))
117 (addtest (ls-lin-alg)
120 ;; using KERNEL-SMOOTH-FRONT, not KERNEL-SMOOTH-CPORT
121 (lisp-stat-linalg:kernel-smooth
122 #(1.0
1.2 1.3 1.8 2.1 2.5)
123 #(1.2
2.0 2.1 2.0 1.1 2.8)
125 ((1.0
1.375 1.75 2.125 2.5)
126 (1.6603277642110226
1.9471748095239771 1.7938127405752287
127 1.5871511322219498 2.518194783156392))))
129 (addtest (ls-lin-alg)
132 (lisp-stat-linalg:kernel-dens
133 #(1.0
1.2 2.5 2.1 1.8 1.2)
135 ((1.0
1.375 1.75 2.125 2.5)
136 (0.7224150453621405
0.5820045548233707 0.38216411702854214
137 0.4829822708587095 0.3485939156929503)) ))
139 (addtest (ls-lin-alg)
142 (lisp-stat-linalg:fft
#(1.0
1.2 2.5 2.1 1.8))
143 #(#C
(1.0
0.0) #C
(1.2
0.0) #C
(2.5
0.0) #C
(2.1
0.0) #C
(1.8
0.0)) ))
145 (addtest (ls-lin-alg)
148 (lisp-stat-descriptive-statistics:lowess
149 #(1.0
1.2 2.5 2.1 1.8 1.2)
150 #(1.2
2.0 2.1 2.0 1.1 2.8))
151 (#(1.0
1.2 1.2 1.8 2.1 2.5))))
154 (deftestsuite ls-spec-fns
() ())
156 ;;;; Log-gamma function
158 (addtest (ls-spec-fns)
160 (lisp-stat-basics:log-gamma
3.4)
164 ;;; Probability distributions
166 ;; This macro should be generalized, but it's a good start now.
167 (defmacro ProbDistnTests
(prefixName
168 quant-params quant-answer
169 cdf-params cdf-answer
170 pmf-params pmf-answer
171 rand-params rand-answer
)
173 (deftestsuite ls-probdist-
,prefixName
(ls-probdistn)
175 (:documentation
"testing for ,testName distribution results")
177 (lisp-stat-basics:,testName-quant
,quant-params
) ,quant-answer
))
179 (lisp-stat-basics:,testName-cdf
,cdf-params
) ,cdf-answer
))
181 (lisp-stat-basics:,testName-pmf
,pmf-params
) ,pmf-answer
))
185 (lisp-stat-basics:,testName-rand
,rand-params
) ,rand-answer
)))))
187 ;;; Normal distribution
189 (deftestsuite ls-probdist-f
(ls-probdistn)
190 (:documentation
"testing for Gaussian distn results")
192 (lisp-stat-basics:normal-quant
0.95)
195 (lisp-stat-basics:normal-cdf
1.3)
198 (lisp-stat-basics:normal-dens
1.3)
199 0.17136859204780736))
201 (lisp-stat-basics:normal-rand
2)
202 (-0.40502015f0 -
0.8091404f0
)))
204 (lisp-stat-basics:bivnorm-cdf
0.2 0.4 0.6)
205 0.4736873734160288)))
207 ;;;; Cauchy distribution
209 (deftestsuite ls-probdist-cauchy
(ls-probdistn)
210 (:documentation
"testing for Cachy-distn results")
212 (lisp-stat-basics:cauchy-quant
0.95)
215 (lisp-stat-basics:cauchy-cdf
1.3)
218 (lisp-stat-basics:cauchy-dens
1.3)
219 0.1183308127104695 ))
221 (lisp-stat-basics:cauchy-rand
2)
222 (-1.06224644160405 -
0.4524695943939537))))
224 ;;;; Gamma distribution
226 (deftestsuite ls-probdist-gamma
(ls-probdistn)
227 (:documentation
"testing for gamma distn results")
229 (lisp-stat-basics:gamma-quant
0.95 4.3)
232 (lisp-stat-basics:gamma-cdf
1.3 4.3)
233 0.028895150986674906))
235 (lisp-stat-basics:gamma-dens
1.3 4.3)
238 (lisp-stat-basics:gamma-rand
2 4.3)
239 (2.454918912880936
4.081365384357454))))
241 ;;;; Chi-square distribution
243 (deftestsuite ls-probdist-chisq
(ls-probdistn)
245 (:documentation
"testing for Chi-square distn results")
247 (lisp-stat-basics:chisq-quant
0.95 3)
250 (lisp-stat-basics:chisq-cdf
1 5)
251 0.03743422675631789))
253 (lisp-stat-basics:chisq-dens
1 5)
254 0.08065690818083521))
258 (lisp-stat-basics:chisq-rand
2 4)
259 (1.968535826180572
2.9988646156942997)))))
261 ;;;; Beta distribution
263 (deftestsuite ls-probdist-beta
(ls-probdistn)
265 (:documentation
"testing for beta distn results")
267 (lisp-stat-basics:beta-quant
0.95 3 2)
270 (lisp-stat-basics:beta-cdf
0.4 2 2.4)
271 0.4247997418541529 ))
273 (lisp-stat-basics:beta-dens
0.4 2 2.4)
274 1.5964741858913518 ))
276 (lisp-stat-basics:beta-rand
2 2 2.4)
277 (0.8014897077282279
0.6516371997922659))))
281 (deftestsuite ls-probdist-t
(ls-probdistn)
282 (:documentation
"testing for t-distn results")
284 (lisp-stat-basics:t-quant
0.95 3)
287 (lisp-stat-basics:t-cdf
1 2.3)
290 (lisp-stat-basics:t-dens
1 2.3)
293 (lisp-stat-basics:t-rand
2 2.3)
294 (-0.34303672776089306 -
1.142505872436518))))
298 (deftestsuite ls-probdist-f
(ls-probdistn)
299 (:documentation
"testing for f-distn results")
301 (lisp-stat-basics:f-quant
0.95 3 5) 5.409451318117459))
303 (lisp-stat-basics:f-cdf
1 3.2 5.4)
306 (lisp-stat-basics:f-dens
1 3.2 5.4)
307 0.37551128864591415))
311 (lisp-stat-basics:f-rand
2 3 2)
312 (0.7939093442091963
0.07442694152491144)))))
314 ;;;; Poisson distribution
316 (deftestsuite ls-probdist-poisson
(ls-probdistn)
318 (:documentation
"testing for poisson distribution results")
320 (lisp-stat-basics:poisson-quant
0.95 3.2) 6))
322 (lisp-stat-basics:poisson-cdf
1 3.2)
323 0.17120125672252395))
325 (lisp-stat-basics:poisson-pmf
1 3.2)
326 0.13043905274097067))
330 (lisp-stat-basics:poisson-rand
5 3.2)
333 ;; Binomial distribution
335 (deftestsuite ls-probdist-binomial
(ls-probdistn)
337 (:documentation
"testing for binomial distribution results")
339 (lisp-stat-basics:binomial-quant
0.95 3 0.4) ;;; DOESN'T RETURN
342 (lisp-stat-basics:binomial-quant
0 3 0.4)
346 (lisp-stat-basics:binomial-cdf
1 3 0.4)
350 (lisp-stat-basics:binomial-pmf
1 3 0.4)
355 (lisp-stat-basics:binomial-rand
5 3 0.4)
359 ;;; External support for running tests