fixed listoflist->matrix-like, and exported.
[CommonLispStat.git] / src / packages.lisp
blobbe15c075e4aef31e420d4a4dd3ac2d68711a39e6
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-04-16 17:21: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 ;;; 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-matrix
138 :lisp-stat-dataframe) ; for dataframe
139 (:export lists-of-same-size
140 equal-listoflist
141 transpose-listoflist
142 listoflist->dataframe
143 listoflist->array
144 listoflist->matrix-like))
146 (defpackage :lisp-stat-model
147 (:documentation "Model management for data analysis.")
148 (:use :common-lisp
149 :lisp-matrix)
150 (:export
151 ;; data structures for model and model/data combination
152 model statistical-model analysis))
155 (defpackage :lisp-stat-regression-linear-clos
156 (:use :common-lisp
157 :lisp-matrix
158 :lisp-stat-dataframe)
159 (:export regression-model))
162 (defpackage :lisp-stat-visualize
163 (:use :common-lisp
164 :lisp-matrix
165 :lisp-stat-dataframe))
167 (defpackage :lisp-stat-visualize-plplot
168 (:use :common-lisp
169 :lisp-matrix
170 :lisp-stat-dataframe
171 :cl-plplot-system)
172 (:export
173 plot-ex
174 contour-plot-ex
175 fn-contour-plot-ex
176 shade-plot-ex
177 3D-plot-ex ))
180 ;;; USER PACKAGES
182 (defpackage :lisp-stat-ffi-int
183 (:use :common-lisp
184 :cffi)
185 (:export ccl-store-integer ccl-store-double ccl-store-ptr
186 get-buf ))
188 (defpackage :lisp-stat-probability
189 (:use :common-lisp
190 :cffi
191 :lisp-stat-ffi-int
192 :lisp-stat-macros)
193 (:export log-gamma set-seed
194 uniform-rand
195 normal-cdf normal-quant normal-dens normal-rand
196 bivnorm-cdf
197 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
198 gamma-cdf gamma-quant gamma-dens gamma-rand
199 chisq-cdf chisq-quant chisq-dens chisq-rand
200 beta-cdf beta-quant beta-dens beta-rand
201 t-cdf t-quant t-dens t-rand
202 f-cdf f-quant f-dens f-rand
203 poisson-cdf poisson-quant poisson-pmf poisson-rand
204 binomial-cdf binomial-quant binomial-pmf binomial-rand))
208 (defpackage :lisp-stat-math
209 (:use :common-lisp
210 :lisp-stat-object-system
211 :lisp-stat-macros
212 :lisp-stat-compound-data
213 :lisp-stat-float)
214 (:shadowing-import-from :lisp-stat-object-system
215 call-method call-next-method)
216 (:shadow expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
217 asin acos atan sinh cosh tanh asinh acosh atanh float random
218 truncate floor ceiling round minusp zerop plusp evenp oddp
219 < <= = /= >= > ;; complex
220 conjugate realpart imagpart phase
221 min max logand logior logxor lognot ffloor fceiling
222 ftruncate fround signum cis)
223 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
224 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
225 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
226 /= >= > ;; complex
227 conjugate realpart imagpart phase min max
228 logand logior logxor lognot ffloor fceiling ftruncate fround
229 signum cis)
230 (:documentation "Vectorization of numerical functions"))
233 #| ;; some of this goes back in, but not all of it?
234 (defpackage :lisp-stat-linalg
235 (:use :common-lisp
236 :cffi
237 :lisp-matrix
238 :lisp-stat-math
239 :lisp-stat-types
240 :lisp-stat-float
241 :lisp-stat-compound-data)
242 (:shadowing-import-from :lisp-stat-math
243 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 conjugate realpart imagpart phase
247 min max logand logior logxor lognot ffloor fceiling
248 ftruncate fround signum cis)
249 (:export chol-decomp lu-decomp lu-solve determinant inverse
250 sv-decomp qr-decomp rcondest make-rotation spline
251 kernel-dens kernel-smooth
252 fft make-sweep-matrix sweep-operator ax+y eigen
254 check-real ;; for optimize
256 covariance-matrix matrix print-matrix solve
257 backsolve eigenvalues eigenvectors accumulate cumsum combine
258 lowess))
265 (defpackage :lisp-stat-data
266 (:documentation "Data management, integration, I/O, and other data technologies.")
267 (:nicknames :ls-data)
268 (:use :common-lisp
269 :lisp-stat-object-system
270 :lisp-stat-config
271 :lisp-stat-types
272 :lisp-stat-compound-data)
273 (:shadowing-import-from :lisp-stat-object-system
274 call-method call-next-method)
275 (:export open-file-dialog read-data-file read-data-columns load-data
276 load-example *variables* *ask-on-redefine*
277 def variables savevar undef))
279 (defpackage :lisp-stat-descriptive-statistics
280 (:use :common-lisp
281 :lisp-stat-data
282 :lisp-stat-math
283 :lisp-stat-compound-data
284 :lisp-matrix
285 :lisp-stat-basics)
286 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
287 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
288 asin acos atan sinh cosh tanh asinh acosh atanh float random
289 truncate floor ceiling round minusp zerop plusp evenp oddp
290 < <= = /= >= > ;; complex
291 conjugate realpart imagpart phase
292 min max logand logior logxor lognot ffloor fceiling
293 ftruncate fround signum cis)
294 (:export standard-deviation
295 quantile median interquartile-range
296 fivnum sample))
299 (defpackage :lisp-stat-regression-linear
300 (:use :common-lisp
301 :lisp-matrix
302 :lisp-stat-object-system
303 :lisp-stat-basics
304 :lisp-stat-compound-data
305 :lisp-stat-descriptive-statistics )
306 (:shadowing-import-from :lisp-stat-object-system
307 call-method call-next-method)
308 (:export regression-model fit-model
310 estimates covariance-matrix
311 ;; functions for helpers
312 lm xtxinv
313 print-object ;; for method dispatch
315 ;; OLD to remove
317 regression-model-proto x y intercept
318 ;; sweep-matrix
319 basis weights included
320 total-sum-of-squares residual-sum-of-squares
321 predictor-names response-name case-labels
324 (defpackage :lisp-stat
325 (:documentation "Experimentation package for LispStat. Serious
326 work should be packaged up elsewhere for reproducibility. By this
327 I mean, creating a data/analytics/analysis package with the
328 minimal set of objects required.")
329 (:use :common-lisp
330 :lisp-stat-object-system
331 :lisp-stat-compound-data
332 :lisp-stat-probability
333 :lisp-stat-types
334 :lisp-stat-float
335 :lisp-stat-basics
336 :lisp-stat-data
337 :lisp-stat-dataframe
338 :cls-data-listoflist
339 :lisp-stat-math
340 :lisp-matrix ;; conversion to a more robust linalg approach
341 :lisp-stat-descriptive-statistics
342 :lisp-stat-regression-linear
343 :cybertiggyr-dsv)
344 (:shadowing-import-from :lisp-stat-object-system
345 call-method call-next-method)
346 (:shadowing-import-from :lisp-stat-math
347 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
348 asin acos atan sinh cosh tanh asinh acosh atanh float random
349 truncate floor ceiling round minusp zerop plusp evenp oddp
350 < <= = /= >= >
351 ;;complex
352 conjugate realpart imagpart phase
354 min max
355 logand logior logxor lognot
356 ffloor fceiling ftruncate fround
357 signum cis)
358 (:export
359 ;; lsobjects :
360 defproto defproto2
361 defmeth send
362 proto-slot-value
364 ;; lstypes :
365 fixnump check-nonneg-fixnum check-one-fixnum
366 check-one-nonneg-fixnum
367 check-one-real check-one-number
369 ;; lsmacros:
371 ;; lsfloat :
372 machine-epsilon
374 ;; compound :
375 compound-data-p *compound-data-proto* compound-object-p
376 compound-data-seq compound-data-length
377 element-list element-seq
378 sort-data order rank
379 recursive-map-elements map-elements
380 repeat
381 check-sequence
382 get-next-element make-next-element set-next-element
383 ;; sequencep
384 iseq
385 ordered-nneg-seq
386 select which
387 difference rseq
389 ;; lsmath.lsp
390 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
391 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
392 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
393 /= >= > ;; complex
394 conjugate realpart imagpart phase min max
395 logand logior logxor lognot ffloor fceiling ftruncate fround
396 signum cis
398 #| ;; The following need to be re-found in lisp-matrix...
400 ;; matrices.lisp
401 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
402 column-list inner-product outer-product cross-product transpose
403 bind-columns bind-rows
405 ;; linalg.lisp
406 chol-decomp lu-decomp lu-solve determinant inverse
407 sv-decomp qr-decomp rcondest make-rotation spline
408 kernel-dens kernel-smooth
409 fft make-sweep-matrix sweep-operator ax+y eigen
410 check-real
411 covariance-matrix matrix print-matrix solve
412 backsolve eigenvalues eigenvectors accumulate cumsum combine
413 lowess
415 ;; in linalg.lisp, possibly not supported by matlisp
416 spline kernel-dens kernel-smooth
420 ;; optimize.lsp
421 newtonmax nelmeadmax
423 ;; lispstat-macros
424 make-rv-function make-rv-function-1
426 ;; data
427 open-file-dialog read-data-file read-data-columns load-data
428 load-example *variables* *ask-on-redefine*
429 def variables savevar undef
431 ;; dataframe
432 dataframe-like dataframe-array make-dataframe
433 varlabels caselabels nrows ncols
434 dataframe-dimension dataframe-dimensons
435 dfref dfref-case dfref-var
436 consistent-dataframe-p
437 dataset
438 list-of-columns list-of-rows
440 ;; listoflist
441 lists-of-same-size equal-listoflist
442 transpose-listoflist
443 listoflist->dataframe listoflist->array listoflist->matrix-like
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 fit-model
474 estimates covariance-matrix
476 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
549 :lift :lisp-matrix
550 :lisp-stat :lisp-stat-data-examples)
551 (:shadowing-import-from :lisp-stat
552 call-method call-next-method ;; objects
553 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
554 asin acos atan sinh cosh tanh asinh acosh atanh float random
555 truncate floor ceiling round minusp zerop plusp evenp oddp
556 < <= = /= >= > ;; complex
557 conjugate realpart imagpart phase
558 min max logand logior logxor lognot ffloor fceiling
559 ftruncate fround signum cis)
560 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
561 almost= almost=lists numerical=)) ; compare
563 (defpackage :lisp-stat-dataframe-example
564 (:use :common-lisp
565 :lift :lisp-stat-unittests
566 :lisp-stat-data-examples
567 :lisp-stat-dataframe)
568 (:export absorbtion aluminum iron))
571 (defpackage :lisp-stat-optimize
572 (:use :common-lisp
573 :cffi
574 :lisp-matrix
575 :lisp-stat-ffi-int
576 :lisp-stat-object-system
577 :lisp-stat-types
578 :lisp-stat-compound-data
579 :lisp-stat-math
580 :lisp-stat-float
581 :lisp-stat-basics
583 :lisp-stat-matrix
584 :lisp-stat-linalg-data
585 :lisp-stat-linalg
588 (:shadowing-import-from :lisp-stat-object-system
589 call-method call-next-method)
590 (:shadowing-import-from :lisp-stat-math
591 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
592 asin acos atan sinh cosh tanh asinh acosh atanh float random
593 truncate floor ceiling round minusp zerop plusp evenp oddp
594 < <= = /= >= > complex conjugate realpart imagpart phase
595 min max logand logior logxor lognot ffloor fceiling
596 ftruncate fround signum cis)
597 (:export
598 ;; derivatives
599 numgrad numhess
601 ;; optimization
602 newtonmax nelmeadmax))