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.
7 ;;; This is semi-external to lispstat core packages. The dependency
8 ;;; should be that lispstat packages are dependencies for the unit
9 ;;; tests. However, where they will end up is still to be
12 (in-package #:cl-user
)
15 (defpackage #:lispstat-tests
16 (:use
:lift
:lisp-stat
)
17 (:export run-ls-tests run-ls-test scoreboard
))
19 (in-package #:lispstat-tests
)
26 ;; optimization-related functions not tested
27 ;;(lisp-stat-optimize:numgrad
28 ;;(lisp-stat-optimize:numhess
29 ;;(lisp-stat-optimize::minfo-maximize
31 ;; the rest return reasonable values, except BINOMIAL-QUANT:
32 ;; (lisp-stat-basics:binomial-quant 0.95 3 0.4) ;;; DOESN'T RETURN
33 ;; (lisp-stat-basics:binomial-quant 0 3 0.4) ;;; -2147483648
36 (deftestsuite ls-lin-alg
() ())
40 (lisp-stat-linalg:chol-decomp
#2A
((2 3 4) (1 2 4) (2 4 5)))
41 (#2A
((1.7888543819998317
0.0 0.0)
42 (1.6770509831248424
0.11180339887498929 0.0)
43 (2.23606797749979
2.23606797749979 3.332000937312528e-8))
48 (lisp-stat-linalg:lu-decomp
#2A
((2 3 4) (1 2 4) (2 4 5)))
49 (#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
)))
53 (lisp-stat-linalg:lu-solve
54 (lisp-stat-linalg:lu-decomp
#2A
((2 3 4) (1 2 4) (2 4 5)))
56 #(-2.333333333333333
1.3333333333333335 0.6666666666666666)))
62 (lisp-stat-linalg:inverse
#2A
((2 3 4) (1 2 4) (2 4 5)))
63 #2A
((2.0 -
0.33333333333333326 -
1.3333333333333335)
64 (-1.0 -
0.6666666666666666 1.3333333333333333)
65 (0.0
0.6666666666666666 -
0.3333333333333333))))
70 (lisp-stat-linalg:sv-decomp
#2A
((2 3 4) (1 2 4) (2 4 5)))
71 (#2A
((-0.5536537653489974
0.34181191712789266 -
0.7593629708013371)
72 (-0.4653437312661058 -
0.8832095891230851 -
0.05827549615722014)
73 (-0.6905959164998124
0.3211003503429828 0.6480523475178517))
74 #(9.699290438141343
0.8971681569301373 0.3447525123483081)
75 #2A
((-0.30454218417339873
0.49334669582252344 -
0.8147779426198863)
76 (-0.5520024849987308
0.6057035911404464 0.5730762743603965)
77 (-0.7762392122368734 -
0.6242853493399995 -
0.08786630745236332))
84 (lisp-stat-linalg:qr-decomp
#2A
((2 3 4) (1 2 4) (2 4 5)))
85 (#2A
((-0.6666666666666665
0.7453559924999298 5.551115123125783e-17)
86 (-0.3333333333333333 -
0.2981423969999719 -
0.894427190999916)
87 (-0.6666666666666666 -
0.5962847939999439 0.44721359549995787))
88 #2A
((-3.0 -
5.333333333333334 -
7.333333333333332)
89 (0.0 -
0.7453559924999292 -
1.1925695879998877)
90 (0.0
0.0 -
1.3416407864998738))) ))
95 (lisp-stat-linalg:rcondest
#2A
((2 3 4) (1 2 4) (2 4 5)))
101 (lisp-stat-linalg:eigen
#2A
((2 3 4) (1 2 4) (2 4 5)))
102 (#(10.656854249492381 -
0.6568542494923802 -
0.9999999999999996)
103 (#(0.4999999999999998
0.4999999999999997 0.7071067811865475)
104 #(-0.49999999999999856 -
0.5000000000000011 0.7071067811865474)
105 #(0.7071067811865483 -
0.7071067811865466 -
1.2560739669470215e-15))
108 (addtest (ls-lin-alg)
111 (lisp-stat-linalg:spline
112 #(1.0
1.2 1.3 1.8 2.1 2.5)
113 #(1.2
2.0 2.1 2.0 1.1 2.8)
115 ((1.0
1.3 1.6 1.9 2.2 2.5)
116 (1.2
2.1 2.2750696543866313 1.6465231041904045 1.2186576148879609 2.8))
119 (addtest (ls-lin-alg)
122 ;; using KERNEL-SMOOTH-FRONT, not KERNEL-SMOOTH-CPORT
123 (lisp-stat-linalg:kernel-smooth
124 #(1.0
1.2 1.3 1.8 2.1 2.5)
125 #(1.2
2.0 2.1 2.0 1.1 2.8)
127 ((1.0
1.375 1.75 2.125 2.5)
128 (1.6603277642110226
1.9471748095239771 1.7938127405752287
129 1.5871511322219498 2.518194783156392)) ))
131 (addtest (ls-lin-alg)
134 (lisp-stat-linalg:kernel-dens
135 #(1.0
1.2 2.5 2.1 1.8 1.2)
137 ((1.0
1.375 1.75 2.125 2.5)
138 (0.7224150453621405
0.5820045548233707 0.38216411702854214
139 0.4829822708587095 0.3485939156929503)) ))
141 (addtest (ls-lin-alg)
144 (lisp-stat-linalg:fft
#(1.0
1.2 2.5 2.1 1.8))
145 #(#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)) ))
147 (deftestsuite ls-stat
() ())
151 (lisp-stat-descriptive-statistics:lowess
152 #(1.0
1.2 2.5 2.1 1.8 1.2)
153 #(1.2
2.0 2.1 2.0 1.1 2.8))
154 (#(1.0
1.2 1.2 1.8 2.1 2.5))))
156 ;;;; Log-gamma function
158 (addtest (ls-spec-fns)
160 (lisp-stat-basics:log-gamma
3.4)
165 (defmacro ProbDistnTests
(prefixName
166 quant-params quant-answer
167 cdf-params cdf-answer
168 pmf-params pmf-answer
169 rand-params rand-answer
)
171 (deftestsuite ls-probdist-
,prefixName
(ls-probdistn)
173 (:documentation
"testing for ,testName distribution results")
175 (lisp-stat-basics:,testName-quant
,quant-params
) ,quant-answer
))
177 (lisp-stat-basics:,testName-cdf
,cdf-params
) ,cdf-answer
))
179 (lisp-stat-basics:,testName-pmf
,pmf-params
) ,pmf-answer
))
183 (lisp-stat-basics:,testName-rand
,rand-params
) ,rand-answer
)))))
188 ;;;; Normal distribution
193 (addtest (ls-probdistn)
196 (lisp-stat-basics:normal-quant
0.95) ;;1.6448536279366268
197 (lisp-stat-basics:normal-cdf
1.3) ;;0.9031995154143897
198 (lisp-stat-basics:normal-dens
1.3) ;;0.17136859204780736
199 (lisp-stat-basics:normal-rand
2) ;;(-0.40502015f0 -0.8091404f0)
201 (lisp-stat-basics:bivnorm-cdf
0.2 0.4 0.6) ;;0.4736873734160288
203 ;;;; Cauchy distribution
205 (addtest (ls-probdistn)
208 (lisp-stat-basics:cauchy-quant
0.95) ;;6.313751514675031
209 (lisp-stat-basics:cauchy-cdf
1.3) ;;0.7912855998398473
210 (lisp-stat-basics:cauchy-dens
1.3) ;;0.1183308127104695
211 (lisp-stat-basics:cauchy-rand
2) ;;(-1.06224644160405 -0.4524695943939537)
213 ;;;; Gamma distribution
215 (addtest (ls-probdistn)
218 (lisp-stat-basics:gamma-quant
0.95 4.3) ;;8.178692439291645
219 (lisp-stat-basics:gamma-cdf
1.3 4.3) ;;0.028895150986674906
220 (lisp-stat-basics:gamma-dens
1.3 4.3) ;;0.0731517686447374
221 (lisp-stat-basics:gamma-rand
2 4.3) ;;(2.454918912880936 4.081365384357454)
223 ;;;; Chi-square distribution
225 (addtest (ls-probdistn)
228 (lisp-stat-basics:chisq-quant
0.95 3) ;;7.814727903379012
229 (lisp-stat-basics:chisq-cdf
1 5) ;;0.03743422675631789
230 (lisp-stat-basics:chisq-dens
1 5) ;;0.08065690818083521
231 (lisp-stat-basics:chisq-rand
2 4) ;;(1.968535826180572 2.9988646156942997)
233 ;;;; Beta distribution
235 (addtest (ls-probdistn)
238 (lisp-stat-basics:beta-quant
0.95 3 2) ;;0.9023885371149876
239 (lisp-stat-basics:beta-cdf
0.4 2 2.4) ;;0.4247997418541529
240 (lisp-stat-basics:beta-dens
0.4 2 2.4) ;;1.5964741858913518
241 (lisp-stat-basics:beta-rand
2 2 2.4) ;;(0.8014897077282279 0.6516371997922659)
245 (addtest (ls-probdistn)
249 (lisp-stat-basics:t-quant
0.95 3) ;;2.35336343484194
250 (lisp-stat-basics:t-cdf
1 2.3) ;;0.794733624298342
251 (lisp-stat-basics:t-dens
1 2.3) ;;0.1978163816318102
252 (lisp-stat-basics:t-rand
2 2.3) ;;(-0.34303672776089306 -1.142505872436518)
256 (addtest (ls-probdistn)
259 (lisp-stat-basics:f-quant
0.95 3 5) ;;5.409451318117459
260 (lisp-stat-basics:f-cdf
1 3.2 5.4) ;;0.5347130905510765
261 (lisp-stat-basics:f-dens
1 3.2 5.4) ;;0.37551128864591415
262 (lisp-stat-basics:f-rand
2 3 2) ;;(0.7939093442091963 0.07442694152491144)
264 ;;;; Poisson distribution
266 (deftestsuite ls-probdist-poisson
(ls-probdistn)
268 (:documentation
"testing for binomial distribution results")
270 (lisp-stat-basics:poisson-quant
0.95 3.2) 6))
272 (lisp-stat-basics:poisson-cdf
1 3.2)
273 0.17120125672252395))
275 (lisp-stat-basics:poisson-pmf
1 3.2)
276 0.13043905274097067))
280 (lisp-stat-basics:poisson-rand
5 3.2)
283 ;; Binomial distribution
285 (deftestsuite ls-probdist-binomial
(ls-probdistn)
287 (:documentation
"testing for binomial distribution results")
289 (lisp-stat-basics:binomial-quant
0.95 3 0.4) ;;; DOESN'T RETURN
292 (lisp-stat-basics:binomial-quant
0 3 0.4)
296 (lisp-stat-basics:binomial-cdf
1 3 0.4)
300 (lisp-stat-basics:binomial-pmf
1 3 0.4)
305 (lisp-stat-basics:binomial-rand
5 3 0.4)
309 ;;; External support for running tests