moved all unittests into same package,
[CommonLispStat.git] / src / packages.lisp
blob1c52ebb52ec0f2602442fd216f61814af6b3f1cb
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2008-11-03 08:26:37 tony>
4 ;;; Creation: <2008-03-11 19:18:34 user>
5 ;;; File: packages.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2007--2008, AJ Rossini. BSD, LLGPL, or GPLv2, depending
8 ;;; on how it arrives.
9 ;;; Purpose: package structure description for lispstat
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
15 ;;; This organization and structure is new to the 21st Century
16 ;;; version.
18 (in-package :cl-user)
20 ;;; LispStat Basics
22 (in-package :cl-user)
24 (defpackage :lisp-stat-object-system
25 (:nicknames :ls-objects :lsos)
26 (:use :common-lisp)
27 (:shadow :call-method :call-next-method :slot-value)
28 (:export ls-object objectp *object* kind-of-p make-object
29 *message-hook*
30 *set-slot-hook* slot-value self
31 send call-next-method call-method
32 defmeth defproto instance-slots proto-name))
38 (defpackage :lisp-stat-types
39 (:documentation "Provides some typeing for LispStat, but is clearly
40 a bit incomplete.")
41 (:use :common-lisp)
42 (:export fixnump
43 check-nonneg-fixnum check-one-nonneg-fixnum
44 check-one-fixnum check-one-real check-one-number))
47 ;;; Package Setup
49 (in-package :cl-user)
51 (defpackage :lisp-stat-float
52 (:use :common-lisp)
53 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
54 machine-epsilon base-float makedouble
56 make-base-trans-fun-2 make-base-trans-fun
58 base-log base-exp base-expt base-sqrt base-sin base-cos
59 base-tan base-asin base-acos base-atan base-sinh
60 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
61 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
62 BASE-FROUND BASE-SIGNUM BASE-CIS))
65 (defpackage :lisp-stat-compound-data
66 (:use :common-lisp
67 :lisp-stat-object-system
68 :lisp-stat-types)
69 (:shadowing-import-from :lisp-stat-object-system
70 slot-value
71 call-next-method call-method)
72 (:export compound-data-p *compound-data-proto*
73 compound-object-p
74 compound-data-seq compound-data-length
75 element-list element-seq
76 sort-data order rank
77 recursive-map-elements map-elements repeat
78 check-sequence
79 get-next-element make-next-element set-next-element
80 sequencep iseq ordered-nneg-seq
81 select split-list which
82 difference rseq
83 flatten-list ))
85 (defpackage :lisp-stat-macros
86 (:use :common-lisp
87 :lisp-stat-compound-data)
88 (:export make-rv-function make-rv-function-1))
90 (defpackage :lisp-stat-basics
91 (:use :common-lisp
92 :lisp-stat-object-system
93 :lisp-stat-types
94 :lisp-stat-float
95 :lisp-stat-macros
96 :lisp-stat-compound-data)
97 (:shadowing-import-from :lisp-stat-object-system
98 slot-value call-method call-next-method)
99 (:export permute-array sum prod count-elements mean
100 if-else sample))
107 (defpackage :lisp-stat-float
108 (:use :common-lisp)
109 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
110 machine-epsilon base-float makedouble
112 make-base-trans-fun-2 make-base-trans-fun
114 BASE-LOG BASE-EXP BASE-EXPT BASE-SQRT BASE-SIN BASE-COS
115 BASE-TAN BASE-ASIN BASE-ACOS BASE-ATAN BASE-SINH
116 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
117 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
118 BASE-FROUND BASE-SIGNUM BASE-CIS))
120 ;;;
122 (defpackage :lisp-stat-macros
123 (:use :common-lisp
124 :lisp-stat-compound-data)
125 (:export make-rv-function make-rv-function-1))
127 ;;; NEW CLOS STRUCTURE
129 (defpackage :lisp-stat-data-clos
130 (:use :common-lisp
131 :lisp-matrix)
132 (:export get-variable-matrix get-variable-vector
133 ;; generic container class for data -- if small enough
134 ;; could be value, otherwise might be reference.
135 data-pointer))
137 (defpackage :lisp-stat-regression-linear-clos
138 (:use :common-lisp
139 :lisp-matrix
140 :lisp-stat-data-clos)
141 (:export regression-model))
145 ;;; USER PACKAGES
147 (defpackage :lisp-stat-ffi-int
148 (:use :common-lisp
149 :cffi)
150 (:export ccl-store-integer ccl-store-double ccl-store-ptr
151 get-buf ))
153 (defpackage :lisp-stat-probability
154 (:use :common-lisp
155 :cffi
156 :lisp-stat-ffi-int
157 :lisp-stat-macros)
158 (:export log-gamma set-seed
159 uniform-rand
160 normal-cdf normal-quant normal-dens normal-rand
161 bivnorm-cdf
162 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
163 gamma-cdf gamma-quant gamma-dens gamma-rand
164 chisq-cdf chisq-quant chisq-dens chisq-rand
165 beta-cdf beta-quant beta-dens beta-rand
166 t-cdf t-quant t-dens t-rand
167 f-cdf f-quant f-dens f-rand
168 poisson-cdf poisson-quant poisson-pmf poisson-rand
169 binomial-cdf binomial-quant binomial-pmf binomial-rand))
173 (defpackage :lisp-stat-matrix
174 (:use :common-lisp
175 :cffi
176 :lisp-stat-compound-data)
177 (:export matrixp ;; matrix -- conflicts!
178 num-rows num-cols matmult identity-matrix diagonal
179 row-list column-list inner-product outer-product
180 cross-product transpose bind-columns bind-rows
181 array-data-vector vector-to-array
183 check-matrix check-square-matrix
185 copy-array copy-vector
188 (defpackage :lisp-stat-linalg-data
189 (:use :common-lisp
190 :cffi
191 :lisp-stat-ffi-int
192 :lisp-stat-types
193 :lisp-stat-compound-data
194 :lisp-stat-matrix)
195 (:export ;; more to add
196 +mode-in+ +mode-re+ +mode-cx+ mode-of
198 la-data-mode la-allocate la-free
200 la-get-double la-put-double
201 la-put-integer
203 la-matrix la-free-matrix la-matrix-to-data la-data-to-matrix
204 la-vector la-free-vector la-vector-to-data la-data-to-vector ))
207 (defpackage :lisp-stat-math
208 (:use :common-lisp
209 :lisp-stat-object-system
210 :lisp-stat-macros
211 :lisp-stat-compound-data
212 :lisp-stat-float)
213 (:shadowing-import-from :lisp-stat-object-system
214 slot-value call-method call-next-method)
215 (:shadow expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
216 asin acos atan sinh cosh tanh asinh acosh atanh float random
217 truncate floor ceiling round minusp zerop plusp evenp oddp
218 < <= = /= >= > ;; complex
219 conjugate realpart imagpart phase
220 min max logand logior logxor lognot ffloor fceiling
221 ftruncate fround signum cis)
222 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
223 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
224 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
225 /= >= > ;; complex
226 conjugate realpart imagpart phase min max
227 logand logior logxor lognot ffloor fceiling ftruncate fround
228 signum cis)
229 (:documentation "Vectorization of numerical functions"))
232 (defpackage :lisp-stat-linalg
233 (:use :common-lisp
234 :cffi
235 :lisp-stat-ffi-int
236 :lisp-stat-math
237 :lisp-stat-types
238 :lisp-stat-float
239 :lisp-stat-compound-data
240 :lisp-stat-linalg-data
241 :lisp-stat-matrix)
242 (:shadowing-import-from :lisp-stat-math
243 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
244 asin acos atan sinh cosh tanh asinh acosh atanh float random
245 truncate floor ceiling round minusp zerop plusp evenp oddp
246 < <= = /= >= > complex conjugate realpart imagpart phase
247 min max logand logior logxor lognot ffloor fceiling
248 ftruncate fround signum cis)
249 (:export chol-decomp lu-decomp lu-solve determinant inverse
250 sv-decomp qr-decomp rcondest make-rotation spline
251 kernel-dens kernel-smooth
252 fft make-sweep-matrix sweep-operator ax+y eigen
254 check-real ;; for optimize
256 covariance-matrix matrix print-matrix solve
257 backsolve eigenvalues eigenvectors accumulate cumsum combine
258 lowess))
261 (defpackage :lisp-stat-config
262 (:use :common-lisp)
263 (:export *default-path*
264 *lsos-files* *basic-files* *ls-files*
265 *lispstat-data-dir* *lispstat-examples-dir*))
268 (defpackage :lisp-stat-data
269 (:documentation "Data management, integration, I/O, and other data technologies.")
270 (:nicknames :ls-data)
271 (:use :common-lisp
272 :lisp-stat-object-system
273 :lisp-stat-config
274 :lisp-stat-types
275 :lisp-stat-compound-data)
276 (:shadowing-import-from :lisp-stat-object-system
277 slot-value call-method call-next-method)
278 (:export open-file-dialog read-data-file read-data-columns load-data
279 load-example *variables* *ask-on-redefine*
280 def variables savevar undef))
282 (defpackage :lisp-stat-descriptive-statistics
283 (:use :common-lisp
284 :lisp-stat-data
285 :lisp-stat-math
286 :lisp-stat-compound-data
287 :lisp-stat-matrix
288 :lisp-stat-linalg-data
289 :lisp-stat-linalg
290 :lisp-stat-basics)
291 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
292 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
293 asin acos atan sinh cosh tanh asinh acosh atanh float random
294 truncate floor ceiling round minusp zerop plusp evenp oddp
295 < <= = /= >= > ;; complex
296 conjugate realpart imagpart phase
297 min max logand logior logxor lognot ffloor fceiling
298 ftruncate fround signum cis)
299 (:export standard-deviation quantile median interquartile-range
300 fivnum sample))
303 (defpackage :lisp-stat-regression-linear
304 (:use :common-lisp
305 :lisp-stat-object-system
306 :lisp-stat-basics
307 :lisp-stat-compound-data
308 :lisp-stat-math
309 :lisp-stat-matrix
310 :lisp-stat-linalg
311 :lisp-stat-descriptive-statistics)
312 (:shadowing-import-from :lisp-stat-object-system
313 slot-value call-method call-next-method)
314 (:shadowing-import-from :lisp-stat-math
315 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
316 asin acos atan sinh cosh tanh asinh acosh atanh float random
317 truncate floor ceiling round minusp zerop plusp evenp oddp
318 < <= = /= >= > ;; complex
319 conjugate realpart imagpart phase
320 min max logand logior logxor lognot ffloor fceiling
321 ftruncate fround signum cis)
322 (:export regression-model regression-model-proto x y intercept sweep-matrix
323 basis weights included total-sum-of-squares residual-sum-of-squares
324 predictor-names response-name case-labels))
327 (defpackage :lisp-stat
328 (:documentation "Experimentation package for LispStat. Serious work
329 should be packaged up elsewhere for reproducibility.")
330 (:use :common-lisp
331 :lisp-stat-object-system
332 :lisp-stat-compound-data
333 :lisp-stat-probability
334 :lisp-stat-types
335 :lisp-stat-float
336 :lisp-stat-basics
337 :lisp-stat-data
338 :lisp-stat-math
339 :lisp-stat-matrix
340 :lisp-stat-linalg
341 :lisp-stat-descriptive-statistics
342 :lisp-stat-regression-linear)
343 (:shadowing-import-from :lisp-stat-object-system
344 slot-value call-method call-next-method)
345 (:shadowing-import-from :lisp-stat-math
346 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
347 asin acos atan sinh cosh tanh asinh acosh atanh float random
348 truncate floor ceiling round minusp zerop plusp evenp oddp
349 < <= = /= >= > ;;complex
350 conjugate realpart imagpart phase
351 min max logand logior logxor lognot ffloor fceiling
352 ftruncate fround signum cis)
353 (:export
354 ;; lsobjects :
355 defproto defproto2
356 defmeth send
358 ;; lstypes :
359 fixnump check-nonneg-fixnum check-one-fixnum
360 check-one-real check-one-number
362 ;; lsmacros:
364 ;; lsfloat :
365 machine-epsilon
367 ;; compound :
368 compound-data-p *compound-data-proto* compound-object-p
369 compound-data-seq compound-data-length
370 element-list element-seq
371 sort-data order rank
372 recursive-map-elements map-elements
373 repeat
374 check-sequence
375 get-next-element make-next-element set-next-element
376 sequencep iseq
377 ordered-nneg-seq
378 select which
379 difference rseq
381 ;; lsmath.lsp
382 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
383 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
384 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
385 /= >= > ;; complex
386 conjugate realpart imagpart phase min max
387 logand logior logxor lognot ffloor fceiling ftruncate fround
388 signum cis
390 ;; matrices.lisp
391 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
392 column-list inner-product outer-product cross-product transpose
393 bind-columns bind-rows
395 ;; linalg.lisp
396 chol-decomp lu-decomp lu-solve determinant inverse
397 sv-decomp qr-decomp rcondest make-rotation spline
398 kernel-dens kernel-smooth
399 fft make-sweep-matrix sweep-operator ax+y eigen
400 check-real
401 covariance-matrix matrix print-matrix solve
402 backsolve eigenvalues eigenvectors accumulate cumsum combine
403 lowess
405 ;; in linalg.lisp, possibly not supported by matlisp
406 spline kernel-dens kernel-smooth
408 ;; optimize.lsp
409 newtonmax nelmeadmax
411 ;; lispstat-macros
412 make-rv-function make-rv-function-1
414 ;; data.lisp
415 open-file-dialog read-data-file read-data-columns load-data
416 load-example *variables* *ask-on-redefine*
417 def variables savevar undef
419 ;; statistics.lsp
420 standard-deviation quantile median interquartile-range
421 fivnum sample
423 ;; dists
424 log-gamma set-seed
425 uniform-rand normal-cdf normal-quant normal-dens
426 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
427 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
428 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
429 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
430 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
431 binomial-cdf binomial-quant binomial-pmf binomial-rand
433 ;;; Here is where we have a problem -- lispstat core should be core
434 ;;; data management and config problems, with packages providing
435 ;;; specialized extensions to LispStat, i.e. regression, nonlin
436 ;;; regression, bayesian regression via laplace approximation, etc.
438 ;;; The following could be considered "recommended packages", similar
439 ;;; to the idea of the recommended packages in R.
441 ;; regression.lsp
442 regression-model regression-model-proto x y intercept sweep-matrix
443 basis weights included total-sum-of-squares residual-sum-of-squares
444 predictor-names response-name case-labels
446 ;; nonlin.lsp
447 nreg-model nreg-model-proto mean-function theta-hat epsilon
448 count-limit verbose
450 ;; bayes.lsp
451 bayes-model bayes-model-proto bayes-internals))
454 (defpackage :lisp-stat-data-examples
455 (:documentation "Example data used for unittests and illustrations,")
456 (:use :common-lisp
457 :lisp-stat)
458 (:shadowing-import-from :lisp-stat
459 slot-value call-method call-next-method
461 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
462 asin acos atan sinh cosh tanh asinh acosh atanh float random
463 truncate floor ceiling round minusp zerop plusp evenp oddp
464 < <= = /= >= > > ;; complex
465 conjugate realpart imagpart phase
466 min max logand logior logxor lognot ffloor fceiling
467 ftruncate fround signum cis
469 <= float imagpart)
470 (:export iron aluminum diabetes ))
473 (defpackage :lisp-stat-user
474 (:documentation "Experimentation package for LispStat.
475 Serious work should be placed in a similar package elsewhere for
476 reproducibility. But this should hint as to what needs to be
477 done for a user- or analysis-package.")
478 (:nicknames :ls-user)
479 (:use :common-lisp
480 :lisp-stat
481 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
482 (:shadowing-import-from :lisp-stat
483 slot-value call-method call-next-method
485 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
486 asin acos atan sinh cosh tanh asinh acosh atanh float random
487 truncate floor ceiling round minusp zerop plusp evenp oddp
488 < <= = /= >= > > ;; complex
489 conjugate realpart imagpart phase
490 min max logand logior logxor lognot ffloor fceiling
491 ftruncate fround signum cis
493 <= float imagpart))
497 ;;;
499 (defpackage :lisp-stat-unittests
500 (:use :common-lisp :lift :lisp-stat)
501 (:shadowing-import-from :lisp-stat
502 slot-value call-method call-next-method ;; objects
503 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
504 asin acos atan sinh cosh tanh asinh acosh atanh float random
505 truncate floor ceiling round minusp zerop plusp evenp oddp
506 < <= = /= >= > ;; complex
507 conjugate realpart imagpart phase
508 min max logand logior logxor lognot ffloor fceiling
509 ftruncate fround signum cis)
510 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
511 almost= almost=lists numerical=)) ; compare
514 (defpackage :lisp-stat-data-clos-example
515 (:use :common-lisp
516 :lift :lisp-stat-unittests
517 :lisp-stat-data-clos))