We use CFFI, so don't bother spec'ing. Additional suggestions for new API.
[CommonLispStat.git] / ls-demo.lisp
blob23f50ac38dc4fc35e12984c10cf5ca2a5ca04d91
1 ;; (asdf:operate 'asdf:compile-op 'cffi)
2 ;; (asdf:operate 'asdf:load-op 'cffi)
3 ;; (asdf:operate 'asdf:load-op 'rclg)
5 (load "/Users/ungil/lisp/CommonLispStat/init.lisp") ;;; To make it easier for Carlos...
7 (load "init.lisp")
8 (asdf:operate 'asdf:compile-op 'lispstat :force t)
9 (asdf:operate 'asdf:compile-op 'lispstat)
11 (asdf:oos 'asdf:load-op :lispstat)
13 (setf *my-base-directory*
14 #p"/home/tony/sandbox/CLS.git/"
15 #p"/Users/ungil/lisp/CommonLispStat/"
19 (in-package :cl-user)
21 ;; Can we get from both the subpackage as well as the "basic
22 ;; configuration"?
24 (lisp-stat:binomial-quant 0.95 3 0.4) ;;; 3
25 (lisp-stat:binomial-quant 0 3 0.4) ;;; 0
27 (lisp-stat:normal-rand 20) ;;; DOESN'T RETURN
29 (in-package :ls-user)
31 (binomial-quant 0.95 3 0.4) ; 3
32 (binomial-quant 0 3 0.4) ; 0
33 (normal-rand 20)
36 (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))
40 ;; 5.000000000000003)
42 (lu-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
43 ;; (#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)
45 (lu-solve
46 (lu-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
47 #(2 3 4))
48 ;; #(-2.333333333333333 1.3333333333333335 0.6666666666666666)
50 (lisp-stat-linalg:inverse #2A((2 3 4) (1 2 4) (2 4 5)))
51 ;; #2A((2.0 -0.33333333333333326 -1.3333333333333335)
52 ;; (-1.0 -0.6666666666666666 1.3333333333333333)
53 ;; (0.0 0.6666666666666666 -0.3333333333333333))
55 (lisp-stat-linalg:sv-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
56 ;; (#2A((-0.5536537653489974 0.34181191712789266 -0.7593629708013371)
57 ;; (-0.4653437312661058 -0.8832095891230851 -0.05827549615722014)
58 ;; (-0.6905959164998124 0.3211003503429828 0.6480523475178517))
59 ;; #(9.699290438141343 0.8971681569301373 0.3447525123483081)
60 ;; #2A((-0.30454218417339873 0.49334669582252344 -0.8147779426198863)
61 ;; (-0.5520024849987308 0.6057035911404464 0.5730762743603965)
62 ;; (-0.7762392122368734 -0.6242853493399995 -0.08786630745236332))
63 ;; T)
65 (lisp-stat-linalg:qr-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
66 ;; (#2A((-0.6666666666666665 0.7453559924999298 5.551115123125783e-17)
67 ;; (-0.3333333333333333 -0.2981423969999719 -0.894427190999916)
68 ;; (-0.6666666666666666 -0.5962847939999439 0.44721359549995787))
69 ;; #2A((-3.0 -5.333333333333334 -7.333333333333332)
70 ;; (0.0 -0.7453559924999292 -1.1925695879998877)
71 ;; (0.0 0.0 -1.3416407864998738)))
73 (lisp-stat-linalg:rcondest #2A((2 3 4) (1 2 4) (2 4 5)))
74 ;; 6.8157451e7
76 (lisp-stat-linalg:eigen #2A((2 3 4) (1 2 4) (2 4 5)))
77 ;; (#(10.656854249492381 -0.6568542494923802 -0.9999999999999996)
78 ;; (#(0.4999999999999998 0.4999999999999997 0.7071067811865475)
79 ;; #(-0.49999999999999856 -0.5000000000000011 0.7071067811865474)
80 ;; #(0.7071067811865483 -0.7071067811865466 -1.2560739669470215e-15))
81 ;; NIL)
83 (lisp-stat-linalg:spline #(1.0 1.2 1.3 1.8 2.1 2.5)
84 #(1.2 2.0 2.1 2.0 1.1 2.8) :xvals 6)
85 ;; ((1.0 1.3 1.6 1.9 2.2 2.5)
86 ;; (1.2 2.1 2.2750696543866313 1.6465231041904045 1.2186576148879609 2.8))
88 ;;; using KERNEL-SMOOTH-FRONT, not KERNEL-SMOOTH-CPORT
89 (lisp-stat-linalg:kernel-smooth #(1.0 1.2 1.3 1.8 2.1 2.5)
90 #(1.2 2.0 2.1 2.0 1.1 2.8) :xvals 5)
91 ;; ((1.0 1.375 1.75 2.125 2.5)
92 ;; (1.6603277642110226 1.9471748095239771 1.7938127405752287
93 ;; 1.5871511322219498 2.518194783156392))
95 (lisp-stat-linalg:kernel-dens #(1.0 1.2 2.5 2.1 1.8 1.2) :xvals 5)
96 ;; ((1.0 1.375 1.75 2.125 2.5)
97 ;; (0.7224150453621405 0.5820045548233707 0.38216411702854214
98 ;; 0.4829822708587095 0.3485939156929503))
100 (lisp-stat-linalg:fft #(1.0 1.2 2.5 2.1 1.8))
101 ;; #(#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))
103 (lisp-stat-descriptive-statistics:lowess
104 #(1.0 1.2 2.5 2.1 1.8 1.2) #(1.2 2.0 2.1 2.0 1.1 2.8))
105 ;; (#(1.0 1.2 1.2 1.8 2.1 2.5))
109 ;;; Log-gamma function
111 (log-gamma 3.4) ;;1.0923280596789584
113 ;;; Probability functions
115 ;;; looking at these a bit more, perhaps a more CLOSy style is needed, i.e.
116 ;;; (quantile :list-or-cons loc :type type (one of 'empirical 'normal 'cauchy, etc...))
117 ;;; similar for the cdf, density, and rand.
118 ;;; Probably worth figuring out how to add a new distribution
119 ;;; efficiently, i.e. by keeping some kind of list.
121 ;;; Normal distribution
123 (normal-quant 0.95) ;;1.6448536279366268
124 (normal-cdf 1.3) ;;0.9031995154143897
125 (normal-dens 1.3) ;;0.17136859204780736
126 (normal-rand 2) ;;(-0.40502015f0 -0.8091404f0)
128 (bivnorm-cdf 0.2 0.4 0.6) ;;0.4736873734160288
130 ;;; Cauchy distribution
132 (cauchy-quant 0.95) ;;6.313751514675031
133 (cauchy-cdf 1.3) ;;0.7912855998398473
134 (cauchy-dens 1.3) ;;0.1183308127104695
135 (cauchy-rand 2) ;;(-1.06224644160405 -0.4524695943939537)
137 ;;; Gamma distribution
139 (gamma-quant 0.95 4.3) ;;8.178692439291645
140 (gamma-cdf 1.3 4.3) ;;0.028895150986674906
141 (gamma-dens 1.3 4.3) ;;0.0731517686447374
142 (gamma-rand 2 4.3) ;;(2.454918912880936 4.081365384357454)
144 ;;; Chi-square distribution
146 (chisq-quant 0.95 3) ;;7.814727903379012
147 (chisq-cdf 1 5) ;;0.03743422675631789
148 (chisq-dens 1 5) ;;0.08065690818083521
149 (chisq-rand 2 4) ;;(1.968535826180572 2.9988646156942997)
151 ;;; Beta distribution
153 (beta-quant 0.95 3 2) ;;0.9023885371149876
154 (beta-cdf 0.4 2 2.4) ;;0.4247997418541529
155 (beta-dens 0.4 2 2.4) ;;1.5964741858913518
156 (beta-rand 2 2 2.4) ;;(0.8014897077282279 0.6516371997922659)
158 ;;; t distribution
160 (t-quant 0.95 3) ;;2.35336343484194
161 (t-cdf 1 2.3) ;;0.794733624298342
162 (t-dens 1 2.3) ;;0.1978163816318102
163 (t-rand 2 2.3) ;;(-0.34303672776089306 -1.142505872436518)
165 ;;; F distribution
167 (f-quant 0.95 3 5) ;;5.409451318117459
168 (f-cdf 1 3.2 5.4) ;;0.5347130905510765
169 (f-dens 1 3.2 5.4) ;;0.37551128864591415
170 (f-rand 2 3 2) ;;(0.7939093442091963 0.07442694152491144)
172 ;;; Poisson distribution
174 (poisson-quant 0.95 3.2) ;;6
175 (poisson-cdf 1 3.2) ;;0.17120125672252395
176 (poisson-pmf 1 3.2) ;;0.13043905274097067
177 (poisson-rand 5 3.2) ;;(2 1 2 0 3)
179 ;;; Binomial distribution
181 (binomial-quant 0.95 3 0.4) ;;; DOESN'T RETURN
182 (binomial-quant 0 3 0.4) ;;; -2147483648
183 (binomial-cdf 1 3 0.4) ;;0.6479999999965776
184 (binomial-pmf 1 3 0.4) ;;0.4320000000226171
185 (binomial-rand 5 3 0.4) ;;(2 2 0 1 2)