2 Time-stamp: <2012-10-04 17:26:54 tony>
3 Creation: <2008-09-08 08:06:30 tony>
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
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 Documentation
23 This section provides some of the details regarding infrastructure of
24 the system, as a means of including TODO statements.
26 ** (Internal) Package and (External) System Hierarchy
28 current (possibly incomplete) set of lisp dependencies <2012-10-04 Thu>
30 0 ~/sandbox/xarray.git
31 1 ~/sandbox/foreign-numeric-vector.git
32 2 ~/sandbox/trivial-features.git
33 3 ~/sandbox/alexandria.git
36 6 ~/sandbox/cl-utilities
37 7 ~/sandbox/metabang-bind.git
38 8 ~/sandbox/iterate.git
39 9 ~/sandbox/array-operations.git
42 *** Singletons (primary building blocks)
44 These are packages as well as
46 | asdf | common system loader |
47 | xarray | common access structure to array-like |
48 | | (matrix, vector) structures. |
49 | cls-config | initialization of Lisp state, variables, etc, |
50 | | localization to the particular lisp. |
51 | lift | unit-testing |
52 | cffi | foriegn function library |
58 as of now, all are in QL heirarchy
60 *** Dependency structure
62 | lisp-matrix | general purpose matrix package, linking to lapack | |
63 | | for numerics. Depends on: | |
66 | | cl-blapack | cffi |
68 | cls-dataframe | in the same spirit as lisp-matrix, a means to | |
69 | | create tables. Perhaps better called datatables? | |
70 | cls-probability | depends on gsll, cl-variates, cl-? initially, | |
74 **** Random number streams and probability calculus
77 Something for random numbers, that has a settable seed. However,
78 we could pass on the "right thing" in favor of something that
82 **** import of data in text files
84 CSV and similar specialized imports
98 Usually, we need to load it before going on.
108 though sometimes we might want to recompile fully. (Can this be
109 done via QL? Need to check)
111 #+name: compile-it-all
113 (asdf:oos 'asdf:compile-op :cls :force T)
118 - State "DONE" from "CURR" [2010-10-12 Tue 13:48] \\
119 setup is mostly complete
120 - State "CURR" from "TODO" [2010-10-12 Tue 13:47]
121 - State "TODO" from "" [2010-10-12 Tue 13:47]
122 This is an example of a custom setup, not really interesting at
123 this point except to remind Tony how to program.
126 (in-package :cl-user)
128 (defun init-CLS (&key (compile 'nil))
129 (let ((packagesToLoad (list ;; core system
130 :lift :lisp-matrix :cls
132 ;; :cl-cairo2-x11 :iterate
135 :cl-pdf :cl-typesetting
137 :asdf-system-connections :xarray
139 :metatilities-base :anaphora :tinaa
140 :cl-ppcre :cl-markdown :docudown
141 ;; version and validate CLOS objects
142 ;; :versioned-objects :validations
145 ;; :cl-glu :cl-glut :cl-glut-examples
150 (mapcar #'(lambda (x)
152 (asdf:oos 'asdf:compile-op x :force T)
153 (asdf:oos 'asdf:load-op x)))
156 (init-CLS)) ;; vs (init-CLS :compile T)
160 | | #<PACKAGE "COMMON-LISP-USER"> |
162 ** TODO [#A] Integrate with quicklist support.
163 - State "TODO" from "" [2010-11-30 Tue 18:00]
165 important to merge with quicklisp system loader support.
166 ** CURR [#A] Testing: unit, regression, examples. [0/3]
167 - State "CURR" from "TODO" [2010-10-12 Tue 13:51]
168 - State "TODO" from "" [2010-10-12 Tue 13:51]
169 Testing consists of unit tests, which internally verify subsets of
170 code, regression tests, and functional tests (in increasing order
172 *** CURR [#B] Unit tests
173 - State "CURR" from "TODO" [2010-11-04 Thu 18:33]
174 - State "CURR" from "TODO" [2010-10-12 Tue 13:48]
175 - State "TODO" from "" [2010-10-12 Tue 13:48]
176 Unit tests have been started using LIFT. Need to consider some of
177 the other systems that provide testing, when people add them to the
178 mix of libraries that we need, along with examples of how to use.
180 #+name: ex-cls-unittest
182 (in-package :lisp-stat-unittests)
183 (run-tests :suite 'lisp-stat-ut)
187 : #<Results for LISP-STAT-UT 78 Tests, 7 Failures, 20 Errors>
189 ;; => tests = 78, failures = 7, errors = 20
193 The following needs to be solved in order to have a decent
194 installation qualification (IQ) and performance qualification (PQ)
198 (in-package :lisp-stat-unittests)
199 (asdf:oos 'asdf:test-op 'cls)
200 ;; which runs (describe (run-tests :suite 'lisp-stat-ut))
205 and check documentation to see if it is useful.
208 (in-package :lisp-stat-unittests)
210 (describe 'lisp-stat-ut)
211 (documentation 'lisp-stat-ut 'type)
213 ;; FIXME: Example: currently not relevant, yet
214 ;; (describe (lift::run-test :test-case 'lisp-stat-unittests::create-proto
215 ;; :suite 'lisp-stat-unittests::lisp-stat-ut-proto))
217 (describe (lift::run-tests :suite 'lisp-stat-ut-dataframe))
218 (lift::run-tests :suite 'lisp-stat-ut-dataframe)
220 (describe (lift::run-test
221 :test-case 'lisp-stat-unittests::create-proto
222 :suite 'lisp-stat-unittests::lisp-stat-ut-proto))
225 *** TODO [#B] Regression Tests
226 - State "TODO" from "" [2010-10-12 Tue 13:54]
228 *** TODO [#B] Functional Tests
229 - State "TODO" from "" [2010-10-12 Tue 13:54]
231 ** CURR [#B] Functional Examples that need to work [1/3]
232 - State "CURR" from "TODO" [2010-11-30 Tue 17:57]
233 - State "TODO" from "" [2010-10-12 Tue 13:55]
235 These examples should be functional forms within CLS, describing
236 working functionality which is needed for work.
237 *** TODO [#A] Dataframe creation
238 Illustration via a file, that we need to get working so that we
239 can get data in-and-out of CLS structures.
241 #+BEGIN_SRC lisp :export examples/example-DF-creation.lisp
242 ;;; -*- mode: lisp -*-
243 ;;; Copyright (c) 2006-2012, by A.J. Rossini <blindglobe@gmail.com>
244 ;;; See COPYRIGHT file for any additional restrictions (BSD license).
245 ;;; Since 1991, ANSI was finally finished. Edited for ANSI Common Lisp.
247 ;;; Time-stamp: <2012-10-04 02:16:45 tony>
248 ;;; Creation: <2012-07-01 11:29:42 tony>
249 ;;; File: example.lisp
250 ;;; Author: AJ Rossini <blindglobe@gmail.com>
251 ;;; Copyright: (c) 2012, AJ Rossini. BSD.
252 ;;; Purpose: example of possible usage.
254 ;;; What is this talk of 'release'? Klingons do not make software
255 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
256 ;;; designers and quality assurance people in its wake.
262 ;; use the example package...
263 (in-package :cls-user)
266 ;; or better yet, create a package/namespace for the particular problem being attacked.
267 (defpackage :my-package-user
268 (:documentation "demo of how to put serious work should be placed in
269 a similar package elsewhere for reproducibility. This hints as to
270 what needs to be done for a user- or analysis-package.")
271 (:nicknames :my-clswork-user)
272 (:use :common-lisp ; always needed for user playgrounds!
273 :lisp-matrix ; we only need the packages that we need...
274 :common-lisp-statistics
275 :lisp-stat-data-examples) ;; this ensures access to a data package
276 (:export summarize-data summarize-results this-data this-report)
277 (:shadowing-import-from :lisp-stat call-method call-next-method
279 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
280 asin acos atan sinh cosh tanh asinh acosh atanh float random
281 truncate floor ceiling round minusp zerop plusp evenp oddp
282 < <= = /= >= > > ;; complex
283 conjugate realpart imagpart phase
284 min max logand logior logxor lognot ffloor fceiling
285 ftruncate fround signum cis
289 (in-package :my-clswork-user)
291 ;; create some data by hand using arrays, and demonstrate access.
293 (let ((myArray #2A((1 2 3)(4 5 6)))
294 (myDF (make-dataframe #2A((1 2 3)(4 5 6))))
295 (myLOL (list (list 1 2 3) (list 4 5 6)))
296 ;; FIXME: listoflist conversion does not work.
297 ;; (myDFlol (make-dataframe '(list ((1 2 3)(4 5 6)))))
300 (= (xref myArray 1 1)
305 *** TODO [#B] Scoping with datasets
306 - State "TODO" from "" [2010-11-04 Thu 18:46]
308 The following needs to work, and a related syntax for resampling
309 and similar synthetic data approaches (bootstrapping, imputation)
310 ought to use similar syntax as well.
311 #+name: DataSetNameScoping
313 (in-package :ls-user)
315 ;; Syntax examples using lexical scope, closures, and bindings to
316 ;; ensure a clean communication of results
317 ;; This is actually a bit tricky, since we need to clarify whether
318 ;; it is line-at-a-time that we are considering or if there is
319 ;; another mapping strategy. In particular, one could imagine a
320 ;; looping-over-observations function, or a
321 ;; looping-over-independent-observations function which leverages a
322 ;; grouping variable which provides guidance for what is considered
323 ;; independent from the sampling frame being considered. The frame
324 ;; itself (definable via some form of metadata to clarify scope?)
325 ;; could clearly provide a bit of relativity for clarifying what
326 ;; statistical independence means.
328 (with-data dataset ((dsvarname1 [usevarname1])
329 (dsvarname2 [usevarname2]))
332 ;; SAS-centric approach to spec'ing work
333 (looping-over-observations
334 dataset ((dsvarname1 [usevarname1])
335 (dsvarname2 [usevarname2]))
338 ;; SAS plus "statistical sensibility"... for example, if an
339 ;; independent observation actually consists of many observations so
340 ;; that a dataframe of independence results -- for example,
341 ;; longitudinal data or spatial data or local-truncated network data
342 ;; are clean examples of such happening -- then we get the data
343 ;; frame or row representing the independent result.
344 (looping-over-independent-observations
345 dataset independence-defining-variable
346 ((dsvarname1 [usevarname1])
347 (dsvarname2 [usevarname2]))
352 *** DONE [#B] Dataframe variable typing
353 - State "DONE" from "CURR" [2010-11-30 Tue 17:56] \\
354 check-type approach works, we would just have to throw a catchable
355 error if we want to use it in a reliable fashion.
356 - State "CURR" from "TODO" [2010-11-30 Tue 17:56]
357 - State "TODO" from "" [2010-11-04 Thu 18:48]
359 Seems to generally work, need to ensure that we use this for
364 (in-package :ls-user)
365 (defparameter *df-test*
366 (make-instance 'dataframe-array
367 :storage #2A (('a "test0" 0 0d0)
373 :case-labels (list "0" "1" 2 "3" "4")
374 :var-labels (list "symbol" "string" "integer" "double-float")
375 :var-types (list 'symbol 'string 'integer 'double-float)))
377 ;; with SBCL, ints become floats? Need to adjust output
378 ;; representation appropriately..
381 (defun check-var (df colnum)
382 (let ((nobs (xdim (dataset df) 0)))
384 (check-type (xref df i colnum) (elt (var-types df) i)))))
386 (xdim (dataset *df-test*) 1)
387 (xdim (dataset *df-test*) 0)
389 (check-var *df-test* 0)
392 (xref *df-test* 1 1))
394 (check-type (xref *df-test* 1 1)
395 string) ;; => nil, so good.
396 (check-type (xref *df-test* 1 1)
397 vector) ;; => nil, so good.
398 (check-type (xref *df-test* 1 1)
399 real) ;; => simple-error type thrown, so good.
401 ;; How to nest errors within errors?
402 (check-type (check-type (xref *df-test* 1 1) real) ;; => error thrown, so good.
406 (check-type *df-test*
407 dataframe-array) ; nil is good.
409 (integerp (xref *df-test* 1 2))
410 (floatp (xref *df-test* 1 2))
411 (integerp (xref *df-test* 1 3))
412 (type-of (xref *df-test* 1 3))
413 (floatp (xref *df-test* 1 3))
415 (type-of (vector 1 1d0))
421 (xref *df-test* 1 '*)
424 ** CURR [#A] Random Numbers [2/6]
425 - State "CURR" from "TODO" [2010-11-05 Fri 15:41]
426 - State "TODO" from "" [2010-10-14 Thu 00:12]
428 Need to select and choose a probability system (probability
429 functions, random numbers). Goal is to have a general framework
430 for representing probability functions, functionals on
431 probabilities, and reproducible random streams based on such
433 *** CURR [#B] CL-VARIATES system evaluation [2/3]
434 - State "CURR" from "TODO" [2010-11-05 Fri 15:40]
435 - State "TODO" from "" [2010-10-12 Tue 14:16]
437 CL-VARIATES is a system developed by Gary W King. It uses streams
438 with seeds, and is hence reproducible. (Random comment: why do CL
439 programmers as a class ignore computational reproducibility?)
441 The main problem with this system is licensing. It has a weird
442 licensing schema which prevents
444 #+name: Loading-CL-VARIATES
446 (in-package :cl-user)
447 (ql:quickload :cl-variates)
448 ;;(ql:quickload :cl-variates-test)
451 #+name: CL-VARIATES-UNITTESTS
453 (in-package :cl-variates-test)
455 (run-tests :suite 'cl-variates-test)
456 (describe (run-tests :suite 'cl-variates-test))
459 basic example of reproducible draws from the uniform and normal
460 random number streams.
462 #+name: CL-VARIATES-REPRO
465 (in-package :cl-variates-user)
467 (defparameter state (make-random-number-generator))
468 (setf (random-seed state) 44)
471 (loop for i from 1 to 10 collect
472 (random-range state 0 10))
473 ;; => (1 5 1 0 7 1 2 2 8 10)
474 (setf (random-seed state) 44)
475 (loop for i from 1 to 10 collect
476 (random-range state 0 10))
477 ;; => (1 5 1 0 7 1 2 2 8 10)
479 (setf (random-seed state) 44)
481 (loop for i from 1 to 10 collect
482 (normal-random state 0 1))
484 ;; (-1.2968656102820426 0.40746363934173213 -0.8594712469518473 0.8795681301148328
485 ;; 1.0731526250004264 -0.8161629082481728 0.7001813608754809 0.1078045427044097
486 ;; 0.20750134211656893 -0.14501914108452274)
488 (setf (random-seed state) 44)
489 (loop for i from 1 to 10 collect
490 (normal-random state 0 1))
492 ;; (-1.2968656102820426 0.40746363934173213 -0.8594712469518473 0.8795681301148328
493 ;; 1.0731526250004264 -0.8161629082481728 0.7001813608754809 0.1078045427044097
494 ;; 0.20750134211656893 -0.14501914108452274)
498 **** CURR [#B] Full example of general usage
499 - State "CURR" from "TODO" [2010-11-05 Fri 15:40]
500 - State "TODO" from "" [2010-11-05 Fri 15:40]
502 What we want to do here is describe the basic available API that
503 is present. So while the previous work describes what the basic
504 reproducibility approach would be in terms of generating lists of
505 reproducible pRNG streams, we need the full range of possible
506 probability laws that are present.
508 One of the good things about cl-variates is that it provides for
509 reproducibility. One of the bad things is that it has a mixed
512 *** TODO [#B] CL-RANDOM system evaluation
513 - State "TODO" from "" [2010-11-05 Fri 15:40]
516 1. no seed setting for random numbers
517 2. contamination of a probability support with optimization and
522 2. nice design for generics.
524 *** TODO [#B] Native CLS (from XLS)
525 - State "TODO" from "" [2010-11-05 Fri 15:40]
527 ** TODO [#B] Numerical Linear Algebra
528 - State "TODO" from "" [2010-10-14 Thu 00:12]
530 *** TODO [#B] LLA evaluation
531 - State "TODO" from "" [2010-10-12 Tue 14:13]
533 LLA is an SBCL targetted linear algebra library from Tamas Papp
535 #+NAME LLA-experiments
537 (in-package :cl-user)
538 (asdf:oos 'asdf:load-op 'lla)
539 (in-package :lla-user)
543 *** CURR [#B] Lisp-Matrix system evaluation
544 - State "CURR" from "TODO" [2010-10-12 Tue 14:13]
545 - State "TODO" from "" [2010-10-12 Tue 14:13]
549 *** TODO [#B] LispLab system evaluation
550 - State "TODO" from "" [2010-10-12 Tue 14:13]
552 LL is an SBCL targetted linear algebra library from ---
554 ** TODO [#B] Statistical Procedures to implement
555 - State "TODO" from "" [2010-10-14 Thu 00:12]
561 (in-package :cls-user)
566 ;; population design eval and opt
574 number of samples/cost of lab analysis and collection
578 (defun pfim (&key model ( constraints ( summary-function )
580 (list num-subjects num-times list-times))))
584 Each individal has a deisgn psi_i
585 nubmer of samples n_i and sampling times t_{i{1}} t_{i{n_1}}
586 individuals can differ
590 individual-level model
593 (=model y_i (+ (f \theta_i \psi_i) epsilion_i ))
594 (=var \epsilion_i \sigma_between \sigma_within )
596 ;; Information Matrix for pop deisgn
598 (defparameter IM (sum (i 1 N) (MF \psi_i \phi_i)))
601 For nonlinear structureal models, expand around RE=0
603 Cramer-Rao : MF^{-1} is lower bound for estimation variance.
607 - smallest SE, but is a matrix, so
608 - criteria for matrix comparison
609 -- D-opt, (power (determinant MF) (/ 1 P))
612 find design maxing D opt, (power (determinant MF) (/ 1 P))
614 -- contin vars for smapling times within interval or set -- number of groups for cat vars
616 Stat in Med 2009, expansion around post-hoc RE est, not necessarily zero.
618 Example binary covariate C
621 (if (= i reference-class)
626 (=model (log \theta) ( ))
633 PFIM provides for a given design and values of \beta:
635 SE/RSE for \beta of each class of each covar
636 eval influence of design on SE(\beta)
638 inter-occassion variability (IOV)
639 - patients sampled more than once, H occassions
641 - additional vars to estimate
645 ;;; comparison criteria
647 functional of conc/time curve which is used for comparison, i.e.
648 (AUC conc/time-curve)
649 (Cmax conc/time-curve)
650 (Tmax conc/time-curve)
654 (defun conc/time-curve (t)
657 (let ((conc (exp (* t \beta1))))
663 (url-get "www.pfim.biostat.fr")
666 ;;; Thinking of generics...
667 (information-matrix model parameters)
668 (information-matrix variance-matrix)
669 (information-matrix model data)
670 (information-matrix list-of-individual-IMs)
673 (defun IM (loglikelihood parameters times)
674 "Does double work. Sum up the resulting IMs to form a full IM."
675 (let ((IM (make-matrix (length parameters)
677 :initial-value 0.0d0)))
678 (dolist (parameterI parameters)
679 (dolist (parameterJ parameters)
681 (differentiate (differentiate loglikelihood parameterI) parameterJ))))))
684 *** difference between empirical, fisherian, and ...? information.
685 *** TODO [#C] Example of Integration with CL-GENOMIC
686 - State "TODO" from "" [2010-10-12 Tue 14:03]
688 CL-GENOMIC is a very interesting data-structure strategy for
689 manipulating sequence data.
693 (in-package :cl-user)
694 (asdf:oos 'asdf:compile-op :ironclad)
695 (asdf:oos 'asdf:load-op :cl-genomic)
697 (in-package :bio-sequence)
698 (make-dna "agccg") ;; fine
699 (make-aa "agccg") ;; fine
700 (make-aa "agc9zz") ;; error expected
704 ** TODO [#B] Documentation and Examples [0/3]
705 - State "TODO" from "" [2010-10-14 Thu 00:12]
707 *** TODO [#B] Docudown
708 - State "TODO" from "" [2010-11-05 Fri 15:34]
711 - State "TODO" from "" [2010-11-05 Fri 15:34]
713 *** TODO [#B] CLPDF, and literate data analysis
714 - State "TODO" from "" [2010-11-05 Fri 15:34]
717 Place proposals for features, work, etc here...
718 ** <2011-12-29 Thu> new stuff
719 First new proposal is to track proposals.
723 This project is dedicated to all the lisp hackers out there who
724 provided the basic infrastructure to get so far so fast with minimal
727 And to all the people trying to help to get this off the ground.