progress on testing, random numbers, loop structure/data shortcuts, and loading ...
[CommonLispStat.git] / TODO.org
blob0958800523684bf0bd87305c8c37b49d8e9bf755
2 Time-stamp: <2010-11-30 18:01:26 tony>
3 Creation:   <2008-09-08 08:06:30 tony>
5 * Intro and Metadata
7 File:       TODO.lisp
8 Author:     AJ Rossini <blindglobe@gmail.com>
9 Copyright:  (c) 2007-2010, AJ Rossini <blindglobe@gmail.com>.  BSD.
10 Purpose:    Stuff that needs to be made working sits inside the
11             Task sections.
13             This file contains the current challenges to solve,
14             including a description of the setup and the work to
15             solve.  Solutions welcome.
17 What is this talk of 'release'? Klingons do not make software
18 'releases'.  Our software 'escapes', leaving a bloody trail of
19 designers and quality assurance people in its wake.
21 * Design
23 ** (Internal) Package and (External) System Hierarchy
24 *** Singletons (primary building blocks)
25     
26     These are packages as well as 
28     | asdf          | common system loader                          |
29     | xarray        | common access structure to array-like         |
30     |               | (matrix, vector) structures.                  |
31     | cls-config    | initialization of Lisp state, variables, etc, |
32     |               | localization to the particular lisp.          |
33     | lift          | unit-testing                                  |
34     | cffi          | foriegn function library                      |
35     | alexandria    |                                               |
36     | babel         |                                               |
37     | iterate       |                                               |
38     | metabang-bind |                                               |
40 *** Dependency structure
42     | lisp-matrix     | general purpose matrix package, linking to lapack |      |
43     |                 | for numerics. Depends on:                         |      |
44     |                 | ffa                                               | cffi |
45     |                 | fnv                                               | cffi |
46     |                 | cl-blapack                                        | cffi |
47     |                 | xarray                                            |      |
48     | cls-dataframe   | in the same spirit as lisp-matrix, a means to     |      |
49     |                 | create tables.  Perhaps better called datatables? |      |
50     | cls-probability | depends on gsll, cl-variates, cl-? initially,     |      |
52 *** Need to integrate
54     cl-randist
56     rsm-string
58     ?? cl-2d  : 
59               cl-cairo2 : cffi
61     ?? cl-plplot : cffi
63 * Tasks to Do [4/25]
64   Usually, we need to load it before going on.
65 #+srcname: loadit
66 #+begin_src lisp
67   (asdf:oos 'asdf:load-op :cls)
68 #+end_src
69 ** DONE [#B] SET UP
70    - State "DONE"       from "CURR"       [2010-10-12 Tue 13:48] \\
71      setup is mostly complete
72    - State "CURR"       from "TODO"       [2010-10-12 Tue 13:47]
73    - State "TODO"       from ""           [2010-10-12 Tue 13:47]
74    This is an example of a custom setup, not really interesting at
75    this point except to remind Tony how to program.
76 #+srcname: loader
77 #+begin_src lisp
78   (in-package :cl-user)
79   (progn 
80     (defun init-CLS (&key (compile 'nil))
81       (let ((packagesToLoad (list ;; core system
82                                   :lift :lisp-matrix :cls
83   
84                                   ;; visualization
85                                   ;; :cl-cairo2-x11 :iterate
86                                   :cl-2d
87                                   ;; doc reporting
88                                   :cl-pdf :cl-typesetting
89                                   ;;INFRA
90                                   :asdf-system-connections :xarray
91                                   ;;DOCS
92                                   :metatilities-base :anaphora :tinaa
93                                   :cl-ppcre :cl-markdown :docudown
94                                   ;; version and validate CLOS objects
95                                   ;; :versioned-objects :validations
96                                   ;;VIZ
97                                   ;; :cl-opengl
98                                   ;; :cl-glu :cl-glut :cl-glut-examples
99   
100                                   :bordeaux-threads
101                                   ;; :cells :cells-gtk
102                                   )))
103         (mapcar #'(lambda (x)
104                     (if compile
105                         (asdf:oos 'asdf:compile-op x :force T)
106                         (asdf:oos 'asdf:load-op x)))
107                 packagesToLoad)))
108   
109     (init-CLS)) ;; vs (init-CLS :compile T)
110 #+end_src
112 #+results:
113 |   | #<PACKAGE "COMMON-LISP-USER"> |
115 ** TODO [#A] Integrate with quicklist support.
116    - State "TODO"       from ""           [2010-11-30 Tue 18:00]
117    
118    important to merge with quicklisp system loader support.
119 ** CURR [#A] Testing: unit, regression, examples. [0/3]
120    - State "CURR"       from "TODO"       [2010-10-12 Tue 13:51]
121    - State "TODO"       from ""           [2010-10-12 Tue 13:51]
122    Testing consists of unit tests, which internally verify subsets of
123    code, regression tests, and functional tests (in increasing order
124    of scale).
125 *** CURR [#B] Unit tests
126     - State "CURR"       from "TODO"       [2010-11-04 Thu 18:33]
127    - State "CURR"       from "TODO"       [2010-10-12 Tue 13:48]
128    - State "TODO"       from ""           [2010-10-12 Tue 13:48]
129    Unit tests have been started using LIFT.  Need to consider some of
130    the other systems that provide testing, when people add them to the
131    mix of libraries that we need, along with examples of how to use.
132 #+srcname: 
133 #+begin_src lisp
134   (in-package :lisp-stat-unittests)
135   (run-tests :suite 'lisp-stat-ut)
136   ;; => tests = 78, failures = 7, errors = 20
137   (asdf:oos 'asdf:test-op 'cls)
138   ;; which runs (describe (run-tests :suite 'lisp-stat-ut))
139 #+end_src
140    and check documentation to see if it is useful.
141 #+srcname: 
142 #+begin_src lisp
143    (in-package :lisp-stat-unittests)
145    (describe 'lisp-stat-ut)
146    (documentation 'lisp-stat-ut 'type)
148    ;; FIXME: Example: currently not relevant, yet
149    ;;   (describe (lift::run-test :test-case  'lisp-stat-unittests::create-proto
150    ;;                             :suite 'lisp-stat-unittests::lisp-stat-ut-proto))
152    (describe (lift::run-tests :suite 'lisp-stat-ut-dataframe))
153    (lift::run-tests :suite 'lisp-stat-ut-dataframe)
155    (describe (lift::run-test
156                :test-case  'lisp-stat-unittests::create-proto
157                :suite 'lisp-stat-unittests::lisp-stat-ut-proto))
158 #+end_src
160 *** TODO [#B] Regression Tests
161     - State "TODO"       from ""           [2010-10-12 Tue 13:54]
163 *** TODO [#B] Functional Tests
164     - State "TODO"       from ""           [2010-10-12 Tue 13:54]
166 ** CURR [#B] Functional Examples that need to work [1/2]
167    - State "CURR"       from "TODO"       [2010-11-30 Tue 17:57]
168    - State "TODO"       from ""           [2010-10-12 Tue 13:55]
170    These examples should be functional forms within CLS, describing
171    working functionality which is needed for work.
173 *** TODO [#B] Scoping with datasets
174     - State "TODO"       from ""           [2010-11-04 Thu 18:46]
176     The following needs to work, and a related syntax for resampling
177     and similar synthetic data approaches (bootstrapping, imputation)
178     ought to use similar syntax as well.
179 #+srcname: DataSetNameScoping
180 #+begin_src lisp
181   (in-package :ls-user)
182   (progn
183     ;; Syntax examples using lexical scope, closures, and bindings to
184     ;; ensure a clean communication of results
185     ;; This is actually a bit tricky, since we need to clarify whether
186     ;; it is line-at-a-time that we are considering or if there is
187     ;; another mapping strategy.  In particular, one could imagine a
188     ;; looping-over-observations function, or a
189     ;; looping-over-independent-observations function which leverages a
190     ;; grouping variable which provides guidance for what is considered
191     ;; independent from the sampling frame being considered. The frame
192     ;; itself (definable via some form of metadata to clarify scope?)
193     ;; could clearly provide a bit of relativity for clarifying what
194     ;; statistical independence means.
195     
196     (with-data dataset ((dsvarname1 [usevarname1])
197                         (dsvarname2 [usevarname2]))
198         @body)
199     
200     (looping-over-observations
201        dataset ((dsvarname1 [usevarname1])
202                 (dsvarname2 [usevarname2]))
203          @body)
204   
205     (looping-over-independent-observations
206        dataset independence-defining-variable
207          ((dsvarname1 [usevarname1])
208           (dsvarname2 [usevarname2]))
209          @body)
210     )
211   
212 #+end_src
214 *** DONE [#B] Dataframe variable typing
215     - State "DONE"       from "CURR"       [2010-11-30 Tue 17:56] \\
216       check-type approach works, we would just have to throw a catchable
217       error if we want to use it in a reliable fashion.
218     - State "CURR"       from "TODO"       [2010-11-30 Tue 17:56]
219     - State "TODO"       from ""           [2010-11-04 Thu 18:48]
221     Seems to generally work, need to ensure that we use this for
222     appropriate typing.
224 #+srcname: DFvarTyping
225 #+begin_src lisp
226   (in-package :ls-user)
227   (defparameter *df-test*
228     (make-instance 'dataframe-array
229                    :storage #2A (('a "test0" 0 0d0)
230                                  ('b "test1" 1 1d0)
231                                  ('c "test2" 2 2d0)
232                                  ('d "test3" 3 3d0)
233                                  ('e "test4" 4 4d0))
234                    :doc "test reality"
235                    :case-labels (list "0" "1" 2 "3" "4")
236                    :var-labels (list "symbol" "string" "integer" "double-float")
237                    :var-types (list 'symbol 'string 'integer 'double-float)))
238   
239   ;; with SBCL, ints become floats?  Need to adjust output
240   ;; representation appropriately..
241   *df-test* 
242   
243   (defun check-var (df colnum)
244     (let ((nobs (xdim (dataset df) 0)))
245       (dotimes (i nobs)
246         (check-type (xref df i colnum) (elt (var-types df) i)))))
247   
248   (xdim (dataset *df-test*) 1)
249   (xdim (dataset *df-test*) 0)
250   
251   (check-var *df-test* 0)
252   
253   (class-of
254     (xref *df-test* 1 1))
255   
256   (check-type (xref *df-test* 1 1)
257               string) ;; => nil, so good.
258   (check-type (xref *df-test* 1 1)
259               vector) ;; => nil, so good.
260   (check-type (xref *df-test* 1 1)
261               real) ;; => simple-error type thrown, so good.
262   
263   ;; How to nest errors within errors?
264   (check-type (check-type (xref *df-test* 1 1) real) ;; => error thrown, so good.
265               simple-error)
266   (xref *df-test* 1 2)
267   
268   (check-type *df-test*
269               dataframe-array) ; nil is good.
270   
271   (integerp (xref *df-test* 1 2))
272   (floatp (xref *df-test* 1 2))
273   (integerp (xref *df-test* 1 3))
274   (type-of (xref *df-test* 1 3))
275   (floatp (xref *df-test* 1 3))
276   
277   (type-of (vector 1 1d0))
278   (type-of *df-test*)
279   
280   (xref *df-test* 2 1)
281   (xref *df-test* 0 0)
282   (xref *df-test* 1 0)
283   (xref *df-test* 1 '*)
284 #+end_src
286 ** CURR [#A] Random Numbers [2/6]
287    - State "CURR"       from "TODO"       [2010-11-05 Fri 15:41]
288    - State "TODO"       from ""           [2010-10-14 Thu 00:12]
290    Need to select and choose a probability system (probability
291    functions, random numbers).  Goal is to have a general framework
292    for representing probability functions, functionals on
293    probabilities, and reproducible random streams based on such
294    numbers. 
295 *** CURR [#B] CL-VARIATES system evaluation [2/3]
296     - State "CURR"       from "TODO"       [2010-11-05 Fri 15:40]
297     - State "TODO"       from ""           [2010-10-12 Tue 14:16]
298     
299     CL-VARIATES is a system developed by Gary W King.  It uses streams
300     with seeds, and is hence reproducible.  (Random comment: why do CL
301     programmers as a class ignore computational reproducibility?)
302 **** DONE [#B] load and verify
303      - State "DONE"       from "CURR"       [2010-11-04 Thu 18:59] \\
304        load, init, and verify performance.
305      - State "CURR"       from "TODO"       [2010-11-04 Thu 18:58]
306      - State "TODO"       from ""           [2010-11-04 Thu 18:58]
308      <2010-11-30 Tue> : just modified cls.asd to ensure that we load
309      as appropriate the correct random variate package.
311 #+srcname: Loading-CL-VARIATES
312 #+begin_src lisp
313   (in-package :cl-user)
314   (asdf:oos 'asdf:load-op 'cl-variates)
315   (asdf:oos 'asdf:load-op 'cl-variates-test)
316 #+end_src
319 #+srcname: CL-VARIATES-UNITTESTS
320 #+begin_src lisp
321   (in-package :cl-variates-test)
322   ;; check tests
323   (run-tests :suite 'cl-variates-test)
324   (describe (run-tests :suite 'cl-variates-test))
325   
326 #+end_src
328 **** DONE [#B] Examples of use
329      - State "DONE"       from "CURR"       [2010-11-05 Fri 15:39] \\
330        basic example of reproducible draws from the uniform and normal random
331        number streams.
332      - State "CURR"       from "TODO"       [2010-11-05 Fri 15:39]
333      - State "TODO"       from ""           [2010-11-04 Thu 19:01]
335 #+srcname: CL-VARIATES-EXAMPLE-USE
336 #+begin_src lisp
337   (in-package :cl-variates-user)
338   ;; example usage
339   (defparameter state (make-random-number-generator))
340   (setf (random-seed state) 44)
341   (random-seed state)
342   (loop for i from 1 to 10 collect
343                     (random-range state 0 10))
344   ;; => (1 5 1 0 7 1 2 2 8 10)
345   (setf (random-seed state) 44)
346   (loop for i from 1 to 10 collect
347                     (random-range state 0 10))
348   ;; => (1 5 1 0 7 1 2 2 8 10)
349   
350   (setf (random-seed state) 44)
351   (random-seed state)
352   (loop for i from 1 to 10 collect
353                     (normal-random state 0 1))
354   ;; => 
355   ;; (-1.2968656102820426 0.40746363934173213 -0.8594712469518473 0.8795681301148328
356   ;;  1.0731526250004264 -0.8161629082481728 0.7001813608754809 0.1078045427044097
357   ;;  0.20750134211656893 -0.14501914108452274)
358   
359   (setf (random-seed state) 44)
360   (loop for i from 1 to 10 collect
361                     (normal-random state 0 1))
362   ;; => 
363   ;; (-1.2968656102820426 0.40746363934173213 -0.8594712469518473 0.8795681301148328
364   ;;  1.0731526250004264 -0.8161629082481728 0.7001813608754809 0.1078045427044097
365   ;;  0.20750134211656893 -0.14501914108452274)
366 #+end_src
368 **** CURR [#B] Full example of general usage 
369      - State "CURR"       from "TODO"       [2010-11-05 Fri 15:40]
370      - State "TODO"       from ""           [2010-11-05 Fri 15:40]
372      What we want to do here is describe the basic available API that
373      is present.  So while the previous work describes what the 
374 *** TODO [#B] CL-RANDOM system evaluation
375     - State "TODO"       from ""           [2010-11-05 Fri 15:40]
377     Problems:
378     1. no seed setting for random numbers
379     2. contamination of a probability support with optimization and
380        linear algebra.
382     Positives:
383     1. good code
384     2. nice design for generics.
385        
386 *** TODO [#B] Native CLS (from XLS)
387     - State "TODO"       from ""           [2010-11-05 Fri 15:40]
388       
389 ** TODO [#B] Numerical Linear Algebra
390    - State "TODO"       from ""           [2010-10-14 Thu 00:12]
392 *** TODO [#B] LLA evaluation
393     - State "TODO"       from ""           [2010-10-12 Tue 14:13]
394 ;;; experiments with LLA
395 (in-package :cl-user)
396 (asdf:oos 'asdf:load-op 'lla)
397 (in-package :lla-user)
399 *** CURR [#B] Lisp-Matrix system evaluation
400     - State "CURR"       from "TODO"       [2010-10-12 Tue 14:13]
401     - State "TODO"       from ""           [2010-10-12 Tue 14:13]
403 *** TODO [#B] LispLab system evaluation
404     - State "TODO"       from ""           [2010-10-12 Tue 14:13]
406 ** TODO [#B] Statistical Procedures to implement
407    - State "TODO"       from ""           [2010-10-14 Thu 00:12]
409 *** PFIM 
410 (in-package :cls-user)
411 ;;;; PFIM notes
413 ;; PFIM 3.2 
415 ;; population design eval and opt
416 #| 
417 issues: 
418 - # individuals
419 - # sampling times
420 - sampling times?
422 constraints:
423 number of samples/cost of lab analysis and collection
424 expt constraints
427 (defun pfim (&key model ( constraints ( summary-function )
429   (list num-subjects num-times list-times))))
432 N individuals i
433 Each individal has a deisgn psi_i
434    nubmer of samples n_i and sampling times t_{i{1}} t_{i{n_1}}
435    individuals can differ
437 Model:
439 individual-level model 
442 (=model y_i (+ (f \theta_i \psi_i) epsilion_i ))
443 (=var \epsilion_i \sigma_between \sigma_within  )
445 ;; Information Matrix for pop deisgn 
447 (defparameter IM (sum  (i 1 N) (MF \psi_i \phi_i)))
450 For nonlinear structureal models, expand around RE=0
452 Cramer-Rao : MF^{-1} is lower bound for estimation variance.
454 Design comparisons: 
456 - smallest SE, but is a matrix, so
457 - criteria for matrix comparison
458 -- D-opt, (power (determinant MF) (/ 1 P))
461 find design maxing D opt, (power (determinant MF) (/ 1 P))
462 Design varialables 
463  -- contin vars for smapling times within interval or set -- number of groups for cat vars
465 Stat in Med 2009, expansion around post-hoc RE est, not necessarily zero.
467 Example binary covariate C
470 (if (= i reference-class) 
471     (setf (aref C i) 0)
472     (setf (aref C i) 1))
474 ;; Exponential RE,
475 (=model (log \theta) (  ))
477 ;; extensions
479 ;; outputs
482 PFIM provides for a given design and values of \beta: 
483  compute extended FIM
484  SE/RSE for \beta of each class of each covar
485  eval influence of design on SE(\beta)
487 inter-occassion variability (IOV)
488 - patients sampled more than once, H occassions
489 - RE for IOV
490 - additional vars to estimate
494 ;;; comparison criteria
496 functional of conc/time curve which is used for comparison, i.e. 
497 (AUC conc/time-curve)
498 (Cmax conc/time-curve)
499 (Tmax conc/time-curve)
501 where 
503 (defun conc/time-curve (t) 
504   ;; computation
505 #| 
506   (let ((conc (exp (* t \beta1))))
507      conc)
509   )
511 ;;See
512 (url-get "www.pfim.biostat.fr")
515 ;;; Thinking of generics...
516 (information-matrix model parameters)
517 (information-matrix variance-matrix)
518 (information-matrix model data)
519 (information-matrix list-of-individual-IMs)
522 (defun IM (loglikelihood parameters times)
523   "Does double work.  Sum up the resulting IMs to form a full IM."
524   (let ((IM (make-matrix (length parameters)
525                          (length parameters)
526                          :initial-value 0.0d0)))
527     (dolist (parameterI parameters)
528       (dolist (parameterJ parameters)
529         (setf (aref IM I J)
530               (differentiate (differentiate loglikelihood parameterI) parameterJ))))))
532 *** difference between empirical, fisherian, and ...? information.
533 *** Example of Integration with CL-GENOMIC
534     - State "TODO"       from ""           [2010-10-12 Tue 14:03]
535     
536     CL-GENOMIC is a very interesting data-structure strategy for
537     manipulating sequence data.
539 #+srcname: 
540 #+begin_src lisp
541     (in-package :cl-user)
542     (asdf:oos 'asdf:compile-op :ironclad)
543     (asdf:oos 'asdf:load-op :cl-genomic)
545     (in-package :bio-sequence)
546     (make-dna "agccg") ;; fine
547     (make-aa "agccg")  ;; fine
548     (make-aa "agc9zz") ;; error expected
549 #+end_src
551 ** TODO [#B] Documentation and Examples [0/3]
552    - State "TODO"       from ""           [2010-10-14 Thu 00:12]
554 *** TODO [#B] Docudown
555     - State "TODO"       from ""           [2010-11-05 Fri 15:34]
557 *** TODO [#A] CLDOC
558     - State "TODO"       from ""           [2010-11-05 Fri 15:34]
560 *** TODO [#B] CLPDF, and literate data analysis
561     - State "TODO"       from ""           [2010-11-05 Fri 15:34]
563 *** 
564 * Proposals