closer to statistical use.
[CommonLispStat.git] / src / packages.lisp
blob4f34051afebacdf7e0de2eae705007e8d4da8269
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-10-30 08:17:46 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 ;;; Current structure, dependencies:
19 (progn
20 (ls-user :depends-on lisp-stat)
21 (lisp-stat :depends-on '(cls-dataframe
22 cls-data
23 lisp-matrix
25 (cls-dataframe :depends-on cls-data)
26 |#
30 ;;; Basics
33 (defpackage :lisp-stat-object-system
34 (:nicknames :ls-objects :lsos)
35 (:use :common-lisp)
36 (:shadow :call-method :call-next-method)
37 (:export ls-object objectp *object* kind-of-p make-object
38 *message-hook*
39 *set-slot-hook* proto-slot-value self
40 send call-next-method call-method
41 defmeth defproto instance-slots proto-name))
43 ;;; -types and -float probably ought to be moved into a -numerics
44 ;;; package.
46 (defpackage :lisp-stat-types
47 (:documentation "Provides some typeing for LispStat, but is clearly
48 a bit incomplete.")
49 (:use :common-lisp)
50 (:export fixnump
51 check-nonneg-fixnum check-one-nonneg-fixnum
52 check-one-fixnum check-one-real check-one-number))
54 (defpackage :lisp-stat-float
55 (:use :common-lisp)
56 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
57 machine-epsilon base-float makedouble
59 make-base-trans-fun-2 make-base-trans-fun
61 base-log base-exp base-expt base-sqrt base-sin base-cos
62 base-tan base-asin base-acos base-atan base-sinh
63 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
64 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
65 BASE-FROUND BASE-SIGNUM BASE-CIS))
67 ;;; Probably should move into cls-data package.
69 (defpackage :lisp-stat-compound-data
70 (:use :common-lisp
71 :lisp-stat-object-system
72 :lisp-stat-types)
73 (:shadowing-import-from :lisp-stat-object-system
74 call-next-method call-method)
75 (:export compound-data-p *compound-data-proto*
76 compound-object-p
77 compound-data-seq compound-data-length
78 element-list element-seq
79 sort-data order rank
80 recursive-map-elements map-elements repeat
81 check-sequence
82 get-next-element make-next-element set-next-element
83 ;; sequencep
84 iseq ordered-nneg-seq
85 select split-list which
86 difference rseq
87 flatten-list))
89 (defpackage :lisp-stat-macros
90 (:use :common-lisp
91 :lisp-stat-compound-data)
92 (:export make-rv-function make-rv-function-1))
94 (defpackage :lisp-stat-basics
95 (:use :common-lisp
96 :lisp-stat-object-system
97 :lisp-stat-types
98 :lisp-stat-float
99 :lisp-stat-macros
100 :lisp-stat-compound-data)
101 (:shadowing-import-from :lisp-stat-object-system
102 call-method call-next-method)
103 (:export permute-array sum prod count-elements mean
104 if-else sample))
106 (defpackage :lisp-stat-float
107 (:use :common-lisp)
108 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
109 machine-epsilon base-float makedouble
111 make-base-trans-fun-2 make-base-trans-fun
113 BASE-LOG BASE-EXP BASE-EXPT BASE-SQRT BASE-SIN BASE-COS
114 BASE-TAN BASE-ASIN BASE-ACOS BASE-ATAN BASE-SINH
115 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
116 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
117 BASE-FROUND BASE-SIGNUM BASE-CIS))
119 (defpackage :lisp-stat-macros
120 (:use :common-lisp
121 :lisp-stat-compound-data)
122 (:export make-rv-function make-rv-function-1))
125 (defpackage :cls-matrix
126 (:documentation "basic utilities for using lisp arrays as numerical
127 matrices. Not optimized, and must consider this slow. Routines
128 should be optimized, it is only that we need them first, optimize
129 them later.")
130 (:use :common-lisp)
131 (:export matrixp num-rows num-cols matmult identity-matrix diagonal
132 row-list column-list inner-product outer-product
133 cross-product transpose bind-columns bind-rows
134 array-data-vector vector-to-array))
137 ;;; NEW CLOS STRUCTURE
139 ;;; cls-data... in dataframe, though.
140 (defpackage :cls-dataframe
141 (:use :common-lisp
142 :xarray
143 :lisp-matrix)
144 (:shadowing-import-from :xarray slice)
145 (:export
146 ;; generic container class for data -- if small enough
147 ;; could be value, otherwise might be reference.
148 dataframe-like
149 dataframe-array
150 make-dataframe
152 ;; accessors
153 varlabels caselabels nrows ncols
154 dataframe-dimension dataframe-dimensons
155 xref xtype xdims xdim xrank slice take carray
157 dfref dfref-case dfref-var
158 consistent-dataframe-p
161 dataset
162 list-of-columns ;; list-of-variables
163 list-of-rows ;; list-of-observations
166 (defpackage :cls-data
167 (:use :common-lisp
168 :xarray
169 :lisp-matrix
170 :cls-dataframe) ; for dataframe
171 (:shadowing-import-from :xarray slice)
172 (:export listoflist->dataframe
173 listoflist->array
174 listoflist->matrix-like))
176 lists-of-same-size
177 equal-listoflist
178 transpose-listoflist
181 (defpackage :cls-dataimport
182 (:documentation "Data I/O and similar import technologies.")
183 (:use :common-lisp
184 :lisp-stat-object-system
185 :cls-dataframe
186 :cls-data
187 :rsm.string)
188 (:shadowing-import-from :lisp-stat-object-system
189 call-method call-next-method)
190 (:export dsvstream->dataframe dsvstream->matrix dsvstream->listoflist))
193 (defpackage :lisp-stat-model
194 (:documentation "Model management for data analysis.")
195 (:use :common-lisp
196 :lisp-matrix)
197 (:export
198 ;; data structures for model and model/data combination
199 model statistical-model analysis))
201 ;;; visualization
203 (defpackage :cls-visualize
204 (:use :common-lisp
205 :lisp-matrix
206 :cls-dataframe)
207 (:shadowing-import-from :xarray slice)
211 (defpackage :cls-visualize-plplot
212 (:use :common-lisp
213 :lisp-matrix
214 :cls-dataframe
215 :cl-plplot-system)
216 (:export
217 ;; examples
218 plot-ex contour-plot-ex fn-contour-plot-ex shade-plot-ex 3D-plot-ex))
221 ;;; USER PACKAGES
223 (defpackage :lisp-stat-ffi-int
224 (:use :common-lisp
225 :cffi)
226 (:export ccl-store-integer ccl-store-double ccl-store-ptr
227 get-buf ))
229 (defpackage :lisp-stat-probability
230 (:use :common-lisp
231 :cffi
232 :lisp-stat-ffi-int
233 :lisp-stat-macros)
234 (:export log-gamma set-seed
235 uniform-rand
236 normal-cdf normal-quant normal-dens normal-rand
237 bivnorm-cdf
238 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
239 gamma-cdf gamma-quant gamma-dens gamma-rand
240 chisq-cdf chisq-quant chisq-dens chisq-rand
241 beta-cdf beta-quant beta-dens beta-rand
242 t-cdf t-quant t-dens t-rand
243 f-cdf f-quant f-dens f-rand
244 poisson-cdf poisson-quant poisson-pmf poisson-rand
245 binomial-cdf binomial-quant binomial-pmf binomial-rand))
249 (defpackage :lisp-stat-math
250 (:use :common-lisp
251 :lisp-stat-object-system
252 :lisp-stat-macros
253 :lisp-stat-compound-data
254 :lisp-stat-float)
255 (:shadowing-import-from :lisp-stat-object-system
256 call-method call-next-method)
257 (:shadow expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
258 asin acos atan sinh cosh tanh asinh acosh atanh float random
259 truncate floor ceiling round minusp zerop plusp evenp oddp
260 < <= = /= >= > ;; complex
261 conjugate realpart imagpart phase
262 min max logand logior logxor lognot ffloor fceiling
263 ftruncate fround signum cis)
264 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
265 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
266 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
267 /= >= > ;; complex
268 conjugate realpart imagpart phase min max
269 logand logior logxor lognot ffloor fceiling ftruncate fround
270 signum cis)
271 (:documentation "Vectorization of numerical functions"))
274 #| ;; some of this goes back in, but not all of it?
275 (defpackage :lisp-stat-linalg
276 (:use :common-lisp
277 :cffi
278 :lisp-matrix
279 :lisp-stat-math
280 :lisp-stat-types
281 :lisp-stat-float
282 :lisp-stat-compound-data)
283 (:shadowing-import-from :lisp-stat-math
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 conjugate realpart imagpart phase
288 min max logand logior logxor lognot ffloor fceiling
289 ftruncate fround signum cis)
290 (:export chol-decomp lu-decomp lu-solve determinant inverse
291 sv-decomp qr-decomp rcondest make-rotation spline
292 kernel-dens kernel-smooth
293 fft make-sweep-matrix sweep-operator ax+y eigen
295 check-real ;; for optimize
297 covariance-matrix matrix print-matrix solve
298 backsolve eigenvalues eigenvectors accumulate cumsum combine
299 lowess))
306 (defpackage :lisp-stat-data
307 (:documentation "Data management, integration, I/O, and other data technologies.")
308 (:nicknames :ls-data)
309 (:use :common-lisp
310 :lisp-stat-object-system
311 :lisp-stat-config
312 :lisp-stat-types
313 :lisp-stat-compound-data)
314 (:shadowing-import-from :lisp-stat-object-system
315 call-method call-next-method)
316 (:export
317 ;; generic structures
318 ;; Variables
319 empirical-statistical-variable
320 modelbased-statistical-variable
321 categorical-statistical-variable
322 nominal-statistical-variable
323 ordinal-statistical-variable
324 continuous-statistical-variable
326 ordering factor-levels nobs support pdmf draw
327 print-object
329 ;; Observations
330 statistical-observation
331 measurement-types record
332 ;; XLS compat tools
333 open-file-dialog read-data-file read-data-columns load-data
334 load-example *variables* *ask-on-redefine*
335 def variables savevar undef))
337 (defpackage :lisp-stat-descriptive-statistics
338 (:use :common-lisp
339 :lisp-matrix
340 :lisp-stat-data
341 :lisp-stat-math
342 :lisp-stat-compound-data
343 :lisp-stat-basics)
344 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
345 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
346 asin acos atan sinh cosh tanh asinh acosh atanh float random
347 truncate floor ceiling round minusp zerop plusp evenp oddp
348 < <= = /= >= > ;; complex
349 conjugate realpart imagpart phase
350 min max logand logior logxor lognot ffloor fceiling
351 ftruncate fround signum cis)
352 (:export mean standard-deviation variance
353 quantile median interquartile-range
354 fivnum sample))
356 (defpackage :lisp-stat-regression-linear
357 (:use :common-lisp
358 :lisp-matrix
359 :lisp-stat-basics
360 :lisp-stat-compound-data
361 :lisp-stat-descriptive-statistics )
362 (:shadowing-import-from :lisp-stat-object-system
363 call-method call-next-method)
364 (:export regression-model fit-model
366 estimates covariance-matrix
367 ;; functions for helpers
368 lm xtxinv
369 print-object ;; for method dispatch
372 (defpackage :common-lisp-statistics
373 (:documentation "Experimentation package for LispStat. Serious work
374 should be packaged up as a separate but similar package to help
375 drive reproducibility. By this I mean, creating a
376 data/analytics/analysis package with the minimal set of
377 objects/packages required.")
378 (:nicknames :cls :common-lisp-statistics :lisp-stat)
379 (:use :common-lisp
380 :xarray ;; generic reference -- internally supporting array, lol structs
381 :lisp-matrix ;; conversion to a more robust linalg approach
382 :lisp-stat-config
383 :lisp-stat-object-system
384 :lisp-stat-compound-data
385 :lisp-stat-probability
386 :lisp-stat-types
387 :lisp-stat-float
388 :lisp-stat-basics
389 :lisp-stat-data
390 :cls-dataframe
391 :cls-data
392 :lisp-stat-math
393 :lisp-stat-descriptive-statistics
394 :lisp-stat-regression-linear
395 :cls-visualize
396 ;; :cybertiggyr-dsv
397 ;; :cls-visualize-plplot
399 (:shadowing-import-from :xarray slice)
400 (:shadowing-import-from :lisp-stat-object-system
401 call-method call-next-method)
402 (:shadowing-import-from :lisp-stat-math
403 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
404 asin acos atan sinh cosh tanh asinh acosh atanh float random
405 truncate floor ceiling round minusp zerop plusp evenp oddp
406 < <= = /= >= >
407 ;;complex
408 conjugate realpart imagpart phase
410 min max
411 logand logior logxor lognot
412 ffloor fceiling ftruncate fround
413 signum cis)
414 (:export
415 ;; lisp-stat-config:
416 *default-path* *lsos-files* *basic-files* *ls-files*
417 *lispstat-home-dir* *lispstat-data-dir* *lispstat-examples-dir*
419 ;; lsobjects :
420 defproto defproto2
421 defmeth send proto-slot-value
423 ;; lstypes :
424 fixnump check-nonneg-fixnum check-one-fixnum
425 check-one-nonneg-fixnum
426 check-one-real check-one-number
428 ;; lsmacros:
430 ;; lsfloat :
431 machine-epsilon
433 ;; compound :
434 compound-data-p *compound-data-proto* compound-object-p
435 compound-data-seq compound-data-length
436 element-list element-seq
437 sort-data order rank
438 recursive-map-elements map-elements
439 repeat
440 check-sequence
441 get-next-element make-next-element set-next-element
442 ;; sequencep
443 iseq
444 ordered-nneg-seq
445 select which
446 difference rseq
448 ;; lsmath.lsp
449 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
450 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
451 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
452 /= >= > ;; complex
453 conjugate realpart imagpart phase min max
454 logand logior logxor lognot ffloor fceiling ftruncate fround
455 signum cis
457 #| ;; The following need to be re-found in lisp-matrix...
459 ;; matrices.lisp
460 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
461 column-list inner-product outer-product cross-product transpose
462 bind-columns bind-rows
464 ;; linalg.lisp
465 chol-decomp lu-decomp lu-solve determinant inverse
466 sv-decomp qr-decomp rcondest make-rotation spline
467 kernel-dens kernel-smooth
468 fft make-sweep-matrix sweep-operator ax+y eigen
469 check-real
470 covariance-matrix matrix print-matrix solve
471 backsolve eigenvalues eigenvectors accumulate cumsum combine
472 lowess
474 ;; in linalg.lisp, possibly not supported by matlisp
475 spline kernel-dens kernel-smooth
479 ;; optimize.lsp
480 newtonmax nelmeadmax
482 ;; lispstat-macros
483 make-rv-function make-rv-function-1
485 ;; xarray
486 xref xtype xdims xdim xdims*
487 lists-of-same-size equal-listoflist transpose-listoflist
489 ;; data
490 ;; need to take this list and make it strings... specs could mean
491 ;; that we process the strings in different ways?
493 (let ((lst ()))
494 (unlist
495 (mapc #'symbol-for-symbol-to-string-or-symbol
496 (do-external-symbols (s (find-package 'lisp-stat-data) lst) (push s lst))))
497 lst)
499 open-file-dialog read-data-file read-data-columns load-data
500 load-example *variables* *ask-on-redefine*
501 def variables savevar undef
502 ;; dataframe
503 dataframe-like dataframe-array make-dataframe
504 varlabels caselabels nrows ncols
505 dataframe-dimension dataframe-dimensons
506 dfref dfref-case dfref-var
507 consistent-dataframe-p
508 dataset list-of-columns list-of-rows
510 ;; listoflist
511 listoflist->dataframe listoflist->array listoflist->matrix-like
513 ;; statistics.lsp (descriptions, should probably be moved
514 ;; later...?
515 standard-deviation quantile median interquartile-range
516 fivnum sample
518 ;; probability (dists.lisp)
519 log-gamma set-seed
520 uniform-rand normal-cdf normal-quant normal-dens
521 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
522 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
523 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
524 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
525 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
526 binomial-cdf binomial-quant binomial-pmf binomial-rand
528 ;; Here is where we have a problem -- lispstat core should be core
529 ;; data management and config problems, with packages providing
530 ;; specialized extensions to LispStat, i.e. regression, nonlin
531 ;; regression, bayesian regression via laplace approximation, etc.
533 ;; The following could be considered "recommended packages",
534 ;; similar to the idea of the recommended packages in R. Probably
535 ;; we want them to do the exporting within that package, therefore
536 ;; NOT being able to lock the "data-ish" package, but only the
537 ;; subpackages prior to export.
539 ;; regression.lsp
540 ;; -- linear regressin models.
541 regression-model fit-model
542 estimates covariance-matrix
544 regression-model-proto x y intercept sweep-matrix
545 basis weights included total-sum-of-squares residual-sum-of-squares
546 predictor-names response-name case-labels
547 lm xtxinv
549 ;; nonlin.lsp
550 ;; -- nonlinear regression models
551 nreg-model nreg-model-proto mean-function theta-hat epsilon
552 count-limit verbose
553 ;; we might need something like xtxinv here? But should be
554 ;; encapsulated, so we use the one in regression.lisp
556 ;; bayes.lsp
557 bayes-model bayes-model-proto bayes-internals
559 ;; plots.lisp
560 plot-ex
561 contour-plot-ex
562 fn-contour-plot-ex
563 shade-plot-ex
564 3D-plot-ex
569 ;;;; PACKAGES FOR USEABILITY
571 (defpackage :lisp-stat-data-examples
572 (:documentation "Example data for unittests, examples, illustrations,")
573 (:use :common-lisp
574 :common-lisp-statistics)
575 (:shadowing-import-from :lisp-stat
576 call-method call-next-method
578 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
579 asin acos atan sinh cosh tanh asinh acosh atanh float random
580 truncate floor ceiling round minusp zerop plusp evenp oddp
581 < <= = /= >= > > ;; complex
582 conjugate realpart imagpart phase
583 min max logand logior logxor lognot ffloor fceiling
584 ftruncate fround signum cis
586 <= float imagpart)
587 (:export iron aluminum absorbtion
588 diabetes dlabs))
591 (defpackage :lisp-stat-user
592 (:documentation "Experimentation package for LispStat. Serious work
593 should be placed in a similar package elsewhere for
594 reproducibility. But this should hint as to what needs to be done
595 for a user- or analysis-package.")
596 (:nicknames :ls-user)
597 (:use :common-lisp ; always needed for user playgrounds!
598 :lisp-matrix
599 :common-lisp-statistics
600 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
601 (:shadowing-import-from :lisp-stat
602 call-method call-next-method
604 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
605 asin acos atan sinh cosh tanh asinh acosh atanh float random
606 truncate floor ceiling round minusp zerop plusp evenp oddp
607 < <= = /= >= > > ;; complex
608 conjugate realpart imagpart phase
609 min max logand logior logxor lognot ffloor fceiling
610 ftruncate fround signum cis
612 <= float imagpart))
614 (defpackage :lisp-stat-unittests
615 (:use :common-lisp
616 :lift :lisp-matrix
617 :lisp-stat :lisp-stat-data-examples)
618 (:shadowing-import-from :lisp-stat
619 call-method call-next-method ;; objects
620 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
621 asin acos atan sinh cosh tanh asinh acosh atanh float random
622 truncate floor ceiling round minusp zerop plusp evenp oddp
623 < <= = /= >= > ;; complex
624 conjugate realpart imagpart phase
625 min max logand logior logxor lognot ffloor fceiling
626 ftruncate fround signum cis)
627 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
628 almost= almost=lists numerical=)) ; compare
630 (defpackage :cls-dataframe-example
631 (:use :common-lisp
632 :lift :lisp-stat-unittests
633 :lisp-stat-data-examples
634 :cls-dataframe)
635 (:export absorbtion aluminum iron))
638 (defpackage :lisp-stat-optimize
639 (:use :common-lisp
640 :cffi
641 :lisp-matrix
642 :lisp-stat-ffi-int
643 :lisp-stat-object-system
644 :lisp-stat-types
645 :lisp-stat-compound-data
646 :lisp-stat-math
647 :lisp-stat-float
648 :lisp-stat-basics
650 :lisp-stat-matrix
651 :lisp-stat-linalg-data
652 :lisp-stat-linalg
655 (:shadowing-import-from :lisp-stat-object-system
656 call-method call-next-method)
657 (:shadowing-import-from :lisp-stat-math
658 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
659 asin acos atan sinh cosh tanh asinh acosh atanh float random
660 truncate floor ceiling round minusp zerop plusp evenp oddp
661 < <= = /= >= > complex conjugate realpart imagpart phase
662 min max logand logior logxor lognot ffloor fceiling
663 ftruncate fround signum cis)
664 (:export
665 ;; derivatives
666 numgrad numhess
668 ;; optimization
669 newtonmax nelmeadmax))