lisp-stat-model package (still need to add to ASDF).
[CommonLispStat.git] / src / packages.lisp
blob782db18e1e5084dbc79788abb2f16d40caff3097
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-04-09 13:29:32 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 ;;; Basics
23 (defpackage :lisp-stat-object-system
24 (:nicknames :ls-objects :lsos)
25 (:use :common-lisp)
26 (:shadow :call-method :call-next-method)
27 (:export ls-object objectp *object* kind-of-p make-object
28 *message-hook*
29 *set-slot-hook* proto-slot-value self
30 send call-next-method call-method
31 defmeth defproto instance-slots proto-name))
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 (defpackage :lisp-stat-compound-data
55 (:use :common-lisp
56 :lisp-stat-object-system
57 :lisp-stat-types)
58 (:shadowing-import-from :lisp-stat-object-system
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 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-dataframe
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-dataframe) ; for dataframe
138 (:export lists-of-same-size
139 equal-listoflist
140 transpose-listoflist
141 make-dataframe-from-listoflist
142 make-array-from-listoflist))
144 (defpackage :lisp-stat-model
145 (:documentation "Model management for data analysis.")
146 (:use :common-lisp
147 :lisp-matrix)
148 (:export
149 ;; data structures for model and model/data combination
150 model statistical-model analysis))
153 (defpackage :lisp-stat-regression-linear-clos
154 (:use :common-lisp
155 :lisp-matrix
156 :lisp-stat-dataframe)
157 (:export regression-model))
160 (defpackage :lisp-stat-visualize
161 (:use :common-lisp
162 :lisp-matrix
163 :lisp-stat-dataframe))
165 (defpackage :lisp-stat-visualize-plplot
166 (:use :common-lisp
167 :lisp-matrix
168 :lisp-stat-dataframe
169 :cl-plplot-system)
170 (:export
171 plot-ex
172 contour-plot-ex
173 fn-contour-plot-ex
174 shade-plot-ex
175 3D-plot-ex ))
178 ;;; USER PACKAGES
180 (defpackage :lisp-stat-ffi-int
181 (:use :common-lisp
182 :cffi)
183 (:export ccl-store-integer ccl-store-double ccl-store-ptr
184 get-buf ))
186 (defpackage :lisp-stat-probability
187 (:use :common-lisp
188 :cffi
189 :lisp-stat-ffi-int
190 :lisp-stat-macros)
191 (:export log-gamma set-seed
192 uniform-rand
193 normal-cdf normal-quant normal-dens normal-rand
194 bivnorm-cdf
195 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
196 gamma-cdf gamma-quant gamma-dens gamma-rand
197 chisq-cdf chisq-quant chisq-dens chisq-rand
198 beta-cdf beta-quant beta-dens beta-rand
199 t-cdf t-quant t-dens t-rand
200 f-cdf f-quant f-dens f-rand
201 poisson-cdf poisson-quant poisson-pmf poisson-rand
202 binomial-cdf binomial-quant binomial-pmf binomial-rand))
206 (defpackage :lisp-stat-math
207 (:use :common-lisp
208 :lisp-stat-object-system
209 :lisp-stat-macros
210 :lisp-stat-compound-data
211 :lisp-stat-float)
212 (:shadowing-import-from :lisp-stat-object-system
213 call-method call-next-method)
214 (:shadow expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
215 asin acos atan sinh cosh tanh asinh acosh atanh float random
216 truncate floor ceiling round minusp zerop plusp evenp oddp
217 < <= = /= >= > ;; complex
218 conjugate realpart imagpart phase
219 min max logand logior logxor lognot ffloor fceiling
220 ftruncate fround signum cis)
221 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
222 tan 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 min max
226 logand logior logxor lognot ffloor fceiling ftruncate fround
227 signum cis)
228 (:documentation "Vectorization of numerical functions"))
231 #| ;; some of this goes back in, but not all of it?
232 (defpackage :lisp-stat-linalg
233 (:use :common-lisp
234 :cffi
235 :lisp-matrix
236 :lisp-stat-math
237 :lisp-stat-types
238 :lisp-stat-float
239 :lisp-stat-compound-data)
240 (:shadowing-import-from :lisp-stat-math
241 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
242 asin acos atan sinh cosh tanh asinh acosh atanh float random
243 truncate floor ceiling round minusp zerop plusp evenp oddp
244 < <= = /= >= > complex conjugate realpart imagpart phase
245 min max logand logior logxor lognot ffloor fceiling
246 ftruncate fround signum cis)
247 (:export chol-decomp lu-decomp lu-solve determinant inverse
248 sv-decomp qr-decomp rcondest make-rotation spline
249 kernel-dens kernel-smooth
250 fft make-sweep-matrix sweep-operator ax+y eigen
252 check-real ;; for optimize
254 covariance-matrix matrix print-matrix solve
255 backsolve eigenvalues eigenvectors accumulate cumsum combine
256 lowess))
263 (defpackage :lisp-stat-data
264 (:documentation "Data management, integration, I/O, and other data technologies.")
265 (:nicknames :ls-data)
266 (:use :common-lisp
267 :lisp-stat-object-system
268 :lisp-stat-config
269 :lisp-stat-types
270 :lisp-stat-compound-data)
271 (:shadowing-import-from :lisp-stat-object-system
272 call-method call-next-method)
273 (:export open-file-dialog read-data-file read-data-columns load-data
274 load-example *variables* *ask-on-redefine*
275 def variables savevar undef))
277 (defpackage :lisp-stat-descriptive-statistics
278 (:use :common-lisp
279 :lisp-stat-data
280 :lisp-stat-math
281 :lisp-stat-compound-data
282 :lisp-matrix
283 :lisp-stat-basics)
284 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
285 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
286 asin acos atan sinh cosh tanh asinh acosh atanh float random
287 truncate floor ceiling round minusp zerop plusp evenp oddp
288 < <= = /= >= > ;; complex
289 conjugate realpart imagpart phase
290 min max logand logior logxor lognot ffloor fceiling
291 ftruncate fround signum cis)
292 (:export standard-deviation
293 quantile median interquartile-range
294 fivnum sample))
297 (defpackage :lisp-stat-regression-linear
298 (:use :common-lisp
299 :lisp-matrix
300 :lisp-stat-object-system
301 :lisp-stat-basics
302 :lisp-stat-compound-data
303 :lisp-stat-descriptive-statistics
305 :lisp-stat-math
308 (:shadowing-import-from :lisp-stat-object-system
309 call-method call-next-method)
311 (:shadowing-import-from :lisp-stat-math
312 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
313 asin acos atan sinh cosh tanh asinh acosh atanh float random
314 truncate floor ceiling round minusp zerop plusp evenp oddp
315 < <= = /= >= > ;; complex
316 conjugate realpart imagpart phase
317 min max logand logior logxor lognot ffloor fceiling
318 ftruncate fround signum cis)
320 (:export regression-model regression-model-proto x y intercept
321 ;; sweep-matrix
322 basis weights included
323 total-sum-of-squares residual-sum-of-squares
324 predictor-names response-name case-labels
325 ;; functions for helpers
326 lm xtxinv ))
328 (defpackage :lisp-stat
329 (:documentation "Experimentation package for LispStat. Serious
330 work should be packaged up elsewhere for reproducibility. By this
331 I mean, creating a data/analytics/analysis package with the
332 minimal set of objects required.")
333 (:use :common-lisp
334 :lisp-stat-object-system
335 :lisp-stat-compound-data
336 :lisp-stat-probability
337 :lisp-stat-types
338 :lisp-stat-float
339 :lisp-stat-basics
340 :lisp-stat-data
341 :lisp-stat-dataframe
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 (:shadowing-import-from :lisp-stat-object-system
348 call-method call-next-method)
349 (:shadowing-import-from :lisp-stat-math
350 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
351 asin acos atan sinh cosh tanh asinh acosh atanh float random
352 truncate floor ceiling round minusp zerop plusp evenp oddp
353 < <= = /= >= >
354 ;;complex
355 conjugate realpart imagpart phase
357 min max
358 logand logior logxor lognot
359 ffloor fceiling ftruncate fround
360 signum cis)
361 (:export
362 ;; lsobjects :
363 defproto defproto2
364 defmeth send
365 proto-slot-value
367 ;; lstypes :
368 fixnump check-nonneg-fixnum check-one-fixnum
369 check-one-nonneg-fixnum
370 check-one-real check-one-number
372 ;; lsmacros:
374 ;; lsfloat :
375 machine-epsilon
377 ;; compound :
378 compound-data-p *compound-data-proto* compound-object-p
379 compound-data-seq compound-data-length
380 element-list element-seq
381 sort-data order rank
382 recursive-map-elements map-elements
383 repeat
384 check-sequence
385 get-next-element make-next-element set-next-element
386 ;; sequencep
387 iseq
388 ordered-nneg-seq
389 select which
390 difference rseq
392 ;; lsmath.lsp
393 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
394 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
395 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
396 /= >= > ;; complex
397 conjugate realpart imagpart phase min max
398 logand logior logxor lognot ffloor fceiling ftruncate fround
399 signum cis
401 #| ;; The following need to be re-found in lisp-matrix...
403 ;; matrices.lisp
404 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
405 column-list inner-product outer-product cross-product transpose
406 bind-columns bind-rows
408 ;; linalg.lisp
409 chol-decomp lu-decomp lu-solve determinant inverse
410 sv-decomp qr-decomp rcondest make-rotation spline
411 kernel-dens kernel-smooth
412 fft make-sweep-matrix sweep-operator ax+y eigen
413 check-real
414 covariance-matrix matrix print-matrix solve
415 backsolve eigenvalues eigenvectors accumulate cumsum combine
416 lowess
418 ;; in linalg.lisp, possibly not supported by matlisp
419 spline kernel-dens kernel-smooth
423 ;; optimize.lsp
424 newtonmax nelmeadmax
426 ;; lispstat-macros
427 make-rv-function make-rv-function-1
429 ;; data
430 open-file-dialog read-data-file read-data-columns load-data
431 load-example *variables* *ask-on-redefine*
432 def variables savevar undef
434 ;; dataframe
435 dataframe-like dataframe-array make-dataframe
436 varlabels caselabels nrows ncols
437 dataframe-dimension dataframe-dimensons
438 dfref dfref-case dfref-var
439 consistent-dataframe-p
440 dataset
441 list-of-columns list-of-rows
443 ;; listoflist
444 lists-of-same-size equal-listoflist
445 transpose-listoflist
446 make-dataframe-from-listoflist make-array-from-listoflist
448 ;; statistics.lsp (descriptions, should probably be moved
449 ;; later...?
450 standard-deviation quantile median interquartile-range
451 fivnum sample
453 ;; probability (dists.lisp)
454 log-gamma set-seed
455 uniform-rand normal-cdf normal-quant normal-dens
456 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
457 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
458 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
459 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
460 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
461 binomial-cdf binomial-quant binomial-pmf binomial-rand
463 ;; Here is where we have a problem -- lispstat core should be core
464 ;; data management and config problems, with packages providing
465 ;; specialized extensions to LispStat, i.e. regression, nonlin
466 ;; regression, bayesian regression via laplace approximation, etc.
468 ;; The following could be considered "recommended packages",
469 ;; similar to the idea of the recommended packages in R. Probably
470 ;; we want them to do the exporting within that package, therefore
471 ;; NOT being able to lock the "data-ish" package, but only the
472 ;; subpackages prior to export.
474 ;; regression.lsp
475 ;; -- linear regressin models.
476 regression-model regression-model-proto x y intercept sweep-matrix
477 basis weights included total-sum-of-squares residual-sum-of-squares
478 predictor-names response-name case-labels
479 lm xtxinv
481 ;; nonlin.lsp
482 ;; -- nonlinear regression models
483 nreg-model nreg-model-proto mean-function theta-hat epsilon
484 count-limit verbose
485 ;; we might need something like xtxinv here? But should be
486 ;; encapsulated, so we use the one in regression.lisp
488 ;; bayes.lsp
489 bayes-model bayes-model-proto bayes-internals
492 ;; plots.lisp
493 plot-ex
494 contour-plot-ex
495 fn-contour-plot-ex
496 shade-plot-ex
497 3D-plot-ex
502 ;;;; PACKAGES FOR USEABILITY
504 (defpackage :lisp-stat-data-examples
505 (:documentation "Example data for unittests, examples, illustrations,")
506 (:use :common-lisp
507 :lisp-stat)
508 (:shadowing-import-from :lisp-stat
509 call-method call-next-method
511 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
512 asin acos atan sinh cosh tanh asinh acosh atanh float random
513 truncate floor ceiling round minusp zerop plusp evenp oddp
514 < <= = /= >= > > ;; complex
515 conjugate realpart imagpart phase
516 min max logand logior logxor lognot ffloor fceiling
517 ftruncate fround signum cis
519 <= float imagpart)
520 (:export iron aluminum absorbtion
521 diabetes dlabs))
524 (defpackage :lisp-stat-user
525 (:documentation "Experimentation package for LispStat.
526 Serious work should be placed in a similar package elsewhere for
527 reproducibility. But this should hint as to what needs to be
528 done for a user- or analysis-package.")
529 (:nicknames :ls-user)
530 (:use :common-lisp
531 :lisp-matrix
532 :lisp-stat
533 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
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))
547 (defpackage :lisp-stat-unittests
548 (:use :common-lisp :lift :lisp-stat :lisp-stat-data-examples)
549 (:shadowing-import-from :lisp-stat
550 call-method call-next-method ;; objects
551 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
552 asin acos atan sinh cosh tanh asinh acosh atanh float random
553 truncate floor ceiling round minusp zerop plusp evenp oddp
554 < <= = /= >= > ;; complex
555 conjugate realpart imagpart phase
556 min max logand logior logxor lognot ffloor fceiling
557 ftruncate fround signum cis)
558 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
559 almost= almost=lists numerical=)) ; compare
561 (defpackage :lisp-stat-dataframe-example
562 (:use :common-lisp
563 :lift :lisp-stat-unittests
564 :lisp-stat-data-examples
565 :lisp-stat-dataframe)
566 (:export absorbtion aluminum iron))
569 (defpackage :lisp-stat-optimize
570 (:use :common-lisp
571 :cffi
572 :lisp-matrix
573 :lisp-stat-ffi-int
574 :lisp-stat-object-system
575 :lisp-stat-types
576 :lisp-stat-compound-data
577 :lisp-stat-math
578 :lisp-stat-float
579 :lisp-stat-basics
581 :lisp-stat-matrix
582 :lisp-stat-linalg-data
583 :lisp-stat-linalg
586 (:shadowing-import-from :lisp-stat-object-system
587 call-method call-next-method)
588 (:shadowing-import-from :lisp-stat-math
589 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
590 asin acos atan sinh cosh tanh asinh acosh atanh float random
591 truncate floor ceiling round minusp zerop plusp evenp oddp
592 < <= = /= >= > complex conjugate realpart imagpart phase
593 min max logand logior logxor lognot ffloor fceiling
594 ftruncate fround signum cis)
595 (:export
596 ;; derivatives
597 numgrad numhess
599 ;; optimization
600 newtonmax nelmeadmax))