removed prototypes from regression -- currently implemented in regression-clon using...
[CommonLispStat.git] / src / packages.lisp
blobd5a9429bfbba3923b73f75aed07143cf6966b49b
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-04-28 23:03:22 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 (in-package :cl-user)
17 ;;; Basics
20 (defpackage :lisp-stat-object-system
21 (:nicknames :ls-objects :lsos)
22 (:use :common-lisp)
23 (:shadow :call-method :call-next-method)
24 (:export ls-object objectp *object* kind-of-p make-object
25 *message-hook*
26 *set-slot-hook* proto-slot-value self
27 send call-next-method call-method
28 defmeth defproto instance-slots proto-name))
30 (defpackage :lisp-stat-types
31 (:documentation "Provides some typeing for LispStat, but is clearly
32 a bit incomplete.")
33 (:use :common-lisp)
34 (:export fixnump
35 check-nonneg-fixnum check-one-nonneg-fixnum
36 check-one-fixnum check-one-real check-one-number))
38 (defpackage :lisp-stat-float
39 (:use :common-lisp)
40 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
41 machine-epsilon base-float makedouble
43 make-base-trans-fun-2 make-base-trans-fun
45 base-log base-exp base-expt base-sqrt base-sin base-cos
46 base-tan base-asin base-acos base-atan base-sinh
47 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
48 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
49 BASE-FROUND BASE-SIGNUM BASE-CIS))
51 (defpackage :lisp-stat-compound-data
52 (:use :common-lisp
53 :lisp-stat-object-system
54 :lisp-stat-types)
55 (:shadowing-import-from :lisp-stat-object-system
56 call-next-method call-method)
57 (:export compound-data-p *compound-data-proto*
58 compound-object-p
59 compound-data-seq compound-data-length
60 element-list element-seq
61 sort-data order rank
62 recursive-map-elements map-elements repeat
63 check-sequence
64 get-next-element make-next-element set-next-element
65 ;; sequencep
66 iseq ordered-nneg-seq
67 select split-list which
68 difference rseq
69 flatten-list))
71 (defpackage :lisp-stat-macros
72 (:use :common-lisp
73 :lisp-stat-compound-data)
74 (:export make-rv-function make-rv-function-1))
76 (defpackage :lisp-stat-basics
77 (:use :common-lisp
78 :lisp-stat-object-system
79 :lisp-stat-types
80 :lisp-stat-float
81 :lisp-stat-macros
82 :lisp-stat-compound-data)
83 (:shadowing-import-from :lisp-stat-object-system
84 call-method call-next-method)
85 (:export permute-array sum prod count-elements mean
86 if-else sample))
88 (defpackage :lisp-stat-float
89 (:use :common-lisp)
90 (:export +stat-float-typing+ +stat-cfloat-typing+ +stat-float-template+
91 machine-epsilon base-float makedouble
93 make-base-trans-fun-2 make-base-trans-fun
95 BASE-LOG BASE-EXP BASE-EXPT BASE-SQRT BASE-SIN BASE-COS
96 BASE-TAN BASE-ASIN BASE-ACOS BASE-ATAN BASE-SINH
97 BASE-COSH BASE-TANH BASE-ASINH BASE-ACOSH BASE-ATANH
98 BASE-ABS BASE-PHASE BASE-FFLOOR BASE-FCEILING BASE-FTRUNCATE
99 BASE-FROUND BASE-SIGNUM BASE-CIS))
101 (defpackage :lisp-stat-macros
102 (:use :common-lisp
103 :lisp-stat-compound-data)
104 (:export make-rv-function make-rv-function-1))
106 ;;; NEW CLOS STRUCTURE
110 (defpackage :cls-dataframe
111 (:use :common-lisp
112 :lisp-matrix)
113 (:export
114 ;; generic container class for data -- if small enough
115 ;; could be value, otherwise might be reference.
116 dataframe-like
117 dataframe-array
118 make-dataframe
120 ;; accessors
121 varlabels caselabels nrows ncols
122 dataframe-dimension dataframe-dimensons
123 dfref dfref-case dfref-var
124 consistent-dataframe-p
126 dataset
127 list-of-columns ;; list-of-variables
128 list-of-rows ;; list-of-observations
132 (defpackage :cls-data-listoflist
133 (:use :common-lisp
134 :lisp-matrix
135 :cls-dataframe) ; for dataframe
136 (:export lists-of-same-size
137 equal-listoflist
138 transpose-listoflist
139 listoflist->dataframe
140 listoflist->array
141 listoflist->matrix-like))
144 (defpackage :cls-dataimport
145 (:documentation "Data I/O and similar import technologies.")
146 (:use :common-lisp
147 :lisp-stat-object-system
148 :cls-dataframe
149 :cls-data-listoflist
150 :rsm.string)
151 (:shadowing-import-from :lisp-stat-object-system
152 call-method call-next-method)
153 (:export dsvstream->dataframe dsvstream->matrix dsvstream->listoflist))
156 (defpackage :lisp-stat-model
157 (:documentation "Model management for data analysis.")
158 (:use :common-lisp
159 :lisp-matrix)
160 (:export
161 ;; data structures for model and model/data combination
162 model statistical-model analysis))
164 ;;; visualization
166 (defpackage :cls-visualize
167 (:use :common-lisp
168 :lisp-matrix
169 :cls-dataframe))
171 (defpackage :cls-visualize-plplot
172 (:use :common-lisp
173 :lisp-matrix
174 :cls-dataframe
175 :cl-plplot-system)
176 (:export
177 ;; examples
178 plot-ex contour-plot-ex fn-contour-plot-ex shade-plot-ex 3D-plot-ex))
181 ;;; USER PACKAGES
183 (defpackage :lisp-stat-ffi-int
184 (:use :common-lisp
185 :cffi)
186 (:export ccl-store-integer ccl-store-double ccl-store-ptr
187 get-buf ))
189 (defpackage :lisp-stat-probability
190 (:use :common-lisp
191 :cffi
192 :lisp-stat-ffi-int
193 :lisp-stat-macros)
194 (:export log-gamma set-seed
195 uniform-rand
196 normal-cdf normal-quant normal-dens normal-rand
197 bivnorm-cdf
198 cauchy-cdf cauchy-quant cauchy-dens cauchy-rand
199 gamma-cdf gamma-quant gamma-dens gamma-rand
200 chisq-cdf chisq-quant chisq-dens chisq-rand
201 beta-cdf beta-quant beta-dens beta-rand
202 t-cdf t-quant t-dens t-rand
203 f-cdf f-quant f-dens f-rand
204 poisson-cdf poisson-quant poisson-pmf poisson-rand
205 binomial-cdf binomial-quant binomial-pmf binomial-rand))
209 (defpackage :lisp-stat-math
210 (:use :common-lisp
211 :lisp-stat-object-system
212 :lisp-stat-macros
213 :lisp-stat-compound-data
214 :lisp-stat-float)
215 (:shadowing-import-from :lisp-stat-object-system
216 call-method call-next-method)
217 (:shadow expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
218 asin acos atan sinh cosh tanh asinh acosh atanh float random
219 truncate floor ceiling round minusp zerop plusp evenp oddp
220 < <= = /= >= > ;; complex
221 conjugate realpart imagpart phase
222 min max logand logior logxor lognot ffloor fceiling
223 ftruncate fround signum cis)
224 (:export ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
225 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
226 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
227 /= >= > ;; complex
228 conjugate realpart imagpart phase min max
229 logand logior logxor lognot ffloor fceiling ftruncate fround
230 signum cis)
231 (:documentation "Vectorization of numerical functions"))
234 #| ;; some of this goes back in, but not all of it?
235 (defpackage :lisp-stat-linalg
236 (:use :common-lisp
237 :cffi
238 :lisp-matrix
239 :lisp-stat-math
240 :lisp-stat-types
241 :lisp-stat-float
242 :lisp-stat-compound-data)
243 (:shadowing-import-from :lisp-stat-math
244 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
245 asin acos atan sinh cosh tanh asinh acosh atanh float random
246 truncate floor ceiling round minusp zerop plusp evenp oddp
247 < <= = /= >= > complex conjugate realpart imagpart phase
248 min max logand logior logxor lognot ffloor fceiling
249 ftruncate fround signum cis)
250 (:export chol-decomp lu-decomp lu-solve determinant inverse
251 sv-decomp qr-decomp rcondest make-rotation spline
252 kernel-dens kernel-smooth
253 fft make-sweep-matrix sweep-operator ax+y eigen
255 check-real ;; for optimize
257 covariance-matrix matrix print-matrix solve
258 backsolve eigenvalues eigenvectors accumulate cumsum combine
259 lowess))
266 (defpackage :lisp-stat-data
267 (:documentation "Data management, integration, I/O, and other data technologies.")
268 (:nicknames :ls-data)
269 (:use :common-lisp
270 :lisp-stat-object-system
271 :lisp-stat-config
272 :lisp-stat-types
273 :lisp-stat-compound-data)
274 (:shadowing-import-from :lisp-stat-object-system
275 call-method call-next-method)
276 (:export open-file-dialog read-data-file read-data-columns load-data
277 load-example *variables* *ask-on-redefine*
278 def variables savevar undef))
280 (defpackage :lisp-stat-descriptive-statistics
281 (:use :common-lisp
282 :lisp-stat-data
283 :lisp-stat-math
284 :lisp-stat-compound-data
285 :lisp-matrix
286 :lisp-stat-basics)
287 (:shadowing-import-from :lisp-stat-math ;; life is a vector!
288 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
289 asin acos atan sinh cosh tanh asinh acosh atanh float random
290 truncate floor ceiling round minusp zerop plusp evenp oddp
291 < <= = /= >= > ;; complex
292 conjugate realpart imagpart phase
293 min max logand logior logxor lognot ffloor fceiling
294 ftruncate fround signum cis)
295 (:export standard-deviation
296 quantile median interquartile-range
297 fivnum sample))
300 (defpackage :lisp-stat-regression-linear
301 (:use :common-lisp
302 :lisp-matrix
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
316 (defpackage :lisp-stat
317 (:documentation "Experimentation package for LispStat. Serious
318 work should be packaged up elsewhere for reproducibility. By this
319 I mean, creating a data/analytics/analysis package with the
320 minimal set of objects required.")
321 (:use :common-lisp
322 :lisp-stat-object-system
323 :lisp-stat-compound-data
324 :lisp-stat-probability
325 :lisp-stat-types
326 :lisp-stat-float
327 :lisp-stat-basics
328 :lisp-stat-data
329 :cls-dataframe
330 :cls-data-listoflist
331 :lisp-stat-math
332 :lisp-matrix ;; conversion to a more robust linalg approach
333 :lisp-stat-descriptive-statistics
334 :lisp-stat-regression-linear
335 :cybertiggyr-dsv
336 :cls-visualize
337 :cls-visualize-plplot)
338 (:shadowing-import-from :lisp-stat-object-system
339 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 < <= = /= >= >
345 ;;complex
346 conjugate realpart imagpart phase
348 min max
349 logand logior logxor lognot
350 ffloor fceiling ftruncate fround
351 signum cis)
352 (:export
353 ;; lsobjects :
354 defproto defproto2
355 defmeth send
356 proto-slot-value
358 ;; lstypes :
359 fixnump check-nonneg-fixnum check-one-fixnum
360 check-one-nonneg-fixnum
361 check-one-real check-one-number
363 ;; lsmacros:
365 ;; lsfloat :
366 machine-epsilon
368 ;; compound :
369 compound-data-p *compound-data-proto* compound-object-p
370 compound-data-seq compound-data-length
371 element-list element-seq
372 sort-data order rank
373 recursive-map-elements map-elements
374 repeat
375 check-sequence
376 get-next-element make-next-element set-next-element
377 ;; sequencep
378 iseq
379 ordered-nneg-seq
380 select which
381 difference rseq
383 ;; lsmath.lsp
384 ^ ** expt + - * / mod rem pmin pmax abs 1+ 1- log exp sqrt sin cos
385 tan asin acos atan sinh cosh tanh asinh acosh atanh float random
386 truncate floor ceiling round minusp zerop plusp evenp oddp < <= =
387 /= >= > ;; complex
388 conjugate realpart imagpart phase min max
389 logand logior logxor lognot ffloor fceiling ftruncate fround
390 signum cis
392 #| ;; The following need to be re-found in lisp-matrix...
394 ;; matrices.lisp
395 matrixp num-rows num-cols matmult identity-matrix diagonal row-list
396 column-list inner-product outer-product cross-product transpose
397 bind-columns bind-rows
399 ;; linalg.lisp
400 chol-decomp lu-decomp lu-solve determinant inverse
401 sv-decomp qr-decomp rcondest make-rotation spline
402 kernel-dens kernel-smooth
403 fft make-sweep-matrix sweep-operator ax+y eigen
404 check-real
405 covariance-matrix matrix print-matrix solve
406 backsolve eigenvalues eigenvectors accumulate cumsum combine
407 lowess
409 ;; in linalg.lisp, possibly not supported by matlisp
410 spline kernel-dens kernel-smooth
414 ;; optimize.lsp
415 newtonmax nelmeadmax
417 ;; lispstat-macros
418 make-rv-function make-rv-function-1
420 ;; data
421 open-file-dialog read-data-file read-data-columns load-data
422 load-example *variables* *ask-on-redefine*
423 def variables savevar undef
425 ;; dataframe
426 dataframe-like dataframe-array make-dataframe
427 varlabels caselabels nrows ncols
428 dataframe-dimension dataframe-dimensons
429 dfref dfref-case dfref-var
430 consistent-dataframe-p
431 dataset
432 list-of-columns list-of-rows
434 ;; listoflist
435 lists-of-same-size equal-listoflist
436 transpose-listoflist
437 listoflist->dataframe listoflist->array listoflist->matrix-like
439 ;; statistics.lsp (descriptions, should probably be moved
440 ;; later...?
441 standard-deviation quantile median interquartile-range
442 fivnum sample
444 ;; probability (dists.lisp)
445 log-gamma set-seed
446 uniform-rand normal-cdf normal-quant normal-dens
447 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
448 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
449 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
450 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
451 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
452 binomial-cdf binomial-quant binomial-pmf binomial-rand
454 ;; Here is where we have a problem -- lispstat core should be core
455 ;; data management and config problems, with packages providing
456 ;; specialized extensions to LispStat, i.e. regression, nonlin
457 ;; regression, bayesian regression via laplace approximation, etc.
459 ;; The following could be considered "recommended packages",
460 ;; similar to the idea of the recommended packages in R. Probably
461 ;; we want them to do the exporting within that package, therefore
462 ;; NOT being able to lock the "data-ish" package, but only the
463 ;; subpackages prior to export.
465 ;; regression.lsp
466 ;; -- linear regressin models.
467 regression-model fit-model
468 estimates covariance-matrix
470 regression-model-proto x y intercept sweep-matrix
471 basis weights included total-sum-of-squares residual-sum-of-squares
472 predictor-names response-name case-labels
473 lm xtxinv
475 ;; nonlin.lsp
476 ;; -- nonlinear regression models
477 nreg-model nreg-model-proto mean-function theta-hat epsilon
478 count-limit verbose
479 ;; we might need something like xtxinv here? But should be
480 ;; encapsulated, so we use the one in regression.lisp
482 ;; bayes.lsp
483 bayes-model bayes-model-proto bayes-internals
485 ;; plots.lisp
486 plot-ex
487 contour-plot-ex
488 fn-contour-plot-ex
489 shade-plot-ex
490 3D-plot-ex
495 ;;;; PACKAGES FOR USEABILITY
497 (defpackage :lisp-stat-data-examples
498 (:documentation "Example data for unittests, examples, illustrations,")
499 (:use :common-lisp
500 :lisp-stat)
501 (:shadowing-import-from :lisp-stat
502 call-method call-next-method
504 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
505 asin acos atan sinh cosh tanh asinh acosh atanh float random
506 truncate floor ceiling round minusp zerop plusp evenp oddp
507 < <= = /= >= > > ;; complex
508 conjugate realpart imagpart phase
509 min max logand logior logxor lognot ffloor fceiling
510 ftruncate fround signum cis
512 <= float imagpart)
513 (:export iron aluminum absorbtion
514 diabetes dlabs))
517 (defpackage :lisp-stat-user
518 (:documentation "Experimentation package for LispStat.
519 Serious work should be placed in a similar package elsewhere for
520 reproducibility. But this should hint as to what needs to be
521 done for a user- or analysis-package.")
522 (:nicknames :ls-user)
523 (:use :common-lisp
524 :lisp-matrix
525 :lisp-stat
526 :lisp-stat-data-examples) ;; this last is to have 'things to play with'
527 (:shadowing-import-from :lisp-stat
528 call-method call-next-method
530 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
531 asin acos atan sinh cosh tanh asinh acosh atanh float random
532 truncate floor ceiling round minusp zerop plusp evenp oddp
533 < <= = /= >= > > ;; complex
534 conjugate realpart imagpart phase
535 min max logand logior logxor lognot ffloor fceiling
536 ftruncate fround signum cis
538 <= float imagpart))
540 (defpackage :lisp-stat-unittests
541 (:use :common-lisp
542 :lift :lisp-matrix
543 :lisp-stat :lisp-stat-data-examples)
544 (:shadowing-import-from :lisp-stat
545 call-method call-next-method ;; objects
546 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan ;; lsmath
547 asin acos atan sinh cosh tanh asinh acosh atanh float random
548 truncate floor ceiling round minusp zerop plusp evenp oddp
549 < <= = /= >= > ;; complex
550 conjugate realpart imagpart phase
551 min max logand logior logxor lognot ffloor fceiling
552 ftruncate fround signum cis)
553 (:export run-lisp-stat-tests run-lisp-stat-test scoreboard ; exec
554 almost= almost=lists numerical=)) ; compare
556 (defpackage :cls-dataframe-example
557 (:use :common-lisp
558 :lift :lisp-stat-unittests
559 :lisp-stat-data-examples
560 :cls-dataframe)
561 (:export absorbtion aluminum iron))
564 (defpackage :lisp-stat-optimize
565 (:use :common-lisp
566 :cffi
567 :lisp-matrix
568 :lisp-stat-ffi-int
569 :lisp-stat-object-system
570 :lisp-stat-types
571 :lisp-stat-compound-data
572 :lisp-stat-math
573 :lisp-stat-float
574 :lisp-stat-basics
576 :lisp-stat-matrix
577 :lisp-stat-linalg-data
578 :lisp-stat-linalg
581 (:shadowing-import-from :lisp-stat-object-system
582 call-method call-next-method)
583 (:shadowing-import-from :lisp-stat-math
584 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
585 asin acos atan sinh cosh tanh asinh acosh atanh float random
586 truncate floor ceiling round minusp zerop plusp evenp oddp
587 < <= = /= >= > complex conjugate realpart imagpart phase
588 min max logand logior logxor lognot ffloor fceiling
589 ftruncate fround signum cis)
590 (:export
591 ;; derivatives
592 numgrad numhess
594 ;; optimization
595 newtonmax nelmeadmax))