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