printing sort of works, good enough for now.
[CommonLispStat.git] / src / packages.lisp
blob195da3d7fa0df8573adbc828d00779475a22ece9
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-03-26 08:18:29 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 ;;; This organization and structure is new to the 21st Century
16 ;;; version.
18 (in-package :cl-user)
20 ;;; LispStat Basics
22 (defpackage :lisp-stat-object-system
23 (:nicknames :ls-objects :lsos)
24 (:use :common-lisp)
25 (:shadow :call-method :call-next-method :slot-value)
26 (:export ls-object objectp *object* kind-of-p make-object
27 *message-hook*
28 *set-slot-hook* slot-value self
29 send call-next-method call-method
30 defmeth defproto instance-slots proto-name))
32 (defpackage :lisp-stat-types
33 (:documentation "Provides some typeing for LispStat, but is clearly
34 a bit incomplete.")
35 (:use :common-lisp)
36 (:export fixnump
37 check-nonneg-fixnum check-one-nonneg-fixnum
38 check-one-fixnum check-one-real check-one-number))
40 (defpackage :lisp-stat-float
41 (:use :common-lisp)
42 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
43 machine-epsilon base-float makedouble
45 make-base-trans-fun-2 make-base-trans-fun
47 base-log base-exp base-expt base-sqrt base-sin base-cos
48 base-tan base-asin base-acos base-atan base-sinh
49 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
50 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
51 BASE-FROUND BASE-SIGNUM BASE-CIS))
53 (defpackage :lisp-stat-compound-data
54 (:use :common-lisp
55 :lisp-stat-object-system
56 :lisp-stat-types)
57 (:shadowing-import-from :lisp-stat-object-system
58 slot-value
59 call-next-method call-method)
60 (:export compound-data-p *compound-data-proto*
61 compound-object-p
62 compound-data-seq compound-data-length
63 element-list element-seq
64 sort-data order rank
65 recursive-map-elements map-elements repeat
66 check-sequence
67 get-next-element make-next-element set-next-element
68 ;; sequencep
69 iseq ordered-nneg-seq
70 select split-list which
71 difference rseq
72 flatten-list))
74 (defpackage :lisp-stat-macros
75 (:use :common-lisp
76 :lisp-stat-compound-data)
77 (:export make-rv-function make-rv-function-1))
79 (defpackage :lisp-stat-basics
80 (:use :common-lisp
81 :lisp-stat-object-system
82 :lisp-stat-types
83 :lisp-stat-float
84 :lisp-stat-macros
85 :lisp-stat-compound-data)
86 (:shadowing-import-from :lisp-stat-object-system
87 slot-value call-method call-next-method)
88 (:export permute-array sum prod count-elements mean
89 if-else sample))
91 (defpackage :lisp-stat-float
92 (:use :common-lisp)
93 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
94 machine-epsilon base-float makedouble
96 make-base-trans-fun-2 make-base-trans-fun
98 BASE-LOG BASE-EXP BASE-EXPT BASE-SQRT BASE-SIN BASE-COS
99 BASE-TAN BASE-ASIN BASE-ACOS BASE-ATAN BASE-SINH
100 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
101 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
102 BASE-FROUND BASE-SIGNUM BASE-CIS))
104 (defpackage :lisp-stat-macros
105 (:use :common-lisp
106 :lisp-stat-compound-data)
107 (:export make-rv-function make-rv-function-1))
109 ;;; NEW CLOS STRUCTURE
113 (defpackage :lisp-stat-data-clos
114 (:use :common-lisp
115 :lisp-matrix)
116 (:export
117 ;; generic container class for data -- if small enough
118 ;; could be value, otherwise might be reference.
119 dataframe-like
120 dataframe-array
121 make-dataframe
123 ;; accessors
124 varlabels caselabels nrows ncols
125 dataframe-dimension dataframe-dimensons
126 dfref dfref-case dfref-var
127 consistent-dataframe-p
129 dataset
130 list-of-columns ;; list-of-variables
131 list-of-rows ;; list-of-observations
135 (defpackage :cls-data-listoflist
136 (:use :common-lisp
137 :lisp-stat-data-clos) ; for dataframe
138 (:export lists-of-same-size
139 equal-listoflist
140 transpose-listoflist
141 make-dataframe-from-listoflist
142 make-array-from-listoflist))
145 (defpackage :lisp-stat-regression-linear-clos
146 (:use :common-lisp
147 :lisp-matrix
148 :lisp-stat-data-clos)
149 (:export regression-model))
152 (defpackage :lisp-stat-visualize
153 (:use :common-lisp
154 :lisp-matrix
155 :lisp-stat-data-clos))
157 (defpackage :lisp-stat-visualize-plplot
158 (:use :common-lisp
159 :lisp-matrix
160 :lisp-stat-data-clos
161 :cl-plplot-system)
162 (:export
163 plot-ex
164 contour-plot-ex
165 fn-contour-plot-ex
166 shade-plot-ex
167 3D-plot-ex ))
170 ;;; USER PACKAGES
172 (defpackage :lisp-stat-ffi-int
173 (:use :common-lisp
174 :cffi)
175 (:export ccl-store-integer ccl-store-double ccl-store-ptr
176 get-buf ))
178 (defpackage :lisp-stat-probability
179 (:use :common-lisp
180 :cffi
181 :lisp-stat-ffi-int
182 :lisp-stat-macros)
183 (:export log-gamma set-seed
184 uniform-rand
185 normal-cdf normal-quant normal-dens normal-rand
186 bivnorm-cdf
187 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
188 gamma-cdf gamma-quant gamma-dens gamma-rand
189 chisq-cdf chisq-quant chisq-dens chisq-rand
190 beta-cdf beta-quant beta-dens beta-rand
191 t-cdf t-quant t-dens t-rand
192 f-cdf f-quant f-dens f-rand
193 poisson-cdf poisson-quant poisson-pmf poisson-rand
194 binomial-cdf binomial-quant binomial-pmf binomial-rand))
197 #| removed, replace by lisp-matrix
198 (defpackage :lisp-stat-matrix
199 (:use :common-lisp
200 :cffi
201 :lisp-stat-compound-data)
202 (:export matrixp ;; matrix -- conflicts!
203 num-rows num-cols matmult identity-matrix diagonal
204 row-list column-list inner-product outer-product
205 cross-product
206 ;; transpose bind-columns bind-rows
207 array-data-vector vector-to-array
209 check-matrix check-square-matrix
211 copy-array copy-vector
215 #| replaced by lisp-matrix
216 (defpackage :lisp-stat-linalg-data
217 (:use :common-lisp
218 :cffi
219 :lisp-stat-ffi-int
220 :lisp-stat-types
221 :lisp-stat-compound-data
222 :lisp-stat-matrix)
223 (:export ;; more to add
224 +mode-in+ +mode-re+ +mode-cx+ mode-of
226 la-data-mode la-allocate la-free
228 la-get-double la-put-double
229 la-put-integer
231 la-matrix la-free-matrix la-matrix-to-data la-data-to-matrix
232 la-vector la-free-vector la-vector-to-data la-data-to-vector ))
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 slot-value 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 slot-value 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-stat-data
309 :lisp-stat-math
310 :lisp-stat-compound-data
311 :lisp-matrix
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 standard-deviation
322 quantile median interquartile-range
323 fivnum sample))
326 (defpackage :lisp-stat-regression-linear
327 (:use :common-lisp
328 :lisp-matrix
329 :lisp-stat-object-system
330 :lisp-stat-basics
331 :lisp-stat-compound-data
332 :lisp-stat-descriptive-statistics
334 :lisp-stat-math
337 (:shadowing-import-from :lisp-stat-object-system
338 slot-value call-method call-next-method)
340 (:shadowing-import-from :lisp-stat-math
341 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
342 asin acos atan sinh cosh tanh asinh acosh atanh float random
343 truncate floor ceiling round minusp zerop plusp evenp oddp
344 < <= = /= >= > ;; complex
345 conjugate realpart imagpart phase
346 min max logand logior logxor lognot ffloor fceiling
347 ftruncate fround signum cis)
349 (:export regression-model regression-model-proto x y intercept
350 ;; sweep-matrix
351 basis weights included
352 total-sum-of-squares residual-sum-of-squares
353 predictor-names response-name case-labels
354 ;; functions for helpers
355 lm xtxinv ))
357 (defpackage :lisp-stat
358 (:documentation "Experimentation package for LispStat. Serious
359 work should be packaged up elsewhere for reproducibility. By this
360 I mean, creating a data/analytics/analysis package with the
361 minimal set of objects required.")
362 (:use :common-lisp
363 :lisp-stat-object-system
364 :lisp-stat-compound-data
365 :lisp-stat-probability
366 :lisp-stat-types
367 :lisp-stat-float
368 :lisp-stat-basics
369 :lisp-stat-data
370 :lisp-stat-data-clos
371 :lisp-stat-math
372 :lisp-matrix ;; conversion to a more robust linalg approach
373 :lisp-stat-descriptive-statistics
374 :lisp-stat-regression-linear
375 :cybertiggyr-dsv)
376 (:shadowing-import-from :lisp-stat-object-system
377 slot-value call-method call-next-method)
378 (:shadowing-import-from :lisp-stat-math
379 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
380 asin acos atan sinh cosh tanh asinh acosh atanh float random
381 truncate floor ceiling round minusp zerop plusp evenp oddp
382 < <= = /= >= >
383 ;;complex
384 conjugate realpart imagpart phase
386 min max
387 logand logior logxor lognot
388 ffloor fceiling ftruncate fround
389 signum cis)
390 (:export
391 ;; lsobjects :
392 defproto defproto2
393 defmeth send
395 ;; lstypes :
396 fixnump check-nonneg-fixnum check-one-fixnum
397 check-one-real check-one-number
399 ;; lsmacros:
401 ;; lsfloat :
402 machine-epsilon
404 ;; compound :
405 compound-data-p *compound-data-proto* compound-object-p
406 compound-data-seq compound-data-length
407 element-list element-seq
408 sort-data order rank
409 recursive-map-elements map-elements
410 repeat
411 check-sequence
412 get-next-element make-next-element set-next-element
413 ;; sequencep
414 iseq
415 ordered-nneg-seq
416 select which
417 difference rseq
419 ;; lsmath.lsp
420 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
421 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
422 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
423 /= >= > ;; complex
424 conjugate realpart imagpart phase min max
425 logand logior logxor lognot ffloor fceiling ftruncate fround
426 signum cis
428 #| ;; The following need to be re-found in lisp-matrix...
430 ;; matrices.lisp
431 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
432 column-list inner-product outer-product cross-product transpose
433 bind-columns bind-rows
435 ;; linalg.lisp
436 chol-decomp lu-decomp lu-solve determinant inverse
437 sv-decomp qr-decomp rcondest make-rotation spline
438 kernel-dens kernel-smooth
439 fft make-sweep-matrix sweep-operator ax+y eigen
440 check-real
441 covariance-matrix matrix print-matrix solve
442 backsolve eigenvalues eigenvectors accumulate cumsum combine
443 lowess
445 ;; in linalg.lisp, possibly not supported by matlisp
446 spline kernel-dens kernel-smooth
450 ;; optimize.lsp
451 newtonmax nelmeadmax
453 ;; lispstat-macros
454 make-rv-function make-rv-function-1
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 ;; data-clos
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
468 list-of-columns list-of-rows
470 ;; listoflist
471 lists-of-same-size equal-listoflist
472 transpose-listoflist
473 make-dataframe-from-listoflist make-array-from-listoflist
475 ;; statistics.lsp (descriptions, should probably be moved
476 ;; later...?
477 standard-deviation quantile median interquartile-range
478 fivnum sample
480 ;; probability (dists.lisp)
481 log-gamma set-seed
482 uniform-rand normal-cdf normal-quant normal-dens
483 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
484 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
485 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
486 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
487 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
488 binomial-cdf binomial-quant binomial-pmf binomial-rand
490 ;; Here is where we have a problem -- lispstat core should be core
491 ;; data management and config problems, with packages providing
492 ;; specialized extensions to LispStat, i.e. regression, nonlin
493 ;; regression, bayesian regression via laplace approximation, etc.
495 ;; The following could be considered "recommended packages",
496 ;; similar to the idea of the recommended packages in R. Probably
497 ;; we want them to do the exporting within that package, therefore
498 ;; NOT being able to lock the "data-ish" package, but only the
499 ;; subpackages prior to export.
501 ;; regression.lsp
502 ;; -- linear regressin models.
503 regression-model regression-model-proto x y intercept sweep-matrix
504 basis weights included total-sum-of-squares residual-sum-of-squares
505 predictor-names response-name case-labels
506 lm xtxinv
508 ;; nonlin.lsp
509 ;; -- nonlinear regression models
510 nreg-model nreg-model-proto mean-function theta-hat epsilon
511 count-limit verbose
512 ;; we might need something like xtxinv here? But should be
513 ;; encapsulated, so we use the one in regression.lisp
515 ;; bayes.lsp
516 bayes-model bayes-model-proto bayes-internals
519 ;; plots.lisp
520 plot-ex
521 contour-plot-ex
522 fn-contour-plot-ex
523 shade-plot-ex
524 3D-plot-ex
529 ;;;; PACKAGES FOR USEABILITY
531 (defpackage :lisp-stat-data-examples
532 (:documentation "Example data for unittests, examples, illustrations,")
533 (:use :common-lisp
534 :lisp-stat)
535 (:shadowing-import-from :lisp-stat
536 slot-value call-method call-next-method
538 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
539 asin acos atan sinh cosh tanh asinh acosh atanh float random
540 truncate floor ceiling round minusp zerop plusp evenp oddp
541 < <= = /= >= > > ;; complex
542 conjugate realpart imagpart phase
543 min max logand logior logxor lognot ffloor fceiling
544 ftruncate fround signum cis
546 <= float imagpart)
547 (:export iron aluminum absorbtion
548 diabetes dlabs))
551 (defpackage :lisp-stat-user
552 (:documentation "Experimentation package for LispStat.
553 Serious work should be placed in a similar package elsewhere for
554 reproducibility. But this should hint as to what needs to be
555 done for a user- or analysis-package.")
556 (:nicknames :ls-user)
557 (:use :common-lisp
558 :lisp-matrix
559 :lisp-stat
560 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
561 (:shadowing-import-from :lisp-stat
562 slot-value call-method call-next-method
564 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
565 asin acos atan sinh cosh tanh asinh acosh atanh float random
566 truncate floor ceiling round minusp zerop plusp evenp oddp
567 < <= = /= >= > > ;; complex
568 conjugate realpart imagpart phase
569 min max logand logior logxor lognot ffloor fceiling
570 ftruncate fround signum cis
572 <= float imagpart))
574 (defpackage :lisp-stat-unittests
575 (:use :common-lisp :lift :lisp-stat :lisp-stat-data-examples)
576 (:shadowing-import-from :lisp-stat
577 slot-value call-method call-next-method ;; objects
578 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
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)
585 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
586 almost= almost=lists numerical=)) ; compare
588 (defpackage :lisp-stat-data-clos-example
589 (:use :common-lisp
590 :lift :lisp-stat-unittests
591 :lisp-stat-data-examples
592 :lisp-stat-data-clos)
593 (:export absorbtion aluminum iron))
596 (defpackage :lisp-stat-optimize
597 (:use :common-lisp
598 :cffi
599 :lisp-matrix
600 :lisp-stat-ffi-int
601 :lisp-stat-object-system
602 :lisp-stat-types
603 :lisp-stat-compound-data
604 :lisp-stat-math
605 :lisp-stat-float
606 :lisp-stat-basics
608 :lisp-stat-matrix
609 :lisp-stat-linalg-data
610 :lisp-stat-linalg
613 (:shadowing-import-from :lisp-stat-object-system
614 slot-value call-method call-next-method)
615 (:shadowing-import-from :lisp-stat-math
616 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
617 asin acos atan sinh cosh tanh asinh acosh atanh float random
618 truncate floor ceiling round minusp zerop plusp evenp oddp
619 < <= = /= >= > complex conjugate realpart imagpart phase
620 min max logand logior logxor lognot ffloor fceiling
621 ftruncate fround signum cis)
622 (:export
623 ;; derivatives
624 numgrad numhess
626 ;; optimization
627 newtonmax nelmeadmax))