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