clean up docstrings and coding style.
[CommonLispStat.git] / src / packages.lisp
bloba0186a14105cb41d83c4162c40abc4943eb327d4
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-07-18 12:58:33 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 (in-package :cl-user)
17 ;;; Basics
20 (defpackage :lisp-stat-object-system
21 (:nicknames :ls-objects :lsos)
22 (:use :common-lisp)
23 (:shadow :call-method :call-next-method)
24 (:export ls-object objectp *object* kind-of-p make-object
25 *message-hook*
26 *set-slot-hook* proto-slot-value self
27 send call-next-method call-method
28 defmeth defproto instance-slots proto-name))
30 ;;; -types and -float probably ought to be moved into a -numerics
31 ;;; package.
33 (defpackage :lisp-stat-types
34 (:documentation "Provides some typeing for LispStat, but is clearly
35 a bit incomplete.")
36 (:use :common-lisp)
37 (:export fixnump
38 check-nonneg-fixnum check-one-nonneg-fixnum
39 check-one-fixnum check-one-real check-one-number))
41 (defpackage :lisp-stat-float
42 (:use :common-lisp)
43 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
44 machine-epsilon base-float makedouble
46 make-base-trans-fun-2 make-base-trans-fun
48 base-log base-exp base-expt base-sqrt base-sin base-cos
49 base-tan base-asin base-acos base-atan base-sinh
50 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
51 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
52 BASE-FROUND BASE-SIGNUM BASE-CIS))
54 ;;; Probably should move into cls-data package.
56 (defpackage :lisp-stat-compound-data
57 (:use :common-lisp
58 :lisp-stat-object-system
59 :lisp-stat-types)
60 (:shadowing-import-from :lisp-stat-object-system
61 call-next-method call-method)
62 (:export compound-data-p *compound-data-proto*
63 compound-object-p
64 compound-data-seq compound-data-length
65 element-list element-seq
66 sort-data order rank
67 recursive-map-elements map-elements repeat
68 check-sequence
69 get-next-element make-next-element set-next-element
70 ;; sequencep
71 iseq ordered-nneg-seq
72 select split-list which
73 difference rseq
74 flatten-list))
76 (defpackage :lisp-stat-macros
77 (:use :common-lisp
78 :lisp-stat-compound-data)
79 (:export make-rv-function make-rv-function-1))
81 (defpackage :lisp-stat-basics
82 (:use :common-lisp
83 :lisp-stat-object-system
84 :lisp-stat-types
85 :lisp-stat-float
86 :lisp-stat-macros
87 :lisp-stat-compound-data)
88 (:shadowing-import-from :lisp-stat-object-system
89 call-method call-next-method)
90 (:export permute-array sum prod count-elements mean
91 if-else sample))
93 (defpackage :lisp-stat-float
94 (:use :common-lisp)
95 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
96 machine-epsilon base-float makedouble
98 make-base-trans-fun-2 make-base-trans-fun
100 BASE-LOG BASE-EXP BASE-EXPT BASE-SQRT BASE-SIN BASE-COS
101 BASE-TAN BASE-ASIN BASE-ACOS BASE-ATAN BASE-SINH
102 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
103 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
104 BASE-FROUND BASE-SIGNUM BASE-CIS))
106 (defpackage :lisp-stat-macros
107 (:use :common-lisp
108 :lisp-stat-compound-data)
109 (:export make-rv-function make-rv-function-1))
112 (defpackage :cls-matrix
113 (:documentation "basic utilities for using lisp arrays as numerical
114 matrices. Not optimized, and must consider this slow. Routines
115 should be optimized, it is only that we need them first, optimize
116 them later.")
117 (:use :common-lisp)
118 (:export matrixp num-rows num-cols matmult identity-matrix diagonal
119 row-list column-list inner-product outer-product
120 cross-product transpose bind-columns bind-rows
121 array-data-vector vector-to-array))
124 ;;; NEW CLOS STRUCTURE
126 ;;; cls-data... in dataframe, though.
127 (defpackage :cls-dataframe
128 (:use :common-lisp
129 :xarray
130 :lisp-matrix)
131 (:export
132 ;; generic container class for data -- if small enough
133 ;; could be value, otherwise might be reference.
134 dataframe-like
135 dataframe-array
136 make-dataframe
138 ;; accessors
139 varlabels caselabels nrows ncols
140 dataframe-dimension dataframe-dimensons
141 xref xtype xdims xdim xrank slice take carray
143 dfref dfref-case dfref-var
144 consistent-dataframe-p
147 dataset
148 list-of-columns ;; list-of-variables
149 list-of-rows ;; list-of-observations
152 ;; move to cls-data -- but in listoflist.lisp
153 (defpackage :cls-data-listoflist
154 (:use :common-lisp
155 :lisp-matrix
156 :cls-dataframe) ; for dataframe
157 (:export lists-of-same-size
158 equal-listoflist
159 transpose-listoflist
160 listoflist->dataframe
161 listoflist->array
162 listoflist->matrix-like))
165 (defpackage :cls-dataimport
166 (:documentation "Data I/O and similar import technologies.")
167 (:use :common-lisp
168 :lisp-stat-object-system
169 :cls-dataframe
170 :cls-data-listoflist
171 :rsm.string)
172 (:shadowing-import-from :lisp-stat-object-system
173 call-method call-next-method)
174 (:export dsvstream->dataframe dsvstream->matrix dsvstream->listoflist))
177 (defpackage :lisp-stat-model
178 (:documentation "Model management for data analysis.")
179 (:use :common-lisp
180 :lisp-matrix)
181 (:export
182 ;; data structures for model and model/data combination
183 model statistical-model analysis))
185 ;;; visualization
187 (defpackage :cls-visualize
188 (:use :common-lisp
189 :lisp-matrix
190 :cls-dataframe))
193 (defpackage :cls-visualize-plplot
194 (:use :common-lisp
195 :lisp-matrix
196 :cls-dataframe
197 :cl-plplot-system)
198 (:export
199 ;; examples
200 plot-ex contour-plot-ex fn-contour-plot-ex shade-plot-ex 3D-plot-ex))
203 ;;; USER PACKAGES
205 (defpackage :lisp-stat-ffi-int
206 (:use :common-lisp
207 :cffi)
208 (:export ccl-store-integer ccl-store-double ccl-store-ptr
209 get-buf ))
211 (defpackage :lisp-stat-probability
212 (:use :common-lisp
213 :cffi
214 :lisp-stat-ffi-int
215 :lisp-stat-macros)
216 (:export log-gamma set-seed
217 uniform-rand
218 normal-cdf normal-quant normal-dens normal-rand
219 bivnorm-cdf
220 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
221 gamma-cdf gamma-quant gamma-dens gamma-rand
222 chisq-cdf chisq-quant chisq-dens chisq-rand
223 beta-cdf beta-quant beta-dens beta-rand
224 t-cdf t-quant t-dens t-rand
225 f-cdf f-quant f-dens f-rand
226 poisson-cdf poisson-quant poisson-pmf poisson-rand
227 binomial-cdf binomial-quant binomial-pmf binomial-rand))
231 (defpackage :lisp-stat-math
232 (:use :common-lisp
233 :lisp-stat-object-system
234 :lisp-stat-macros
235 :lisp-stat-compound-data
236 :lisp-stat-float)
237 (:shadowing-import-from :lisp-stat-object-system
238 call-method call-next-method)
239 (:shadow expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
240 asin acos atan sinh cosh tanh asinh acosh atanh float random
241 truncate floor ceiling round minusp zerop plusp evenp oddp
242 < <= = /= >= > ;; complex
243 conjugate realpart imagpart phase
244 min max logand logior logxor lognot ffloor fceiling
245 ftruncate fround signum cis)
246 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
247 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
248 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
249 /= >= > ;; complex
250 conjugate realpart imagpart phase min max
251 logand logior logxor lognot ffloor fceiling ftruncate fround
252 signum cis)
253 (:documentation "Vectorization of numerical functions"))
256 #| ;; some of this goes back in, but not all of it?
257 (defpackage :lisp-stat-linalg
258 (:use :common-lisp
259 :cffi
260 :lisp-matrix
261 :lisp-stat-math
262 :lisp-stat-types
263 :lisp-stat-float
264 :lisp-stat-compound-data)
265 (:shadowing-import-from :lisp-stat-math
266 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
267 asin acos atan sinh cosh tanh asinh acosh atanh float random
268 truncate floor ceiling round minusp zerop plusp evenp oddp
269 < <= = /= >= > complex conjugate realpart imagpart phase
270 min max logand logior logxor lognot ffloor fceiling
271 ftruncate fround signum cis)
272 (:export chol-decomp lu-decomp lu-solve determinant inverse
273 sv-decomp qr-decomp rcondest make-rotation spline
274 kernel-dens kernel-smooth
275 fft make-sweep-matrix sweep-operator ax+y eigen
277 check-real ;; for optimize
279 covariance-matrix matrix print-matrix solve
280 backsolve eigenvalues eigenvectors accumulate cumsum combine
281 lowess))
288 (defpackage :lisp-stat-data
289 (:documentation "Data management, integration, I/O, and other data technologies.")
290 (:nicknames :ls-data)
291 (:use :common-lisp
292 :lisp-stat-object-system
293 :lisp-stat-config
294 :lisp-stat-types
295 :lisp-stat-compound-data)
296 (:shadowing-import-from :lisp-stat-object-system
297 call-method call-next-method)
298 (:export open-file-dialog read-data-file read-data-columns load-data
299 load-example *variables* *ask-on-redefine*
300 def variables savevar undef))
302 (defpackage :lisp-stat-descriptive-statistics
303 (:use :common-lisp
304 :lisp-matrix
305 :lisp-stat-data
306 :lisp-stat-math
307 :lisp-stat-compound-data
308 :lisp-stat-basics)
309 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
310 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
311 asin acos atan sinh cosh tanh asinh acosh atanh float random
312 truncate floor ceiling round minusp zerop plusp evenp oddp
313 < <= = /= >= > ;; complex
314 conjugate realpart imagpart phase
315 min max logand logior logxor lognot ffloor fceiling
316 ftruncate fround signum cis)
317 (:export mean standard-deviation variance
318 quantile median interquartile-range
319 fivnum sample))
321 (defpackage :lisp-stat-regression-linear
322 (:use :common-lisp
323 :lisp-matrix
324 :lisp-stat-basics
325 :lisp-stat-compound-data
326 :lisp-stat-descriptive-statistics )
327 (:shadowing-import-from :lisp-stat-object-system
328 call-method call-next-method)
329 (:export regression-model fit-model
331 estimates covariance-matrix
332 ;; functions for helpers
333 lm xtxinv
334 print-object ;; for method dispatch
337 (defpackage :common-lisp-statistics
338 (:documentation "Experimentation package for LispStat. Serious work
339 should be packaged up elsewhere for reproducibility. By this I
340 mean, creating a data/analytics/analysis package with the minimal
341 set of objects required.")
342 (:nicknames :cls :common-lisp-statistics :lisp-stat)
343 (:use :common-lisp
344 :lisp-stat-config
345 :lisp-stat-object-system
346 :lisp-stat-compound-data
347 :lisp-stat-probability
348 :lisp-stat-types
349 :lisp-stat-float
350 :lisp-stat-basics
351 :lisp-stat-data
352 :cls-dataframe
353 :cls-data-listoflist
354 :lisp-stat-math
355 :lisp-matrix ;; conversion to a more robust linalg approach
356 :lisp-stat-descriptive-statistics
357 :lisp-stat-regression-linear
358 ;; :cybertiggyr-dsv
359 :cls-visualize
360 ;; :cls-visualize-plplot
362 (:shadowing-import-from :lisp-stat-object-system
363 call-method call-next-method)
364 (:shadowing-import-from :lisp-stat-math
365 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
366 asin acos atan sinh cosh tanh asinh acosh atanh float random
367 truncate floor ceiling round minusp zerop plusp evenp oddp
368 < <= = /= >= >
369 ;;complex
370 conjugate realpart imagpart phase
372 min max
373 logand logior logxor lognot
374 ffloor fceiling ftruncate fround
375 signum cis)
376 (:export
377 ;; lisp-stat-config:
378 *default-path* *lsos-files* *basic-files* *ls-files*
379 *lispstat-home-dir* *lispstat-data-dir* *lispstat-examples-dir*
381 ;; lsobjects :
382 defproto defproto2
383 defmeth send proto-slot-value
385 ;; lstypes :
386 fixnump check-nonneg-fixnum check-one-fixnum
387 check-one-nonneg-fixnum
388 check-one-real check-one-number
390 ;; lsmacros:
392 ;; lsfloat :
393 machine-epsilon
395 ;; compound :
396 compound-data-p *compound-data-proto* compound-object-p
397 compound-data-seq compound-data-length
398 element-list element-seq
399 sort-data order rank
400 recursive-map-elements map-elements
401 repeat
402 check-sequence
403 get-next-element make-next-element set-next-element
404 ;; sequencep
405 iseq
406 ordered-nneg-seq
407 select which
408 difference rseq
410 ;; lsmath.lsp
411 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
412 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
413 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
414 /= >= > ;; complex
415 conjugate realpart imagpart phase min max
416 logand logior logxor lognot ffloor fceiling ftruncate fround
417 signum cis
419 #| ;; The following need to be re-found in lisp-matrix...
421 ;; matrices.lisp
422 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
423 column-list inner-product outer-product cross-product transpose
424 bind-columns bind-rows
426 ;; linalg.lisp
427 chol-decomp lu-decomp lu-solve determinant inverse
428 sv-decomp qr-decomp rcondest make-rotation spline
429 kernel-dens kernel-smooth
430 fft make-sweep-matrix sweep-operator ax+y eigen
431 check-real
432 covariance-matrix matrix print-matrix solve
433 backsolve eigenvalues eigenvectors accumulate cumsum combine
434 lowess
436 ;; in linalg.lisp, possibly not supported by matlisp
437 spline kernel-dens kernel-smooth
441 ;; optimize.lsp
442 newtonmax nelmeadmax
444 ;; lispstat-macros
445 make-rv-function make-rv-function-1
447 ;; xarray
448 xref xtype xdims xdim xdims*
450 ;; data
451 open-file-dialog read-data-file read-data-columns load-data
452 load-example *variables* *ask-on-redefine*
453 def variables savevar undef
455 ;; dataframe
456 dataframe-like dataframe-array make-dataframe
457 varlabels caselabels nrows ncols
458 dataframe-dimension dataframe-dimensons
459 dfref dfref-case dfref-var
460 consistent-dataframe-p
461 dataset list-of-columns list-of-rows
463 ;; listoflist
464 lists-of-same-size equal-listoflist
465 transpose-listoflist
466 listoflist->dataframe listoflist->array listoflist->matrix-like
468 ;; statistics.lsp (descriptions, should probably be moved
469 ;; later...?
470 standard-deviation quantile median interquartile-range
471 fivnum sample
473 ;; probability (dists.lisp)
474 log-gamma set-seed
475 uniform-rand normal-cdf normal-quant normal-dens
476 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
477 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
478 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
479 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
480 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
481 binomial-cdf binomial-quant binomial-pmf binomial-rand
483 ;; Here is where we have a problem -- lispstat core should be core
484 ;; data management and config problems, with packages providing
485 ;; specialized extensions to LispStat, i.e. regression, nonlin
486 ;; regression, bayesian regression via laplace approximation, etc.
488 ;; The following could be considered "recommended packages",
489 ;; similar to the idea of the recommended packages in R. Probably
490 ;; we want them to do the exporting within that package, therefore
491 ;; NOT being able to lock the "data-ish" package, but only the
492 ;; subpackages prior to export.
494 ;; regression.lsp
495 ;; -- linear regressin models.
496 regression-model fit-model
497 estimates covariance-matrix
499 regression-model-proto x y intercept sweep-matrix
500 basis weights included total-sum-of-squares residual-sum-of-squares
501 predictor-names response-name case-labels
502 lm xtxinv
504 ;; nonlin.lsp
505 ;; -- nonlinear regression models
506 nreg-model nreg-model-proto mean-function theta-hat epsilon
507 count-limit verbose
508 ;; we might need something like xtxinv here? But should be
509 ;; encapsulated, so we use the one in regression.lisp
511 ;; bayes.lsp
512 bayes-model bayes-model-proto bayes-internals
514 ;; plots.lisp
515 plot-ex
516 contour-plot-ex
517 fn-contour-plot-ex
518 shade-plot-ex
519 3D-plot-ex
524 ;;;; PACKAGES FOR USEABILITY
526 (defpackage :lisp-stat-data-examples
527 (:documentation "Example data for unittests, examples, illustrations,")
528 (:use :common-lisp
529 :common-lisp-statistics)
530 (:shadowing-import-from :lisp-stat
531 call-method call-next-method
533 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
534 asin acos atan sinh cosh tanh asinh acosh atanh float random
535 truncate floor ceiling round minusp zerop plusp evenp oddp
536 < <= = /= >= > > ;; complex
537 conjugate realpart imagpart phase
538 min max logand logior logxor lognot ffloor fceiling
539 ftruncate fround signum cis
541 <= float imagpart)
542 (:export iron aluminum absorbtion
543 diabetes dlabs))
546 (defpackage :lisp-stat-user
547 (:documentation "Experimentation package for LispStat. Serious work
548 should be placed in a similar package elsewhere for
549 reproducibility. But this should hint as to what needs to be done
550 for a user- or analysis-package.")
551 (:nicknames :ls-user)
552 (:use :common-lisp ; always needed for user playgrounds!
553 :lisp-matrix
554 :common-lisp-statistics
555 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
556 (:shadowing-import-from :lisp-stat
557 call-method call-next-method
559 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
560 asin acos atan sinh cosh tanh asinh acosh atanh float random
561 truncate floor ceiling round minusp zerop plusp evenp oddp
562 < <= = /= >= > > ;; complex
563 conjugate realpart imagpart phase
564 min max logand logior logxor lognot ffloor fceiling
565 ftruncate fround signum cis
567 <= float imagpart))
569 (defpackage :lisp-stat-unittests
570 (:use :common-lisp
571 :lift :lisp-matrix
572 :lisp-stat :lisp-stat-data-examples)
573 (:shadowing-import-from :lisp-stat
574 call-method call-next-method ;; objects
575 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
576 asin acos atan sinh cosh tanh asinh acosh atanh float random
577 truncate floor ceiling round minusp zerop plusp evenp oddp
578 < <= = /= >= > ;; complex
579 conjugate realpart imagpart phase
580 min max logand logior logxor lognot ffloor fceiling
581 ftruncate fround signum cis)
582 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
583 almost= almost=lists numerical=)) ; compare
585 (defpackage :cls-dataframe-example
586 (:use :common-lisp
587 :lift :lisp-stat-unittests
588 :lisp-stat-data-examples
589 :cls-dataframe)
590 (:export absorbtion aluminum iron))
593 (defpackage :lisp-stat-optimize
594 (:use :common-lisp
595 :cffi
596 :lisp-matrix
597 :lisp-stat-ffi-int
598 :lisp-stat-object-system
599 :lisp-stat-types
600 :lisp-stat-compound-data
601 :lisp-stat-math
602 :lisp-stat-float
603 :lisp-stat-basics
605 :lisp-stat-matrix
606 :lisp-stat-linalg-data
607 :lisp-stat-linalg
610 (:shadowing-import-from :lisp-stat-object-system
611 call-method call-next-method)
612 (:shadowing-import-from :lisp-stat-math
613 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
614 asin acos atan sinh cosh tanh asinh acosh atanh float random
615 truncate floor ceiling round minusp zerop plusp evenp oddp
616 < <= = /= >= > complex conjugate realpart imagpart phase
617 min max logand logior logxor lognot ffloor fceiling
618 ftruncate fround signum cis)
619 (:export
620 ;; derivatives
621 numgrad numhess
623 ;; optimization
624 newtonmax nelmeadmax))