no ore mbd system loader
[CommonLispStat.git] / TODO.org
blob00eb8d8e9370ce5c048ac63e6ce86843df0dd769
2 Time-stamp: <2012-07-01 11:14:12 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     as of now, all are in QL heirarchy
42 *** Dependency structure
44     | lisp-matrix     | general purpose matrix package, linking to lapack |      |
45     |                 | for numerics. Depends on:                         |      |
46     |                 | ffa                                               | cffi |
47     |                 | fnv                                               | cffi |
48     |                 | cl-blapack                                        | cffi |
49     |                 | xarray                                            |      |
50     | cls-dataframe   | in the same spirit as lisp-matrix, a means to     |      |
51     |                 | create tables.  Perhaps better called datatables? |      |
52     | cls-probability | depends on gsll, cl-variates, cl-? initially,     |      |
54 *** Need to integrate
56     cl-randist
58     rsm-string
60     ?? cl-2d  : 
61               cl-cairo2 : cffi
63     ?? cl-plplot : cffi
65 * Tasks to Do [4/25]
67   Usually, we need to load it before going on.
69 #+srcname: loadit
70 #+begin_src lisp
71       (ql:quickload :cls)
72 #+end_src
74   though sometimes we might want to recompile fully.  (Can this be
75   done via QL?  Need to check)
77 #+name: compile-it-all
78 #+begin_src lisp
79   (asdf:oos 'asdf:compile-op :cls :force T)
80 #+end_src
83 ** DONE [#B] SET UP
84    - State "DONE"       from "CURR"       [2010-10-12 Tue 13:48] \\
85      setup is mostly complete
86    - State "CURR"       from "TODO"       [2010-10-12 Tue 13:47]
87    - State "TODO"       from ""           [2010-10-12 Tue 13:47]
88    This is an example of a custom setup, not really interesting at
89    this point except to remind Tony how to program.
90 #+srcname: loader
91 #+begin_src lisp
92   (in-package :cl-user)
93   (progn 
94     (defun init-CLS (&key (compile 'nil))
95       (let ((packagesToLoad (list ;; core system
96                                   :lift :lisp-matrix :cls
97                                   ;; visualization
98                                   ;; :cl-cairo2-x11 :iterate
99                                   :cl-2d
100                                   ;; doc reporting
101                                   :cl-pdf :cl-typesetting
102                                   ;;INFRA
103                                   :asdf-system-connections :xarray
104                                   ;;DOCS
105                                   :metatilities-base :anaphora :tinaa
106                                   :cl-ppcre :cl-markdown :docudown
107                                   ;; version and validate CLOS objects
108                                   ;; :versioned-objects :validations
109                                   ;;VIZ
110                                   ;; :cl-opengl
111                                   ;; :cl-glu :cl-glut :cl-glut-examples
112   
113                                   :bordeaux-threads
114                                   ;; :cells :cells-gtk
115                                   )))
116         (mapcar #'(lambda (x)
117                     (if compile
118                         (asdf:oos 'asdf:compile-op x :force T)
119                         (asdf:oos 'asdf:load-op x)))
120                 packagesToLoad)))
121   
122     (init-CLS)) ;; vs (init-CLS :compile T)
123 #+end_src
125 #+results:
126 |   | #<PACKAGE "COMMON-LISP-USER"> |
128 ** TODO [#A] Integrate with quicklist support.
129    - State "TODO"       from ""           [2010-11-30 Tue 18:00]
130    
131    important to merge with quicklisp system loader support.
132 ** CURR [#A] Testing: unit, regression, examples. [0/3]
133    - State "CURR"       from "TODO"       [2010-10-12 Tue 13:51]
134    - State "TODO"       from ""           [2010-10-12 Tue 13:51]
135    Testing consists of unit tests, which internally verify subsets of
136    code, regression tests, and functional tests (in increasing order
137    of scale).
138 *** CURR [#B] Unit tests
139     - State "CURR"       from "TODO"       [2010-11-04 Thu 18:33]
140    - State "CURR"       from "TODO"       [2010-10-12 Tue 13:48]
141    - State "TODO"       from ""           [2010-10-12 Tue 13:48]
142    Unit tests have been started using LIFT.  Need to consider some of
143    the other systems that provide testing, when people add them to the
144    mix of libraries that we need, along with examples of how to use.
146 #+srcname: ex-cls-unittest
147 #+begin_src lisp
148   (in-package :lisp-stat-unittests)
149   (run-tests :suite 'lisp-stat-ut)
150 #+end_src
152 #+results:
153 : #<Results for LISP-STAT-UT 78 Tests, 7 Failures, 20 Errors>
155   ;; => tests = 78, failures = 7, errors = 20
159 The following needs to be solved in order to have a decent
160 installation qualification (IQ) and performance qualification (PQ)
162 #+srcname: cls-unittest
163 #+begin_src lisp
164   (in-package :lisp-stat-unittests)
165   (asdf:oos 'asdf:test-op 'cls)
166   ;; which runs (describe (run-tests :suite 'lisp-stat-ut))
167 #+end_src
171    and check documentation to see if it is useful.
172 #+srcname: 
173 #+begin_src lisp
174    (in-package :lisp-stat-unittests)
176    (describe 'lisp-stat-ut)
177    (documentation 'lisp-stat-ut 'type)
179    ;; FIXME: Example: currently not relevant, yet
180    ;;   (describe (lift::run-test :test-case  'lisp-stat-unittests::create-proto
181    ;;                             :suite 'lisp-stat-unittests::lisp-stat-ut-proto))
183    (describe (lift::run-tests :suite 'lisp-stat-ut-dataframe))
184    (lift::run-tests :suite 'lisp-stat-ut-dataframe)
186    (describe (lift::run-test
187                :test-case  'lisp-stat-unittests::create-proto
188                :suite 'lisp-stat-unittests::lisp-stat-ut-proto))
189 #+end_src
191 *** TODO [#B] Regression Tests
192     - State "TODO"       from ""           [2010-10-12 Tue 13:54]
194 *** TODO [#B] Functional Tests
195     - State "TODO"       from ""           [2010-10-12 Tue 13:54]
197 ** CURR [#B] Functional Examples that need to work [1/2]
198    - State "CURR"       from "TODO"       [2010-11-30 Tue 17:57]
199    - State "TODO"       from ""           [2010-10-12 Tue 13:55]
201    These examples should be functional forms within CLS, describing
202    working functionality which is needed for work.
204 *** TODO [#B] Scoping with datasets
205     - State "TODO"       from ""           [2010-11-04 Thu 18:46]
207     The following needs to work, and a related syntax for resampling
208     and similar synthetic data approaches (bootstrapping, imputation)
209     ought to use similar syntax as well.
210 #+srcname: DataSetNameScoping
211 #+begin_src lisp
212   (in-package :ls-user)
213   (progn
214     ;; Syntax examples using lexical scope, closures, and bindings to
215     ;; ensure a clean communication of results
216     ;; This is actually a bit tricky, since we need to clarify whether
217     ;; it is line-at-a-time that we are considering or if there is
218     ;; another mapping strategy.  In particular, one could imagine a
219     ;; looping-over-observations function, or a
220     ;; looping-over-independent-observations function which leverages a
221     ;; grouping variable which provides guidance for what is considered
222     ;; independent from the sampling frame being considered. The frame
223     ;; itself (definable via some form of metadata to clarify scope?)
224     ;; could clearly provide a bit of relativity for clarifying what
225     ;; statistical independence means.
226     
227     (with-data dataset ((dsvarname1 [usevarname1])
228                         (dsvarname2 [usevarname2]))
229         @body)
230   
231     ;; SAS-centric approach to spec'ing work 
232     (looping-over-observations
233        dataset ((dsvarname1 [usevarname1])
234                 (dsvarname2 [usevarname2]))
235          @body)
236   
237     ;; SAS plus "statistical sensibility"... for example, if an
238     ;; independent observation actually consists of many observations so
239     ;; that a dataframe of independence results -- for example,
240     ;; longitudinal data or spatial data or local-truncated network data
241     ;; are clean examples of such happening -- then we get the data
242     ;; frame or row representing the independent result.
243     (looping-over-independent-observations
244        dataset independence-defining-variable
245          ((dsvarname1 [usevarname1])
246           (dsvarname2 [usevarname2]))
247          @body)
248     )
249 #+end_src
251 *** DONE [#B] Dataframe variable typing
252     - State "DONE"       from "CURR"       [2010-11-30 Tue 17:56] \\
253       check-type approach works, we would just have to throw a catchable
254       error if we want to use it in a reliable fashion.
255     - State "CURR"       from "TODO"       [2010-11-30 Tue 17:56]
256     - State "TODO"       from ""           [2010-11-04 Thu 18:48]
258     Seems to generally work, need to ensure that we use this for
259     appropriate typing.
261 #+srcname: DFvarTyping
262 #+begin_src lisp
263   (in-package :ls-user)
264   (defparameter *df-test*
265     (make-instance 'dataframe-array
266                    :storage #2A (('a "test0" 0 0d0)
267                                  ('b "test1" 1 1d0)
268                                  ('c "test2" 2 2d0)
269                                  ('d "test3" 3 3d0)
270                                  ('e "test4" 4 4d0))
271                    :doc "test reality"
272                    :case-labels (list "0" "1" 2 "3" "4")
273                    :var-labels (list "symbol" "string" "integer" "double-float")
274                    :var-types (list 'symbol 'string 'integer 'double-float)))
275   
276   ;; with SBCL, ints become floats?  Need to adjust output
277   ;; representation appropriately..
278   ,*df-test* 
279   
280   (defun check-var (df colnum)
281     (let ((nobs (xdim (dataset df) 0)))
282       (dotimes (i nobs)
283         (check-type (xref df i colnum) (elt (var-types df) i)))))
284   
285   (xdim (dataset *df-test*) 1)
286   (xdim (dataset *df-test*) 0)
287   
288   (check-var *df-test* 0)
289   
290   (class-of
291     (xref *df-test* 1 1))
292   
293   (check-type (xref *df-test* 1 1)
294               string) ;; => nil, so good.
295   (check-type (xref *df-test* 1 1)
296               vector) ;; => nil, so good.
297   (check-type (xref *df-test* 1 1)
298               real) ;; => simple-error type thrown, so good.
299   
300   ;; How to nest errors within errors?
301   (check-type (check-type (xref *df-test* 1 1) real) ;; => error thrown, so good.
302               simple-error)
303   (xref *df-test* 1 2)
304   
305   (check-type *df-test*
306               dataframe-array) ; nil is good.
307   
308   (integerp (xref *df-test* 1 2))
309   (floatp (xref *df-test* 1 2))
310   (integerp (xref *df-test* 1 3))
311   (type-of (xref *df-test* 1 3))
312   (floatp (xref *df-test* 1 3))
313   
314   (type-of (vector 1 1d0))
315   (type-of *df-test*)
316   
317   (xref *df-test* 2 1)
318   (xref *df-test* 0 0)
319   (xref *df-test* 1 0)
320   (xref *df-test* 1 '*)
321 #+end_src
322   
323 ** CURR [#A] Random Numbers [2/6]
324    - State "CURR"       from "TODO"       [2010-11-05 Fri 15:41]
325    - State "TODO"       from ""           [2010-10-14 Thu 00:12]
327    Need to select and choose a probability system (probability
328    functions, random numbers).  Goal is to have a general framework
329    for representing probability functions, functionals on
330    probabilities, and reproducible random streams based on such
331    numbers. 
332 *** CURR [#B] CL-VARIATES system evaluation [2/3]
333     - State "CURR"       from "TODO"       [2010-11-05 Fri 15:40]
334     - State "TODO"       from ""           [2010-10-12 Tue 14:16]
335     
336     CL-VARIATES is a system developed by Gary W King.  It uses streams
337     with seeds, and is hence reproducible.  (Random comment: why do CL
338     programmers as a class ignore computational reproducibility?)
339 **** DONE [#B] load and verify
340      - State "DONE"       from "CURR"       [2010-11-04 Thu 18:59] \\
341        load, init, and verify performance.
342      - State "CURR"       from "TODO"       [2010-11-04 Thu 18:58]
343      - State "TODO"       from ""           [2010-11-04 Thu 18:58]
345      <2010-11-30 Tue> : just modified cls.asd to ensure that we load
346      as appropriate the correct random variate package.
348 #+srcname: Loading-CL-VARIATES
349 #+begin_src lisp
350   (in-package :cl-user)
351   (asdf:oos 'asdf:load-op 'cl-variates)
352   (asdf:oos 'asdf:load-op 'cl-variates-test)
353 #+end_src
355 #+results:
356 : #<ASDF:LOAD-OP NIL {C2C30E1}>
357 : NIL
360 #+srcname: CL-VARIATES-UNITTESTS
361 #+begin_src lisp
362   
363   (in-package :cl-variates-test)
364   ;; check tests
365   (run-tests :suite 'cl-variates-test)
366   (describe (run-tests :suite 'cl-variates-test))
367   
368 #+end_src
370 **** DONE [#B] Examples of use
371      - State "DONE"       from "CURR"       [2010-11-05 Fri 15:39] \\
372        basic example of reproducible draws from the uniform and normal random
373        number streams.
374      - State "CURR"       from "TODO"       [2010-11-05 Fri 15:39]
375      - State "TODO"       from ""           [2010-11-04 Thu 19:01]
377 #+srcname: CL-VARIATES-REPRO
378 #+begin_src lisp
379   
380   (in-package :cl-variates-user)
381   
382   (defparameter state (make-random-number-generator))
383   (setf (random-seed state) 44)
384   
385   (random-seed state)
386   (loop for i from 1 to 10 collect
387                     (random-range state 0 10))
388   ;; => (1 5 1 0 7 1 2 2 8 10)
389   (setf (random-seed state) 44)
390   (loop for i from 1 to 10 collect
391                     (random-range state 0 10))
392   ;; => (1 5 1 0 7 1 2 2 8 10)
393   
394   (setf (random-seed state) 44)
395   (random-seed state)
396   (loop for i from 1 to 10 collect
397                     (normal-random state 0 1))
398   ;; => 
399   ;; (-1.2968656102820426 0.40746363934173213 -0.8594712469518473 0.8795681301148328
400   ;;  1.0731526250004264 -0.8161629082481728 0.7001813608754809 0.1078045427044097
401   ;;  0.20750134211656893 -0.14501914108452274)
402   
403   (setf (random-seed state) 44)
404   (loop for i from 1 to 10 collect
405                     (normal-random state 0 1))
406   ;; => 
407   ;; (-1.2968656102820426 0.40746363934173213 -0.8594712469518473 0.8795681301148328
408   ;;  1.0731526250004264 -0.8161629082481728 0.7001813608754809 0.1078045427044097
409   ;;  0.20750134211656893 -0.14501914108452274)
410   
411 #+end_src
413 **** CURR [#B] Full example of general usage 
414      - State "CURR"       from "TODO"       [2010-11-05 Fri 15:40]
415      - State "TODO"       from ""           [2010-11-05 Fri 15:40]
417      What we want to do here is describe the basic available API that
418      is present.  So while the previous work describes what the basic
419      reproducibility approach would be in terms of generating lists of
420      reproducible pRNG streams, we need the full range of possible
421      probability laws that are present. 
423      One of the good things about cl-variates is that it provides for
424      reproducibility.  One of the bad things is that it has a mixed
425      bag for an API.
427 *** TODO [#B] CL-RANDOM system evaluation
428     - State "TODO"       from ""           [2010-11-05 Fri 15:40]
430     Problems:
431     1. no seed setting for random numbers
432     2. contamination of a probability support with optimization and
433        linear algebra.
435     Positives:
436     1. good code
437     2. nice design for generics.
438        
439 *** TODO [#B] Native CLS (from XLS)
440     - State "TODO"       from ""           [2010-11-05 Fri 15:40]
441       
442 ** TODO [#B] Numerical Linear Algebra
443    - State "TODO"       from ""           [2010-10-14 Thu 00:12]
445 *** TODO [#B] LLA evaluation
446     - State "TODO"       from ""           [2010-10-12 Tue 14:13]
447 ;;; experiments with LLA
448 (in-package :cl-user)
449 (asdf:oos 'asdf:load-op 'lla)
450 (in-package :lla-user)
452 *** CURR [#B] Lisp-Matrix system evaluation
453     - State "CURR"       from "TODO"       [2010-10-12 Tue 14:13]
454     - State "TODO"       from ""           [2010-10-12 Tue 14:13]
456 *** TODO [#B] LispLab system evaluation
457     - State "TODO"       from ""           [2010-10-12 Tue 14:13]
459 ** TODO [#B] Statistical Procedures to implement
460    - State "TODO"       from ""           [2010-10-14 Thu 00:12]
462 *** PFIM 
463 (in-package :cls-user)
464 ;;;; PFIM notes
466 ;; PFIM 3.2 
468 ;; population design eval and opt
469 #| 
470 issues: 
471 - # individuals
472 - # sampling times
473 - sampling times?
475 constraints:
476 number of samples/cost of lab analysis and collection
477 expt constraints
480 (defun pfim (&key model ( constraints ( summary-function )
482   (list num-subjects num-times list-times))))
485 N individuals i
486 Each individal has a deisgn psi_i
487    nubmer of samples n_i and sampling times t_{i{1}} t_{i{n_1}}
488    individuals can differ
490 Model:
492 individual-level model 
495 (=model y_i (+ (f \theta_i \psi_i) epsilion_i ))
496 (=var \epsilion_i \sigma_between \sigma_within  )
498 ;; Information Matrix for pop deisgn 
500 (defparameter IM (sum  (i 1 N) (MF \psi_i \phi_i)))
503 For nonlinear structureal models, expand around RE=0
505 Cramer-Rao : MF^{-1} is lower bound for estimation variance.
507 Design comparisons: 
509 - smallest SE, but is a matrix, so
510 - criteria for matrix comparison
511 -- D-opt, (power (determinant MF) (/ 1 P))
514 find design maxing D opt, (power (determinant MF) (/ 1 P))
515 Design varialables 
516  -- contin vars for smapling times within interval or set -- number of groups for cat vars
518 Stat in Med 2009, expansion around post-hoc RE est, not necessarily zero.
520 Example binary covariate C
523 (if (= i reference-class) 
524     (setf (aref C i) 0)
525     (setf (aref C i) 1))
527 ;; Exponential RE,
528 (=model (log \theta) (  ))
530 ;; extensions
532 ;; outputs
535 PFIM provides for a given design and values of \beta: 
536  compute extended FIM
537  SE/RSE for \beta of each class of each covar
538  eval influence of design on SE(\beta)
540 inter-occassion variability (IOV)
541 - patients sampled more than once, H occassions
542 - RE for IOV
543 - additional vars to estimate
547 ;;; comparison criteria
549 functional of conc/time curve which is used for comparison, i.e. 
550 (AUC conc/time-curve)
551 (Cmax conc/time-curve)
552 (Tmax conc/time-curve)
554 where 
556 (defun conc/time-curve (t) 
557   ;; computation
558 #| 
559   (let ((conc (exp (* t \beta1))))
560      conc)
562   )
564 ;;See
565 (url-get "www.pfim.biostat.fr")
568 ;;; Thinking of generics...
569 (information-matrix model parameters)
570 (information-matrix variance-matrix)
571 (information-matrix model data)
572 (information-matrix list-of-individual-IMs)
575 (defun IM (loglikelihood parameters times)
576   "Does double work.  Sum up the resulting IMs to form a full IM."
577   (let ((IM (make-matrix (length parameters)
578                          (length parameters)
579                          :initial-value 0.0d0)))
580     (dolist (parameterI parameters)
581       (dolist (parameterJ parameters)
582         (setf (aref IM I J)
583               (differentiate (differentiate loglikelihood parameterI) parameterJ))))))
585 *** difference between empirical, fisherian, and ...? information.
586 *** Example of Integration with CL-GENOMIC
587     - State "TODO"       from ""           [2010-10-12 Tue 14:03]
588     
589     CL-GENOMIC is a very interesting data-structure strategy for
590     manipulating sequence data.
592 #+srcname: 
593 #+begin_src lisp
594     (in-package :cl-user)
595     (asdf:oos 'asdf:compile-op :ironclad)
596     (asdf:oos 'asdf:load-op :cl-genomic)
598     (in-package :bio-sequence)
599     (make-dna "agccg") ;; fine
600     (make-aa "agccg")  ;; fine
601     (make-aa "agc9zz") ;; error expected
602 #+end_src
604 ** TODO [#B] Documentation and Examples [0/3]
605    - State "TODO"       from ""           [2010-10-14 Thu 00:12]
607 *** TODO [#B] Docudown
608     - State "TODO"       from ""           [2010-11-05 Fri 15:34]
610 *** TODO [#A] CLDOC
611     - State "TODO"       from ""           [2010-11-05 Fri 15:34]
613 *** TODO [#B] CLPDF, and literate data analysis
614     - State "TODO"       from ""           [2010-11-05 Fri 15:34]
616 * Proposals
617   Place proposals for features, work, etc here...
618 ** <2011-12-29 Thu> new stuff
619    First new proposal is to track proposals.
620 * Rejoinder
621   This project is dedicated to all the lisp hackers out there who
622   provided the basic infrastructure to get so far so fast with minimal
623   effort on my part.