cleaned up examples in prep for lisp-matrix integration
[CommonLispStat.git] / src / packages.lisp
blob1834cac32a74cef575c0bad51d0b07c601f5ad88
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2008-12-03 07:49:59 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
81 iseq ordered-nneg-seq
82 select split-list which
83 difference rseq
84 flatten-list ))
86 (defpackage :lisp-stat-macros
87 (:use :common-lisp
88 :lisp-stat-compound-data)
89 (:export make-rv-function make-rv-function-1))
91 (defpackage :lisp-stat-basics
92 (:use :common-lisp
93 :lisp-stat-object-system
94 :lisp-stat-types
95 :lisp-stat-float
96 :lisp-stat-macros
97 :lisp-stat-compound-data)
98 (:shadowing-import-from :lisp-stat-object-system
99 slot-value call-method call-next-method)
100 (:export permute-array sum prod count-elements mean
101 if-else sample))
105 (defpackage :lisp-stat-float
106 (:use :common-lisp)
107 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
108 machine-epsilon base-float makedouble
110 make-base-trans-fun-2 make-base-trans-fun
112 BASE-LOG BASE-EXP BASE-EXPT BASE-SQRT BASE-SIN BASE-COS
113 BASE-TAN BASE-ASIN BASE-ACOS BASE-ATAN BASE-SINH
114 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
115 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
116 BASE-FROUND BASE-SIGNUM BASE-CIS))
118 ;;;
120 (defpackage :lisp-stat-macros
121 (:use :common-lisp
122 :lisp-stat-compound-data)
123 (:export make-rv-function make-rv-function-1))
125 ;;; NEW CLOS STRUCTURE
127 (defpackage :lisp-stat-data-clos
128 (:use :common-lisp
129 :lisp-matrix)
130 (:export get-variable-matrix get-variable-vector
131 ;; generic container class for data -- if small enough
132 ;; could be value, otherwise might be reference.
133 data-pointer))
136 (defpackage :lisp-stat-regression-linear-clos
137 (:use :common-lisp
138 :lisp-matrix
139 :lisp-stat-data-clos)
140 (:export regression-model))
144 ;;; USER PACKAGES
146 (defpackage :lisp-stat-ffi-int
147 (:use :common-lisp
148 :cffi)
149 (:export ccl-store-integer ccl-store-double ccl-store-ptr
150 get-buf ))
152 (defpackage :lisp-stat-probability
153 (:use :common-lisp
154 :cffi
155 :lisp-stat-ffi-int
156 :lisp-stat-macros)
157 (:export log-gamma set-seed
158 uniform-rand
159 normal-cdf normal-quant normal-dens normal-rand
160 bivnorm-cdf
161 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
162 gamma-cdf gamma-quant gamma-dens gamma-rand
163 chisq-cdf chisq-quant chisq-dens chisq-rand
164 beta-cdf beta-quant beta-dens beta-rand
165 t-cdf t-quant t-dens t-rand
166 f-cdf f-quant f-dens f-rand
167 poisson-cdf poisson-quant poisson-pmf poisson-rand
168 binomial-cdf binomial-quant binomial-pmf binomial-rand))
172 (defpackage :lisp-stat-matrix
173 (:use :common-lisp
174 :cffi
175 :lisp-stat-compound-data)
176 (:export matrixp ;; matrix -- conflicts!
177 num-rows num-cols matmult identity-matrix diagonal
178 row-list column-list inner-product outer-product
179 cross-product transpose bind-columns bind-rows
180 array-data-vector vector-to-array
182 check-matrix check-square-matrix
184 copy-array copy-vector
187 (defpackage :lisp-stat-linalg-data
188 (:use :common-lisp
189 :cffi
190 :lisp-stat-ffi-int
191 :lisp-stat-types
192 :lisp-stat-compound-data
193 :lisp-stat-matrix)
194 (:export ;; more to add
195 +mode-in+ +mode-re+ +mode-cx+ mode-of
197 la-data-mode la-allocate la-free
199 la-get-double la-put-double
200 la-put-integer
202 la-matrix la-free-matrix la-matrix-to-data la-data-to-matrix
203 la-vector la-free-vector la-vector-to-data la-data-to-vector ))
206 (defpackage :lisp-stat-math
207 (:use :common-lisp
208 :lisp-stat-object-system
209 :lisp-stat-macros
210 :lisp-stat-compound-data
211 :lisp-stat-float)
212 (:shadowing-import-from :lisp-stat-object-system
213 slot-value call-method call-next-method)
214 (:shadow expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
215 asin acos atan sinh cosh tanh asinh acosh atanh float random
216 truncate floor ceiling round minusp zerop plusp evenp oddp
217 < <= = /= >= > ;; complex
218 conjugate realpart imagpart phase
219 min max logand logior logxor lognot ffloor fceiling
220 ftruncate fround signum cis)
221 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
222 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
223 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
224 /= >= > ;; complex
225 conjugate realpart imagpart phase min max
226 logand logior logxor lognot ffloor fceiling ftruncate fround
227 signum cis)
228 (:documentation "Vectorization of numerical functions"))
231 (defpackage :lisp-stat-linalg
232 (:use :common-lisp
233 :cffi
234 :lisp-stat-ffi-int
235 :lisp-stat-math
236 :lisp-stat-types
237 :lisp-stat-float
238 :lisp-stat-compound-data
239 :lisp-stat-linalg-data
240 :lisp-stat-matrix)
241 (:shadowing-import-from :lisp-stat-math
242 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
243 asin acos atan sinh cosh tanh asinh acosh atanh float random
244 truncate floor ceiling round minusp zerop plusp evenp oddp
245 < <= = /= >= > complex conjugate realpart imagpart phase
246 min max logand logior logxor lognot ffloor fceiling
247 ftruncate fround signum cis)
248 (:export chol-decomp lu-decomp lu-solve determinant inverse
249 sv-decomp qr-decomp rcondest make-rotation spline
250 kernel-dens kernel-smooth
251 fft make-sweep-matrix sweep-operator ax+y eigen
253 check-real ;; for optimize
255 covariance-matrix matrix print-matrix solve
256 backsolve eigenvalues eigenvectors accumulate cumsum combine
257 lowess))
262 (defpackage :lisp-stat-data
263 (:documentation "Data management, integration, I/O, and other data technologies.")
264 (:nicknames :ls-data)
265 (:use :common-lisp
266 :lisp-stat-object-system
267 :lisp-stat-config
268 :lisp-stat-types
269 :lisp-stat-compound-data)
270 (:shadowing-import-from :lisp-stat-object-system
271 slot-value call-method call-next-method)
272 (:export open-file-dialog read-data-file read-data-columns load-data
273 load-example *variables* *ask-on-redefine*
274 def variables savevar undef))
276 (defpackage :lisp-stat-descriptive-statistics
277 (:use :common-lisp
278 :lisp-stat-data
279 :lisp-stat-math
280 :lisp-stat-compound-data
281 :lisp-matrix
282 :lisp-stat-basics)
283 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
284 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
285 asin acos atan sinh cosh tanh asinh acosh atanh float random
286 truncate floor ceiling round minusp zerop plusp evenp oddp
287 < <= = /= >= > ;; complex
288 conjugate realpart imagpart phase
289 min max logand logior logxor lognot ffloor fceiling
290 ftruncate fround signum cis)
291 (:export standard-deviation quantile median interquartile-range
292 fivnum sample))
295 (defpackage :lisp-stat-regression-linear
296 (:use :common-lisp
297 :lisp-stat-object-system
298 :lisp-stat-basics
299 :lisp-stat-compound-data
300 :lisp-stat-math
301 :lisp-matrix
302 :lisp-stat-descriptive-statistics)
303 (:shadowing-import-from :lisp-stat-object-system
304 slot-value call-method call-next-method)
305 (:shadowing-import-from :lisp-stat-math
306 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
307 asin acos atan sinh cosh tanh asinh acosh atanh float random
308 truncate floor ceiling round minusp zerop plusp evenp oddp
309 < <= = /= >= > ;; complex
310 conjugate realpart imagpart phase
311 min max logand logior logxor lognot ffloor fceiling
312 ftruncate fround signum cis)
313 (:export regression-model regression-model-proto x y intercept sweep-matrix
314 basis weights included total-sum-of-squares residual-sum-of-squares
315 predictor-names response-name case-labels))
317 (defpackage :lisp-stat
318 (:documentation "Experimentation package for LispStat. Serious
319 work should be packaged up elsewhere for reproducibility. By this
320 I mean, creating a data/analytics/analysis package with the
321 minimal set of objects required.")
322 (:use :common-lisp
323 :lisp-stat-object-system
324 :lisp-stat-compound-data
325 :lisp-stat-probability
326 :lisp-stat-types
327 :lisp-stat-float
328 :lisp-stat-basics
329 :lisp-stat-data
330 :lisp-stat-math
331 :lisp-matrix ;; conversion to a more robust linalg approach
332 :lisp-stat-descriptive-statistics
333 :lisp-stat-regression-linear)
334 (:shadowing-import-from :lisp-stat-object-system
335 slot-value call-method call-next-method)
336 (:shadowing-import-from :lisp-stat-math
337 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
338 asin acos atan sinh cosh tanh asinh acosh atanh float random
339 truncate floor ceiling round minusp zerop plusp evenp oddp
340 < <= = /= >= >
341 ;;complex
342 conjugate realpart imagpart phase
344 min max
345 logand logior logxor lognot
346 ffloor fceiling ftruncate fround
347 signum cis)
348 (:export
349 ;; lsobjects :
350 defproto defproto2
351 defmeth send
353 ;; lstypes :
354 fixnump check-nonneg-fixnum check-one-fixnum
355 check-one-real check-one-number
357 ;; lsmacros:
359 ;; lsfloat :
360 machine-epsilon
362 ;; compound :
363 compound-data-p *compound-data-proto* compound-object-p
364 compound-data-seq compound-data-length
365 element-list element-seq
366 sort-data order rank
367 recursive-map-elements map-elements
368 repeat
369 check-sequence
370 get-next-element make-next-element set-next-element
371 ;; sequencep
372 iseq
373 ordered-nneg-seq
374 select which
375 difference rseq
377 ;; lsmath.lsp
378 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
379 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
380 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
381 /= >= > ;; complex
382 conjugate realpart imagpart phase min max
383 logand logior logxor lognot ffloor fceiling ftruncate fround
384 signum cis
387 ;; The following need to be re-found in lisp-matrix...
388 ;; matrices.lisp
389 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
390 column-list inner-product outer-product cross-product transpose
391 bind-columns bind-rows
393 ;; linalg.lisp
394 chol-decomp lu-decomp lu-solve determinant inverse
395 sv-decomp qr-decomp rcondest make-rotation spline
396 kernel-dens kernel-smooth
397 fft make-sweep-matrix sweep-operator ax+y eigen
398 check-real
399 covariance-matrix matrix print-matrix solve
400 backsolve eigenvalues eigenvectors accumulate cumsum combine
401 lowess
403 ;; in linalg.lisp, possibly not supported by matlisp
404 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 (descriptions, should probably be moved
420 ;; later...?
421 standard-deviation quantile median interquartile-range
422 fivnum sample
424 ;; probability (dists.lisp)
425 log-gamma set-seed
426 uniform-rand normal-cdf normal-quant normal-dens
427 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
428 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
429 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
430 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
431 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
432 binomial-cdf binomial-quant binomial-pmf binomial-rand
434 ;; Here is where we have a problem -- lispstat core should be core
435 ;; data management and config problems, with packages providing
436 ;; specialized extensions to LispStat, i.e. regression, nonlin
437 ;; regression, bayesian regression via laplace approximation, etc.
439 ;; The following could be considered "recommended packages",
440 ;; similar to the idea of the recommended packages in R. Probably
441 ;; we want them to do the exporting within that package, therefore
442 ;; NOT being able to lock the "data-ish" package, but only the
443 ;; subpackages prior to export.
445 ;; regression.lsp
446 regression-model regression-model-proto x y intercept sweep-matrix
447 basis weights included total-sum-of-squares residual-sum-of-squares
448 predictor-names response-name case-labels
450 ;; nonlin.lsp
451 nreg-model nreg-model-proto mean-function theta-hat epsilon
452 count-limit verbose
454 ;; bayes.lsp
455 bayes-model bayes-model-proto bayes-internals))
458 ;;;; PACKAGES FOR USEABILITY
460 (defpackage :lisp-stat-data-examples
461 (:documentation "Example data for unittests, examples, illustrations,")
462 (:use :common-lisp
463 :lisp-stat)
464 (:shadowing-import-from :lisp-stat
465 slot-value call-method call-next-method
467 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
468 asin acos atan sinh cosh tanh asinh acosh atanh float random
469 truncate floor ceiling round minusp zerop plusp evenp oddp
470 < <= = /= >= > > ;; complex
471 conjugate realpart imagpart phase
472 min max logand logior logxor lognot ffloor fceiling
473 ftruncate fround signum cis
475 <= float imagpart)
476 (:export iron aluminum absorbtion
477 diabetes dlabs))
480 (defpackage :lisp-stat-user
481 (:documentation "Experimentation package for LispStat.
482 Serious work should be placed in a similar package elsewhere for
483 reproducibility. But this should hint as to what needs to be
484 done for a user- or analysis-package.")
485 (:nicknames :ls-user)
486 (:use :common-lisp
487 :lisp-matrix
488 :lisp-stat
489 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
490 (:shadowing-import-from :lisp-stat
491 slot-value call-method call-next-method
493 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
494 asin acos atan sinh cosh tanh asinh acosh atanh float random
495 truncate floor ceiling round minusp zerop plusp evenp oddp
496 < <= = /= >= > > ;; complex
497 conjugate realpart imagpart phase
498 min max logand logior logxor lognot ffloor fceiling
499 ftruncate fround signum cis
501 <= float imagpart))
503 (defpackage :lisp-stat-unittests
504 (:use :common-lisp :lift :lisp-stat :lisp-stat-data-examples)
505 (:shadowing-import-from :lisp-stat
506 slot-value call-method call-next-method ;; objects
507 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
508 asin acos atan sinh cosh tanh asinh acosh atanh float random
509 truncate floor ceiling round minusp zerop plusp evenp oddp
510 < <= = /= >= > ;; complex
511 conjugate realpart imagpart phase
512 min max logand logior logxor lognot ffloor fceiling
513 ftruncate fround signum cis)
514 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
515 almost= almost=lists numerical=)) ; compare
517 (defpackage :lisp-stat-data-clos-example
518 (:use :common-lisp
519 :lift :lisp-stat-unittests
520 :lisp-stat-data-examples
521 :lisp-stat-data-clos)
522 (:export absorbtion aluminum iron))