use xref approach for CLS. (need to do so for lisp-matrix as well.
[CommonLispStat.git] / src / packages.lisp
blobfef185bf8370e0540b20be1c2766ac5c5592977f
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-07-22 19:17:55 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 (:shadowing-import-from :xarray slice)
132 (:export
133 ;; generic container class for data -- if small enough
134 ;; could be value, otherwise might be reference.
135 dataframe-like
136 dataframe-array
137 make-dataframe
139 ;; accessors
140 varlabels caselabels nrows ncols
141 dataframe-dimension dataframe-dimensons
142 xref xtype xdims xdim xrank slice take carray
144 dfref dfref-case dfref-var
145 consistent-dataframe-p
148 dataset
149 list-of-columns ;; list-of-variables
150 list-of-rows ;; list-of-observations
153 ;; move to cls-data -- but in listoflist.lisp
154 (defpackage :cls-data-listoflist
155 (:use :common-lisp
156 :lisp-matrix
157 :cls-dataframe) ; for dataframe
158 (:shadowing-import-from :xarray slice)
159 (:export lists-of-same-size
160 equal-listoflist
161 transpose-listoflist
162 listoflist->dataframe
163 listoflist->array
164 listoflist->matrix-like))
167 (defpackage :cls-dataimport
168 (:documentation "Data I/O and similar import technologies.")
169 (:use :common-lisp
170 :lisp-stat-object-system
171 :cls-dataframe
172 :cls-data-listoflist
173 :rsm.string)
174 (:shadowing-import-from :lisp-stat-object-system
175 call-method call-next-method)
176 (:export dsvstream->dataframe dsvstream->matrix dsvstream->listoflist))
179 (defpackage :lisp-stat-model
180 (:documentation "Model management for data analysis.")
181 (:use :common-lisp
182 :lisp-matrix)
183 (:export
184 ;; data structures for model and model/data combination
185 model statistical-model analysis))
187 ;;; visualization
189 (defpackage :cls-visualize
190 (:use :common-lisp
191 :lisp-matrix
192 :cls-dataframe)
193 (:shadowing-import-from :xarray slice)
197 (defpackage :cls-visualize-plplot
198 (:use :common-lisp
199 :lisp-matrix
200 :cls-dataframe
201 :cl-plplot-system)
202 (:export
203 ;; examples
204 plot-ex contour-plot-ex fn-contour-plot-ex shade-plot-ex 3D-plot-ex))
207 ;;; USER PACKAGES
209 (defpackage :lisp-stat-ffi-int
210 (:use :common-lisp
211 :cffi)
212 (:export ccl-store-integer ccl-store-double ccl-store-ptr
213 get-buf ))
215 (defpackage :lisp-stat-probability
216 (:use :common-lisp
217 :cffi
218 :lisp-stat-ffi-int
219 :lisp-stat-macros)
220 (:export log-gamma set-seed
221 uniform-rand
222 normal-cdf normal-quant normal-dens normal-rand
223 bivnorm-cdf
224 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
225 gamma-cdf gamma-quant gamma-dens gamma-rand
226 chisq-cdf chisq-quant chisq-dens chisq-rand
227 beta-cdf beta-quant beta-dens beta-rand
228 t-cdf t-quant t-dens t-rand
229 f-cdf f-quant f-dens f-rand
230 poisson-cdf poisson-quant poisson-pmf poisson-rand
231 binomial-cdf binomial-quant binomial-pmf binomial-rand))
235 (defpackage :lisp-stat-math
236 (:use :common-lisp
237 :lisp-stat-object-system
238 :lisp-stat-macros
239 :lisp-stat-compound-data
240 :lisp-stat-float)
241 (:shadowing-import-from :lisp-stat-object-system
242 call-method call-next-method)
243 (:shadow 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
247 conjugate realpart imagpart phase
248 min max logand logior logxor lognot ffloor fceiling
249 ftruncate fround signum cis)
250 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
251 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
252 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
253 /= >= > ;; complex
254 conjugate realpart imagpart phase min max
255 logand logior logxor lognot ffloor fceiling ftruncate fround
256 signum cis)
257 (:documentation "Vectorization of numerical functions"))
260 #| ;; some of this goes back in, but not all of it?
261 (defpackage :lisp-stat-linalg
262 (:use :common-lisp
263 :cffi
264 :lisp-matrix
265 :lisp-stat-math
266 :lisp-stat-types
267 :lisp-stat-float
268 :lisp-stat-compound-data)
269 (:shadowing-import-from :lisp-stat-math
270 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
271 asin acos atan sinh cosh tanh asinh acosh atanh float random
272 truncate floor ceiling round minusp zerop plusp evenp oddp
273 < <= = /= >= > complex conjugate realpart imagpart phase
274 min max logand logior logxor lognot ffloor fceiling
275 ftruncate fround signum cis)
276 (:export chol-decomp lu-decomp lu-solve determinant inverse
277 sv-decomp qr-decomp rcondest make-rotation spline
278 kernel-dens kernel-smooth
279 fft make-sweep-matrix sweep-operator ax+y eigen
281 check-real ;; for optimize
283 covariance-matrix matrix print-matrix solve
284 backsolve eigenvalues eigenvectors accumulate cumsum combine
285 lowess))
292 (defpackage :lisp-stat-data
293 (:documentation "Data management, integration, I/O, and other data technologies.")
294 (:nicknames :ls-data)
295 (:use :common-lisp
296 :lisp-stat-object-system
297 :lisp-stat-config
298 :lisp-stat-types
299 :lisp-stat-compound-data)
300 (:shadowing-import-from :lisp-stat-object-system
301 call-method call-next-method)
302 (:export open-file-dialog read-data-file read-data-columns load-data
303 load-example *variables* *ask-on-redefine*
304 def variables savevar undef))
306 (defpackage :lisp-stat-descriptive-statistics
307 (:use :common-lisp
308 :lisp-matrix
309 :lisp-stat-data
310 :lisp-stat-math
311 :lisp-stat-compound-data
312 :lisp-stat-basics)
313 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
314 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
315 asin acos atan sinh cosh tanh asinh acosh atanh float random
316 truncate floor ceiling round minusp zerop plusp evenp oddp
317 < <= = /= >= > ;; complex
318 conjugate realpart imagpart phase
319 min max logand logior logxor lognot ffloor fceiling
320 ftruncate fround signum cis)
321 (:export mean standard-deviation variance
322 quantile median interquartile-range
323 fivnum sample))
325 (defpackage :lisp-stat-regression-linear
326 (:use :common-lisp
327 :lisp-matrix
328 :lisp-stat-basics
329 :lisp-stat-compound-data
330 :lisp-stat-descriptive-statistics )
331 (:shadowing-import-from :lisp-stat-object-system
332 call-method call-next-method)
333 (:export regression-model fit-model
335 estimates covariance-matrix
336 ;; functions for helpers
337 lm xtxinv
338 print-object ;; for method dispatch
341 (defpackage :common-lisp-statistics
342 (:documentation "Experimentation package for LispStat. Serious work
343 should be packaged up elsewhere for reproducibility. By this I
344 mean, creating a data/analytics/analysis package with the minimal
345 set of objects required.")
346 (:nicknames :cls :common-lisp-statistics :lisp-stat)
347 (:use :common-lisp
348 :lisp-stat-config
349 :lisp-stat-object-system
350 :lisp-stat-compound-data
351 :lisp-stat-probability
352 :lisp-stat-types
353 :lisp-stat-float
354 :lisp-stat-basics
355 :lisp-stat-data
356 :cls-dataframe
357 :cls-data-listoflist
358 :lisp-stat-math
359 :xarray
360 :lisp-matrix ;; conversion to a more robust linalg approach
361 :lisp-stat-descriptive-statistics
362 :lisp-stat-regression-linear
363 ;; :cybertiggyr-dsv
364 :cls-visualize
365 ;; :cls-visualize-plplot
367 (:shadowing-import-from :xarray slice)
368 (:shadowing-import-from :lisp-stat-object-system
369 call-method call-next-method)
370 (:shadowing-import-from :lisp-stat-math
371 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
372 asin acos atan sinh cosh tanh asinh acosh atanh float random
373 truncate floor ceiling round minusp zerop plusp evenp oddp
374 < <= = /= >= >
375 ;;complex
376 conjugate realpart imagpart phase
378 min max
379 logand logior logxor lognot
380 ffloor fceiling ftruncate fround
381 signum cis)
382 (:export
383 ;; lisp-stat-config:
384 *default-path* *lsos-files* *basic-files* *ls-files*
385 *lispstat-home-dir* *lispstat-data-dir* *lispstat-examples-dir*
387 ;; lsobjects :
388 defproto defproto2
389 defmeth send proto-slot-value
391 ;; lstypes :
392 fixnump check-nonneg-fixnum check-one-fixnum
393 check-one-nonneg-fixnum
394 check-one-real check-one-number
396 ;; lsmacros:
398 ;; lsfloat :
399 machine-epsilon
401 ;; compound :
402 compound-data-p *compound-data-proto* compound-object-p
403 compound-data-seq compound-data-length
404 element-list element-seq
405 sort-data order rank
406 recursive-map-elements map-elements
407 repeat
408 check-sequence
409 get-next-element make-next-element set-next-element
410 ;; sequencep
411 iseq
412 ordered-nneg-seq
413 select which
414 difference rseq
416 ;; lsmath.lsp
417 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
418 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
419 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
420 /= >= > ;; complex
421 conjugate realpart imagpart phase min max
422 logand logior logxor lognot ffloor fceiling ftruncate fround
423 signum cis
425 #| ;; The following need to be re-found in lisp-matrix...
427 ;; matrices.lisp
428 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
429 column-list inner-product outer-product cross-product transpose
430 bind-columns bind-rows
432 ;; linalg.lisp
433 chol-decomp lu-decomp lu-solve determinant inverse
434 sv-decomp qr-decomp rcondest make-rotation spline
435 kernel-dens kernel-smooth
436 fft make-sweep-matrix sweep-operator ax+y eigen
437 check-real
438 covariance-matrix matrix print-matrix solve
439 backsolve eigenvalues eigenvectors accumulate cumsum combine
440 lowess
442 ;; in linalg.lisp, possibly not supported by matlisp
443 spline kernel-dens kernel-smooth
447 ;; optimize.lsp
448 newtonmax nelmeadmax
450 ;; lispstat-macros
451 make-rv-function make-rv-function-1
453 ;; xarray
454 xref xtype xdims xdim xdims*
456 ;; data
457 open-file-dialog read-data-file read-data-columns load-data
458 load-example *variables* *ask-on-redefine*
459 def variables savevar undef
461 ;; dataframe
462 dataframe-like dataframe-array make-dataframe
463 varlabels caselabels nrows ncols
464 dataframe-dimension dataframe-dimensons
465 dfref dfref-case dfref-var
466 consistent-dataframe-p
467 dataset list-of-columns list-of-rows
469 ;; listoflist
470 lists-of-same-size equal-listoflist
471 transpose-listoflist
472 listoflist->dataframe listoflist->array listoflist->matrix-like
474 ;; statistics.lsp (descriptions, should probably be moved
475 ;; later...?
476 standard-deviation quantile median interquartile-range
477 fivnum sample
479 ;; probability (dists.lisp)
480 log-gamma set-seed
481 uniform-rand normal-cdf normal-quant normal-dens
482 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
483 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
484 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
485 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
486 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
487 binomial-cdf binomial-quant binomial-pmf binomial-rand
489 ;; Here is where we have a problem -- lispstat core should be core
490 ;; data management and config problems, with packages providing
491 ;; specialized extensions to LispStat, i.e. regression, nonlin
492 ;; regression, bayesian regression via laplace approximation, etc.
494 ;; The following could be considered "recommended packages",
495 ;; similar to the idea of the recommended packages in R. Probably
496 ;; we want them to do the exporting within that package, therefore
497 ;; NOT being able to lock the "data-ish" package, but only the
498 ;; subpackages prior to export.
500 ;; regression.lsp
501 ;; -- linear regressin models.
502 regression-model fit-model
503 estimates covariance-matrix
505 regression-model-proto x y intercept sweep-matrix
506 basis weights included total-sum-of-squares residual-sum-of-squares
507 predictor-names response-name case-labels
508 lm xtxinv
510 ;; nonlin.lsp
511 ;; -- nonlinear regression models
512 nreg-model nreg-model-proto mean-function theta-hat epsilon
513 count-limit verbose
514 ;; we might need something like xtxinv here? But should be
515 ;; encapsulated, so we use the one in regression.lisp
517 ;; bayes.lsp
518 bayes-model bayes-model-proto bayes-internals
520 ;; plots.lisp
521 plot-ex
522 contour-plot-ex
523 fn-contour-plot-ex
524 shade-plot-ex
525 3D-plot-ex
530 ;;;; PACKAGES FOR USEABILITY
532 (defpackage :lisp-stat-data-examples
533 (:documentation "Example data for unittests, examples, illustrations,")
534 (:use :common-lisp
535 :common-lisp-statistics)
536 (:shadowing-import-from :lisp-stat
537 call-method call-next-method
539 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
540 asin acos atan sinh cosh tanh asinh acosh atanh float random
541 truncate floor ceiling round minusp zerop plusp evenp oddp
542 < <= = /= >= > > ;; complex
543 conjugate realpart imagpart phase
544 min max logand logior logxor lognot ffloor fceiling
545 ftruncate fround signum cis
547 <= float imagpart)
548 (:export iron aluminum absorbtion
549 diabetes dlabs))
552 (defpackage :lisp-stat-user
553 (:documentation "Experimentation package for LispStat. Serious work
554 should be placed in a similar package elsewhere for
555 reproducibility. But this should hint as to what needs to be done
556 for a user- or analysis-package.")
557 (:nicknames :ls-user)
558 (:use :common-lisp ; always needed for user playgrounds!
559 :lisp-matrix
560 :common-lisp-statistics
561 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
562 (:shadowing-import-from :lisp-stat
563 call-method call-next-method
565 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
566 asin acos atan sinh cosh tanh asinh acosh atanh float random
567 truncate floor ceiling round minusp zerop plusp evenp oddp
568 < <= = /= >= > > ;; complex
569 conjugate realpart imagpart phase
570 min max logand logior logxor lognot ffloor fceiling
571 ftruncate fround signum cis
573 <= float imagpart))
575 (defpackage :lisp-stat-unittests
576 (:use :common-lisp
577 :lift :lisp-matrix
578 :lisp-stat :lisp-stat-data-examples)
579 (:shadowing-import-from :lisp-stat
580 call-method call-next-method ;; objects
581 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
582 asin acos atan sinh cosh tanh asinh acosh atanh float random
583 truncate floor ceiling round minusp zerop plusp evenp oddp
584 < <= = /= >= > ;; complex
585 conjugate realpart imagpart phase
586 min max logand logior logxor lognot ffloor fceiling
587 ftruncate fround signum cis)
588 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
589 almost= almost=lists numerical=)) ; compare
591 (defpackage :cls-dataframe-example
592 (:use :common-lisp
593 :lift :lisp-stat-unittests
594 :lisp-stat-data-examples
595 :cls-dataframe)
596 (:export absorbtion aluminum iron))
599 (defpackage :lisp-stat-optimize
600 (:use :common-lisp
601 :cffi
602 :lisp-matrix
603 :lisp-stat-ffi-int
604 :lisp-stat-object-system
605 :lisp-stat-types
606 :lisp-stat-compound-data
607 :lisp-stat-math
608 :lisp-stat-float
609 :lisp-stat-basics
611 :lisp-stat-matrix
612 :lisp-stat-linalg-data
613 :lisp-stat-linalg
616 (:shadowing-import-from :lisp-stat-object-system
617 call-method call-next-method)
618 (:shadowing-import-from :lisp-stat-math
619 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
620 asin acos atan sinh cosh tanh asinh acosh atanh float random
621 truncate floor ceiling round minusp zerop plusp evenp oddp
622 < <= = /= >= > complex conjugate realpart imagpart phase
623 min max logand logior logxor lognot ffloor fceiling
624 ftruncate fround signum cis)
625 (:export
626 ;; derivatives
627 numgrad numhess
629 ;; optimization
630 newtonmax nelmeadmax))