start of cl-plplot code
[CommonLispStat.git] / src / packages.lisp
blob1feb8e6e8bd36df01851bd2b41435c4a6a33f0d9
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-03-18 12:12:51 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
111 (defpackage :lisp-stat-data-clos
112 (:use :common-lisp
113 :lisp-matrix)
114 (:export
115 ;; generic container class for data -- if small enough
116 ;; could be value, otherwise might be reference.
117 dataframe-like
118 dataframe-array
119 get-variable-matrix get-variable-vector
120 data-pointer))
123 (defpackage :lisp-stat-regression-linear-clos
124 (:use :common-lisp
125 :lisp-matrix
126 :lisp-stat-data-clos)
127 (:export regression-model))
130 (defpackage :lisp-stat-visualize
131 (:use :common-lisp
132 :lisp-matrix
133 :lisp-stat-data-clos))
135 (defpackage :lisp-stat-visualize-plplot
136 (:use :common-lisp
137 :lisp-matrix
138 :lisp-stat-data-clos
139 :cl-plplot-system)
140 (:export
141 plot-ex
142 contour-plot-ex
143 fn-contour-plot-ex
144 shade-plot-ex
145 3D-plot-ex ))
148 ;;; USER PACKAGES
150 (defpackage :lisp-stat-ffi-int
151 (:use :common-lisp
152 :cffi)
153 (:export ccl-store-integer ccl-store-double ccl-store-ptr
154 get-buf ))
156 (defpackage :lisp-stat-probability
157 (:use :common-lisp
158 :cffi
159 :lisp-stat-ffi-int
160 :lisp-stat-macros)
161 (:export log-gamma set-seed
162 uniform-rand
163 normal-cdf normal-quant normal-dens normal-rand
164 bivnorm-cdf
165 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
166 gamma-cdf gamma-quant gamma-dens gamma-rand
167 chisq-cdf chisq-quant chisq-dens chisq-rand
168 beta-cdf beta-quant beta-dens beta-rand
169 t-cdf t-quant t-dens t-rand
170 f-cdf f-quant f-dens f-rand
171 poisson-cdf poisson-quant poisson-pmf poisson-rand
172 binomial-cdf binomial-quant binomial-pmf binomial-rand))
175 #| removed, replace by lisp-matrix
176 (defpackage :lisp-stat-matrix
177 (:use :common-lisp
178 :cffi
179 :lisp-stat-compound-data)
180 (:export matrixp ;; matrix -- conflicts!
181 num-rows num-cols matmult identity-matrix diagonal
182 row-list column-list inner-product outer-product
183 cross-product
184 ;; transpose bind-columns bind-rows
185 array-data-vector vector-to-array
187 check-matrix check-square-matrix
189 copy-array copy-vector
193 #| replaced by lisp-matrix
194 (defpackage :lisp-stat-linalg-data
195 (:use :common-lisp
196 :cffi
197 :lisp-stat-ffi-int
198 :lisp-stat-types
199 :lisp-stat-compound-data
200 :lisp-stat-matrix)
201 (:export ;; more to add
202 +mode-in+ +mode-re+ +mode-cx+ mode-of
204 la-data-mode la-allocate la-free
206 la-get-double la-put-double
207 la-put-integer
209 la-matrix la-free-matrix la-matrix-to-data la-data-to-matrix
210 la-vector la-free-vector la-vector-to-data la-data-to-vector ))
213 (defpackage :lisp-stat-math
214 (:use :common-lisp
215 :lisp-stat-object-system
216 :lisp-stat-macros
217 :lisp-stat-compound-data
218 :lisp-stat-float)
219 (:shadowing-import-from :lisp-stat-object-system
220 slot-value call-method call-next-method)
221 (:shadow expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
222 asin acos atan sinh cosh tanh asinh acosh atanh float random
223 truncate floor ceiling round minusp zerop plusp evenp oddp
224 < <= = /= >= > ;; complex
225 conjugate realpart imagpart phase
226 min max logand logior logxor lognot ffloor fceiling
227 ftruncate fround signum cis)
228 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
229 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
230 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
231 /= >= > ;; complex
232 conjugate realpart imagpart phase min max
233 logand logior logxor lognot ffloor fceiling ftruncate fround
234 signum cis)
235 (:documentation "Vectorization of numerical functions"))
238 #| ;; some of this goes back in, but not all of it?
239 (defpackage :lisp-stat-linalg
240 (:use :common-lisp
241 :cffi
242 :lisp-matrix
243 :lisp-stat-math
244 :lisp-stat-types
245 :lisp-stat-float
246 :lisp-stat-compound-data)
247 (:shadowing-import-from :lisp-stat-math
248 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
249 asin acos atan sinh cosh tanh asinh acosh atanh float random
250 truncate floor ceiling round minusp zerop plusp evenp oddp
251 < <= = /= >= > complex conjugate realpart imagpart phase
252 min max logand logior logxor lognot ffloor fceiling
253 ftruncate fround signum cis)
254 (:export chol-decomp lu-decomp lu-solve determinant inverse
255 sv-decomp qr-decomp rcondest make-rotation spline
256 kernel-dens kernel-smooth
257 fft make-sweep-matrix sweep-operator ax+y eigen
259 check-real ;; for optimize
261 covariance-matrix matrix print-matrix solve
262 backsolve eigenvalues eigenvectors accumulate cumsum combine
263 lowess))
270 (defpackage :lisp-stat-data
271 (:documentation "Data management, integration, I/O, and other data technologies.")
272 (:nicknames :ls-data)
273 (:use :common-lisp
274 :lisp-stat-object-system
275 :lisp-stat-config
276 :lisp-stat-types
277 :lisp-stat-compound-data)
278 (:shadowing-import-from :lisp-stat-object-system
279 slot-value call-method call-next-method)
280 (:export open-file-dialog read-data-file read-data-columns load-data
281 load-example *variables* *ask-on-redefine*
282 def variables savevar undef))
284 (defpackage :lisp-stat-descriptive-statistics
285 (:use :common-lisp
286 :lisp-stat-data
287 :lisp-stat-math
288 :lisp-stat-compound-data
289 :lisp-matrix
290 :lisp-stat-basics)
291 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
292 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
293 asin acos atan sinh cosh tanh asinh acosh atanh float random
294 truncate floor ceiling round minusp zerop plusp evenp oddp
295 < <= = /= >= > ;; complex
296 conjugate realpart imagpart phase
297 min max logand logior logxor lognot ffloor fceiling
298 ftruncate fround signum cis)
299 (:export standard-deviation
300 quantile median interquartile-range
301 fivnum sample))
304 (defpackage :lisp-stat-regression-linear
305 (:use :common-lisp
306 :lisp-matrix
307 :lisp-stat-object-system
308 :lisp-stat-basics
309 :lisp-stat-compound-data
310 :lisp-stat-descriptive-statistics
312 :lisp-stat-math
315 (:shadowing-import-from :lisp-stat-object-system
316 slot-value call-method call-next-method)
318 (:shadowing-import-from :lisp-stat-math
319 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
320 asin acos atan sinh cosh tanh asinh acosh atanh float random
321 truncate floor ceiling round minusp zerop plusp evenp oddp
322 < <= = /= >= > ;; complex
323 conjugate realpart imagpart phase
324 min max logand logior logxor lognot ffloor fceiling
325 ftruncate fround signum cis)
327 (:export regression-model regression-model-proto x y intercept
328 ;; sweep-matrix
329 basis weights included
330 total-sum-of-squares residual-sum-of-squares
331 predictor-names response-name case-labels
332 ;; functions for helpers
333 lm xtxinv ))
335 (defpackage :lisp-stat
336 (:documentation "Experimentation package for LispStat. Serious
337 work should be packaged up elsewhere for reproducibility. By this
338 I mean, creating a data/analytics/analysis package with the
339 minimal set of objects required.")
340 (:use :common-lisp
341 :lisp-stat-object-system
342 :lisp-stat-compound-data
343 :lisp-stat-probability
344 :lisp-stat-types
345 :lisp-stat-float
346 :lisp-stat-basics
347 :lisp-stat-data
348 :lisp-stat-data-clos
349 :lisp-stat-math
350 :lisp-matrix ;; conversion to a more robust linalg approach
351 :lisp-stat-descriptive-statistics
352 :lisp-stat-regression-linear
353 :cybertiggyr-dsv)
354 (:shadowing-import-from :lisp-stat-object-system
355 slot-value call-method call-next-method)
356 (:shadowing-import-from :lisp-stat-math
357 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
358 asin acos atan sinh cosh tanh asinh acosh atanh float random
359 truncate floor ceiling round minusp zerop plusp evenp oddp
360 < <= = /= >= >
361 ;;complex
362 conjugate realpart imagpart phase
364 min max
365 logand logior logxor lognot
366 ffloor fceiling ftruncate fround
367 signum cis)
368 (:export
369 ;; lsobjects :
370 defproto defproto2
371 defmeth send
373 ;; lstypes :
374 fixnump check-nonneg-fixnum check-one-fixnum
375 check-one-real check-one-number
377 ;; lsmacros:
379 ;; lsfloat :
380 machine-epsilon
382 ;; compound :
383 compound-data-p *compound-data-proto* compound-object-p
384 compound-data-seq compound-data-length
385 element-list element-seq
386 sort-data order rank
387 recursive-map-elements map-elements
388 repeat
389 check-sequence
390 get-next-element make-next-element set-next-element
391 ;; sequencep
392 iseq
393 ordered-nneg-seq
394 select which
395 difference rseq
397 ;; lsmath.lsp
398 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
399 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
400 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
401 /= >= > ;; complex
402 conjugate realpart imagpart phase min max
403 logand logior logxor lognot ffloor fceiling ftruncate fround
404 signum cis
406 #| ;; The following need to be re-found in lisp-matrix...
408 ;; matrices.lisp
409 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
410 column-list inner-product outer-product cross-product transpose
411 bind-columns bind-rows
413 ;; linalg.lisp
414 chol-decomp lu-decomp lu-solve determinant inverse
415 sv-decomp qr-decomp rcondest make-rotation spline
416 kernel-dens kernel-smooth
417 fft make-sweep-matrix sweep-operator ax+y eigen
418 check-real
419 covariance-matrix matrix print-matrix solve
420 backsolve eigenvalues eigenvectors accumulate cumsum combine
421 lowess
423 ;; in linalg.lisp, possibly not supported by matlisp
424 spline kernel-dens kernel-smooth
428 ;; optimize.lsp
429 newtonmax nelmeadmax
431 ;; lispstat-macros
432 make-rv-function make-rv-function-1
434 ;; data
435 open-file-dialog read-data-file read-data-columns load-data
436 load-example *variables* *ask-on-redefine*
437 def variables savevar undef
439 ;; data-clos
440 dataframe-like
441 dataframe-array
445 ;; statistics.lsp (descriptions, should probably be moved
446 ;; later...?
447 standard-deviation quantile median interquartile-range
448 fivnum sample
450 ;; probability (dists.lisp)
451 log-gamma set-seed
452 uniform-rand normal-cdf normal-quant normal-dens
453 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
454 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
455 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
456 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
457 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
458 binomial-cdf binomial-quant binomial-pmf binomial-rand
460 ;; Here is where we have a problem -- lispstat core should be core
461 ;; data management and config problems, with packages providing
462 ;; specialized extensions to LispStat, i.e. regression, nonlin
463 ;; regression, bayesian regression via laplace approximation, etc.
465 ;; The following could be considered "recommended packages",
466 ;; similar to the idea of the recommended packages in R. Probably
467 ;; we want them to do the exporting within that package, therefore
468 ;; NOT being able to lock the "data-ish" package, but only the
469 ;; subpackages prior to export.
471 ;; regression.lsp
472 ;; -- linear regressin models.
473 regression-model regression-model-proto x y intercept sweep-matrix
474 basis weights included total-sum-of-squares residual-sum-of-squares
475 predictor-names response-name case-labels
476 lm xtxinv
478 ;; nonlin.lsp
479 ;; -- nonlinear regression models
480 nreg-model nreg-model-proto mean-function theta-hat epsilon
481 count-limit verbose
482 ;; we might need something like xtxinv here? But should be
483 ;; encapsulated, so we use the one in regression.lisp
485 ;; bayes.lsp
486 bayes-model bayes-model-proto bayes-internals
489 ;; plots.lisp
490 plot-ex
491 contour-plot-ex
492 fn-contour-plot-ex
493 shade-plot-ex
494 3D-plot-ex
499 ;;;; PACKAGES FOR USEABILITY
501 (defpackage :lisp-stat-data-examples
502 (:documentation "Example data for unittests, examples, illustrations,")
503 (:use :common-lisp
504 :lisp-stat)
505 (:shadowing-import-from :lisp-stat
506 slot-value call-method call-next-method
508 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
509 asin acos atan sinh cosh tanh asinh acosh atanh float random
510 truncate floor ceiling round minusp zerop plusp evenp oddp
511 < <= = /= >= > > ;; complex
512 conjugate realpart imagpart phase
513 min max logand logior logxor lognot ffloor fceiling
514 ftruncate fround signum cis
516 <= float imagpart)
517 (:export iron aluminum absorbtion
518 diabetes dlabs))
521 (defpackage :lisp-stat-user
522 (:documentation "Experimentation package for LispStat.
523 Serious work should be placed in a similar package elsewhere for
524 reproducibility. But this should hint as to what needs to be
525 done for a user- or analysis-package.")
526 (:nicknames :ls-user)
527 (:use :common-lisp
528 :lisp-matrix
529 :lisp-stat
530 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
531 (:shadowing-import-from :lisp-stat
532 slot-value call-method call-next-method
534 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
535 asin acos atan sinh cosh tanh asinh acosh atanh float random
536 truncate floor ceiling round minusp zerop plusp evenp oddp
537 < <= = /= >= > > ;; complex
538 conjugate realpart imagpart phase
539 min max logand logior logxor lognot ffloor fceiling
540 ftruncate fround signum cis
542 <= float imagpart))
544 (defpackage :lisp-stat-unittests
545 (:use :common-lisp :lift :lisp-stat :lisp-stat-data-examples)
546 (:shadowing-import-from :lisp-stat
547 slot-value call-method call-next-method ;; objects
548 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
549 asin acos atan sinh cosh tanh asinh acosh atanh float random
550 truncate floor ceiling round minusp zerop plusp evenp oddp
551 < <= = /= >= > ;; complex
552 conjugate realpart imagpart phase
553 min max logand logior logxor lognot ffloor fceiling
554 ftruncate fround signum cis)
555 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
556 almost= almost=lists numerical=)) ; compare
558 (defpackage :lisp-stat-data-clos-example
559 (:use :common-lisp
560 :lift :lisp-stat-unittests
561 :lisp-stat-data-examples
562 :lisp-stat-data-clos)
563 (:export absorbtion aluminum iron))
566 (defpackage :lisp-stat-optimize
567 (:use :common-lisp
568 :cffi
569 :lisp-matrix
570 :lisp-stat-ffi-int
571 :lisp-stat-object-system
572 :lisp-stat-types
573 :lisp-stat-compound-data
574 :lisp-stat-math
575 :lisp-stat-float
576 :lisp-stat-basics
578 :lisp-stat-matrix
579 :lisp-stat-linalg-data
580 :lisp-stat-linalg
583 (:shadowing-import-from :lisp-stat-object-system
584 slot-value call-method call-next-method)
585 (:shadowing-import-from :lisp-stat-math
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 conjugate realpart imagpart phase
590 min max logand logior logxor lognot ffloor fceiling
591 ftruncate fround signum cis)
592 (:export
593 ;; derivatives
594 numgrad numhess
596 ;; optimization
597 newtonmax nelmeadmax))