more slot-value to proto-slot-value fixes.
[CommonLispStat.git] / src / packages.lisp
blobf6fc88b6209029b9de83e9f84b380a404077b4d2
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-03-31 17:25:41 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)
26 (:export ls-object objectp *object* kind-of-p make-object
27 *message-hook*
28 *set-slot-hook* proto-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 call-next-method call-method)
59 (:export compound-data-p *compound-data-proto*
60 compound-object-p
61 compound-data-seq compound-data-length
62 element-list element-seq
63 sort-data order rank
64 recursive-map-elements map-elements repeat
65 check-sequence
66 get-next-element make-next-element set-next-element
67 ;; sequencep
68 iseq ordered-nneg-seq
69 select split-list which
70 difference rseq
71 flatten-list))
73 (defpackage :lisp-stat-macros
74 (:use :common-lisp
75 :lisp-stat-compound-data)
76 (:export make-rv-function make-rv-function-1))
78 (defpackage :lisp-stat-basics
79 (:use :common-lisp
80 :lisp-stat-object-system
81 :lisp-stat-types
82 :lisp-stat-float
83 :lisp-stat-macros
84 :lisp-stat-compound-data)
85 (:shadowing-import-from :lisp-stat-object-system
86 call-method call-next-method)
87 (:export permute-array sum prod count-elements mean
88 if-else sample))
90 (defpackage :lisp-stat-float
91 (:use :common-lisp)
92 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
93 machine-epsilon base-float makedouble
95 make-base-trans-fun-2 make-base-trans-fun
97 BASE-LOG BASE-EXP BASE-EXPT BASE-SQRT BASE-SIN BASE-COS
98 BASE-TAN BASE-ASIN BASE-ACOS BASE-ATAN BASE-SINH
99 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
100 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
101 BASE-FROUND BASE-SIGNUM BASE-CIS))
103 (defpackage :lisp-stat-macros
104 (:use :common-lisp
105 :lisp-stat-compound-data)
106 (:export make-rv-function make-rv-function-1))
108 ;;; NEW CLOS STRUCTURE
112 (defpackage :lisp-stat-data-clos
113 (:use :common-lisp
114 :lisp-matrix)
115 (:export
116 ;; generic container class for data -- if small enough
117 ;; could be value, otherwise might be reference.
118 dataframe-like
119 dataframe-array
120 make-dataframe
122 ;; accessors
123 varlabels caselabels nrows ncols
124 dataframe-dimension dataframe-dimensons
125 dfref dfref-case dfref-var
126 consistent-dataframe-p
128 dataset
129 list-of-columns ;; list-of-variables
130 list-of-rows ;; list-of-observations
134 (defpackage :cls-data-listoflist
135 (:use :common-lisp
136 :lisp-stat-data-clos) ; for dataframe
137 (:export lists-of-same-size
138 equal-listoflist
139 transpose-listoflist
140 make-dataframe-from-listoflist
141 make-array-from-listoflist))
144 (defpackage :lisp-stat-regression-linear-clos
145 (:use :common-lisp
146 :lisp-matrix
147 :lisp-stat-data-clos)
148 (:export regression-model))
151 (defpackage :lisp-stat-visualize
152 (:use :common-lisp
153 :lisp-matrix
154 :lisp-stat-data-clos))
156 (defpackage :lisp-stat-visualize-plplot
157 (:use :common-lisp
158 :lisp-matrix
159 :lisp-stat-data-clos
160 :cl-plplot-system)
161 (:export
162 plot-ex
163 contour-plot-ex
164 fn-contour-plot-ex
165 shade-plot-ex
166 3D-plot-ex ))
169 ;;; USER PACKAGES
171 (defpackage :lisp-stat-ffi-int
172 (:use :common-lisp
173 :cffi)
174 (:export ccl-store-integer ccl-store-double ccl-store-ptr
175 get-buf ))
177 (defpackage :lisp-stat-probability
178 (:use :common-lisp
179 :cffi
180 :lisp-stat-ffi-int
181 :lisp-stat-macros)
182 (:export log-gamma set-seed
183 uniform-rand
184 normal-cdf normal-quant normal-dens normal-rand
185 bivnorm-cdf
186 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
187 gamma-cdf gamma-quant gamma-dens gamma-rand
188 chisq-cdf chisq-quant chisq-dens chisq-rand
189 beta-cdf beta-quant beta-dens beta-rand
190 t-cdf t-quant t-dens t-rand
191 f-cdf f-quant f-dens f-rand
192 poisson-cdf poisson-quant poisson-pmf poisson-rand
193 binomial-cdf binomial-quant binomial-pmf binomial-rand))
196 #| removed, replace by lisp-matrix
197 (defpackage :lisp-stat-matrix
198 (:use :common-lisp
199 :cffi
200 :lisp-stat-compound-data)
201 (:export matrixp ;; matrix -- conflicts!
202 num-rows num-cols matmult identity-matrix diagonal
203 row-list column-list inner-product outer-product
204 cross-product
205 ;; transpose bind-columns bind-rows
206 array-data-vector vector-to-array
208 check-matrix check-square-matrix
210 copy-array copy-vector
214 #| replaced by lisp-matrix
215 (defpackage :lisp-stat-linalg-data
216 (:use :common-lisp
217 :cffi
218 :lisp-stat-ffi-int
219 :lisp-stat-types
220 :lisp-stat-compound-data
221 :lisp-stat-matrix)
222 (:export ;; more to add
223 +mode-in+ +mode-re+ +mode-cx+ mode-of
225 la-data-mode la-allocate la-free
227 la-get-double la-put-double
228 la-put-integer
230 la-matrix la-free-matrix la-matrix-to-data la-data-to-matrix
231 la-vector la-free-vector la-vector-to-data la-data-to-vector ))
234 (defpackage :lisp-stat-math
235 (:use :common-lisp
236 :lisp-stat-object-system
237 :lisp-stat-macros
238 :lisp-stat-compound-data
239 :lisp-stat-float)
240 (:shadowing-import-from :lisp-stat-object-system
241 call-method call-next-method)
242 (:shadow expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
243 asin acos atan sinh cosh tanh asinh acosh atanh float random
244 truncate floor ceiling round minusp zerop plusp evenp oddp
245 < <= = /= >= > ;; complex
246 conjugate realpart imagpart phase
247 min max logand logior logxor lognot ffloor fceiling
248 ftruncate fround signum cis)
249 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
250 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
251 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
252 /= >= > ;; complex
253 conjugate realpart imagpart phase min max
254 logand logior logxor lognot ffloor fceiling ftruncate fround
255 signum cis)
256 (:documentation "Vectorization of numerical functions"))
259 #| ;; some of this goes back in, but not all of it?
260 (defpackage :lisp-stat-linalg
261 (:use :common-lisp
262 :cffi
263 :lisp-matrix
264 :lisp-stat-math
265 :lisp-stat-types
266 :lisp-stat-float
267 :lisp-stat-compound-data)
268 (:shadowing-import-from :lisp-stat-math
269 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
270 asin acos atan sinh cosh tanh asinh acosh atanh float random
271 truncate floor ceiling round minusp zerop plusp evenp oddp
272 < <= = /= >= > complex conjugate realpart imagpart phase
273 min max logand logior logxor lognot ffloor fceiling
274 ftruncate fround signum cis)
275 (:export chol-decomp lu-decomp lu-solve determinant inverse
276 sv-decomp qr-decomp rcondest make-rotation spline
277 kernel-dens kernel-smooth
278 fft make-sweep-matrix sweep-operator ax+y eigen
280 check-real ;; for optimize
282 covariance-matrix matrix print-matrix solve
283 backsolve eigenvalues eigenvectors accumulate cumsum combine
284 lowess))
291 (defpackage :lisp-stat-data
292 (:documentation "Data management, integration, I/O, and other data technologies.")
293 (:nicknames :ls-data)
294 (:use :common-lisp
295 :lisp-stat-object-system
296 :lisp-stat-config
297 :lisp-stat-types
298 :lisp-stat-compound-data)
299 (:shadowing-import-from :lisp-stat-object-system
300 call-method call-next-method)
301 (:export open-file-dialog read-data-file read-data-columns load-data
302 load-example *variables* *ask-on-redefine*
303 def variables savevar undef))
305 (defpackage :lisp-stat-descriptive-statistics
306 (:use :common-lisp
307 :lisp-stat-data
308 :lisp-stat-math
309 :lisp-stat-compound-data
310 :lisp-matrix
311 :lisp-stat-basics)
312 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
313 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
314 asin acos atan sinh cosh tanh asinh acosh atanh float random
315 truncate floor ceiling round minusp zerop plusp evenp oddp
316 < <= = /= >= > ;; complex
317 conjugate realpart imagpart phase
318 min max logand logior logxor lognot ffloor fceiling
319 ftruncate fround signum cis)
320 (:export standard-deviation
321 quantile median interquartile-range
322 fivnum sample))
325 (defpackage :lisp-stat-regression-linear
326 (:use :common-lisp
327 :lisp-matrix
328 :lisp-stat-object-system
329 :lisp-stat-basics
330 :lisp-stat-compound-data
331 :lisp-stat-descriptive-statistics
333 :lisp-stat-math
336 (:shadowing-import-from :lisp-stat-object-system
337 call-method call-next-method)
339 (:shadowing-import-from :lisp-stat-math
340 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
341 asin acos atan sinh cosh tanh asinh acosh atanh float random
342 truncate floor ceiling round minusp zerop plusp evenp oddp
343 < <= = /= >= > ;; complex
344 conjugate realpart imagpart phase
345 min max logand logior logxor lognot ffloor fceiling
346 ftruncate fround signum cis)
348 (:export regression-model regression-model-proto x y intercept
349 ;; sweep-matrix
350 basis weights included
351 total-sum-of-squares residual-sum-of-squares
352 predictor-names response-name case-labels
353 ;; functions for helpers
354 lm xtxinv ))
356 (defpackage :lisp-stat
357 (:documentation "Experimentation package for LispStat. Serious
358 work should be packaged up elsewhere for reproducibility. By this
359 I mean, creating a data/analytics/analysis package with the
360 minimal set of objects required.")
361 (:use :common-lisp
362 :lisp-stat-object-system
363 :lisp-stat-compound-data
364 :lisp-stat-probability
365 :lisp-stat-types
366 :lisp-stat-float
367 :lisp-stat-basics
368 :lisp-stat-data
369 :lisp-stat-data-clos
370 :lisp-stat-math
371 :lisp-matrix ;; conversion to a more robust linalg approach
372 :lisp-stat-descriptive-statistics
373 :lisp-stat-regression-linear
374 :cybertiggyr-dsv)
375 (:shadowing-import-from :lisp-stat-object-system
376 call-method call-next-method)
377 (:shadowing-import-from :lisp-stat-math
378 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
379 asin acos atan sinh cosh tanh asinh acosh atanh float random
380 truncate floor ceiling round minusp zerop plusp evenp oddp
381 < <= = /= >= >
382 ;;complex
383 conjugate realpart imagpart phase
385 min max
386 logand logior logxor lognot
387 ffloor fceiling ftruncate fround
388 signum cis)
389 (:export
390 ;; lsobjects :
391 defproto defproto2
392 defmeth send
394 ;; lstypes :
395 fixnump check-nonneg-fixnum check-one-fixnum
396 check-one-real check-one-number
398 ;; lsmacros:
400 ;; lsfloat :
401 machine-epsilon
403 ;; compound :
404 compound-data-p *compound-data-proto* compound-object-p
405 compound-data-seq compound-data-length
406 element-list element-seq
407 sort-data order rank
408 recursive-map-elements map-elements
409 repeat
410 check-sequence
411 get-next-element make-next-element set-next-element
412 ;; sequencep
413 iseq
414 ordered-nneg-seq
415 select which
416 difference rseq
418 ;; lsmath.lsp
419 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
420 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
421 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
422 /= >= > ;; complex
423 conjugate realpart imagpart phase min max
424 logand logior logxor lognot ffloor fceiling ftruncate fround
425 signum cis
427 #| ;; The following need to be re-found in lisp-matrix...
429 ;; matrices.lisp
430 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
431 column-list inner-product outer-product cross-product transpose
432 bind-columns bind-rows
434 ;; linalg.lisp
435 chol-decomp lu-decomp lu-solve determinant inverse
436 sv-decomp qr-decomp rcondest make-rotation spline
437 kernel-dens kernel-smooth
438 fft make-sweep-matrix sweep-operator ax+y eigen
439 check-real
440 covariance-matrix matrix print-matrix solve
441 backsolve eigenvalues eigenvectors accumulate cumsum combine
442 lowess
444 ;; in linalg.lisp, possibly not supported by matlisp
445 spline kernel-dens kernel-smooth
449 ;; optimize.lsp
450 newtonmax nelmeadmax
452 ;; lispstat-macros
453 make-rv-function make-rv-function-1
455 ;; data
456 open-file-dialog read-data-file read-data-columns load-data
457 load-example *variables* *ask-on-redefine*
458 def variables savevar undef
460 ;; data-clos
461 dataframe-like dataframe-array make-dataframe
462 varlabels caselabels nrows ncols
463 dataframe-dimension dataframe-dimensons
464 dfref dfref-case dfref-var
465 consistent-dataframe-p
466 dataset
467 list-of-columns list-of-rows
469 ;; listoflist
470 lists-of-same-size equal-listoflist
471 transpose-listoflist
472 make-dataframe-from-listoflist make-array-from-listoflist
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 regression-model-proto x y intercept sweep-matrix
503 basis weights included total-sum-of-squares residual-sum-of-squares
504 predictor-names response-name case-labels
505 lm xtxinv
507 ;; nonlin.lsp
508 ;; -- nonlinear regression models
509 nreg-model nreg-model-proto mean-function theta-hat epsilon
510 count-limit verbose
511 ;; we might need something like xtxinv here? But should be
512 ;; encapsulated, so we use the one in regression.lisp
514 ;; bayes.lsp
515 bayes-model bayes-model-proto bayes-internals
518 ;; plots.lisp
519 plot-ex
520 contour-plot-ex
521 fn-contour-plot-ex
522 shade-plot-ex
523 3D-plot-ex
528 ;;;; PACKAGES FOR USEABILITY
530 (defpackage :lisp-stat-data-examples
531 (:documentation "Example data for unittests, examples, illustrations,")
532 (:use :common-lisp
533 :lisp-stat)
534 (:shadowing-import-from :lisp-stat
535 call-method call-next-method
537 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
538 asin acos atan sinh cosh tanh asinh acosh atanh float random
539 truncate floor ceiling round minusp zerop plusp evenp oddp
540 < <= = /= >= > > ;; complex
541 conjugate realpart imagpart phase
542 min max logand logior logxor lognot ffloor fceiling
543 ftruncate fround signum cis
545 <= float imagpart)
546 (:export iron aluminum absorbtion
547 diabetes dlabs))
550 (defpackage :lisp-stat-user
551 (:documentation "Experimentation package for LispStat.
552 Serious work should be placed in a similar package elsewhere for
553 reproducibility. But this should hint as to what needs to be
554 done for a user- or analysis-package.")
555 (:nicknames :ls-user)
556 (:use :common-lisp
557 :lisp-matrix
558 :lisp-stat
559 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
560 (:shadowing-import-from :lisp-stat
561 call-method call-next-method
563 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
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
571 <= float imagpart))
573 (defpackage :lisp-stat-unittests
574 (:use :common-lisp :lift :lisp-stat :lisp-stat-data-examples)
575 (:shadowing-import-from :lisp-stat
576 call-method call-next-method ;; objects
577 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
578 asin acos atan sinh cosh tanh asinh acosh atanh float random
579 truncate floor ceiling round minusp zerop plusp evenp oddp
580 < <= = /= >= > ;; complex
581 conjugate realpart imagpart phase
582 min max logand logior logxor lognot ffloor fceiling
583 ftruncate fround signum cis)
584 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
585 almost= almost=lists numerical=)) ; compare
587 (defpackage :lisp-stat-data-clos-example
588 (:use :common-lisp
589 :lift :lisp-stat-unittests
590 :lisp-stat-data-examples
591 :lisp-stat-data-clos)
592 (:export absorbtion aluminum iron))
595 (defpackage :lisp-stat-optimize
596 (:use :common-lisp
597 :cffi
598 :lisp-matrix
599 :lisp-stat-ffi-int
600 :lisp-stat-object-system
601 :lisp-stat-types
602 :lisp-stat-compound-data
603 :lisp-stat-math
604 :lisp-stat-float
605 :lisp-stat-basics
607 :lisp-stat-matrix
608 :lisp-stat-linalg-data
609 :lisp-stat-linalg
612 (:shadowing-import-from :lisp-stat-object-system
613 call-method call-next-method)
614 (:shadowing-import-from :lisp-stat-math
615 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
616 asin acos atan sinh cosh tanh asinh acosh atanh float random
617 truncate floor ceiling round minusp zerop plusp evenp oddp
618 < <= = /= >= > complex conjugate realpart imagpart phase
619 min max logand logior logxor lognot ffloor fceiling
620 ftruncate fround signum cis)
621 (:export
622 ;; derivatives
623 numgrad numhess
625 ;; optimization
626 newtonmax nelmeadmax))