starting on regression generics (so that lists or lisp-matrix input works).
[CommonLispStat.git] / TODO.lisp
blobbcecc83839b5ded44a2e8df08a47942c6913a986
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2008-12-07 10:42:43 tony>
4 ;;; Creation: <2008-09-08 08:06:30 tony>
5 ;;; File: TODO.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c) 2007-2008, AJ Rossini <blindglobe@gmail.com>. BSD.
8 ;;; Purpose: demonstrations of how one might use CLS.
10 ;;; What is this talk of 'release'? Klingons do not make software
11 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
12 ;;; designers and quality assurance people in its wake.
14 ;;; This file contains the current challenges to solve, including a
15 ;;; description of the setup and the work to solve....
17 ;;; SET UP
19 (in-package :cl-user)
20 ;;(asdf:oos 'asdf:compile-op 'lispstat)
21 ;;(asdf:oos 'asdf:load-op 'lispstat)
23 (in-package :lisp-stat-unittests)
25 (describe (run-tests :suite 'lisp-stat-ut))
26 (run-tests :suite 'lisp-stat-ut)
27 ;; tests = 68, failures = 12, errors = 7
29 (in-package :ls-user)
31 ;;; FIXME: Example: currently not relevant, yet
33 (describe
34 (lift::run-test
35 :test-case 'lisp-stat-unittests::create-proto
36 :suite 'lisp-stat-unittests::lisp-stat-ut-proto))
39 :;; FIXME: data frames and structural inheritance
41 ;; Serious flaw -- need to consider that we are not really well
42 ;; working with the data structures, in that Luke created compound as
43 ;; a base class, which turns out to be slightly backward if we are to
44 ;; maintain the numerical structures as well as computational
45 ;; efficiency.
49 ;;; FIXME: Regression modeling
50 (progn
52 (defparameter m nil
53 "holding variable.")
54 ;; need to make vectors and matrices from the lists...
56 (def m (regression-model (list iron aluminum) absorbtion :print nil))
58 (defparameter *indep-vars-1-matrix*
59 (make-matrix 1 (length iron)
60 :initial-contents
61 (list (mapcar #'(lambda (x) (coerce x 'double-float))
62 iron))))
63 ;; *indep-vars-1-matrix*
65 (defparameter *indep-vars-2-matrix*
66 (make-matrix 2 (length iron)
67 :initial-contents
68 (list
69 (mapcar #'(lambda (x) (coerce x 'double-float))
70 iron)
71 (mapcar #'(lambda (x) (coerce x 'double-float))
72 aluminum))))
73 ;; *indep-vars-2-matrix*
76 ;; FAILS due to coercion issues; it just isn't lispy, it's R'y.
77 ;; (defparameter *dep-var* (make-vector (length absorbtion)
78 ;; :initial-contents (list absorbtion)))
79 ;; BUT this should be the right type.
80 (defparameter *dep-var*
81 (make-vector (length absorbtion)
82 :type :row
83 :initial-contents
84 (list
85 (mapcar #'(lambda (x) (coerce x 'double-float))
86 absorbtion))))
87 ;; *dep-var*
90 (defparameter *dep-var-int*
91 (make-vector (length absorbtion)
92 :type :row
93 :element-type 'integer
94 :initial-contents (list absorbtion)))
96 (typep *dep-var* 'matrix-like) ; => T
97 (typep *dep-var* 'vector-like) ; => T
99 (typep *indep-vars-1-matrix* 'matrix-like) ; => T
100 (typep *indep-vars-1-matrix* 'vector-like) ; => T
101 (typep *indep-vars-2-matrix* 'matrix-like) ; => T
102 (typep *indep-vars-2-matrix* 'vector-like) ; => F
104 (def m1 (regression-model-new *indep-vars-1-matrix* *dep-var* ))
105 (def m2 (regression-model-new *indep-vars-2-matrix* *dep-var* ))
107 iron
108 ;; following fails, need to ensure that we work on list elts, not just
109 ;; elts within a list:
110 ;; (coerce iron 'real)
112 ;; the following is a general list-conversion coercion approach -- is
113 ;; there a more efficient way?
114 (mapcar #'(lambda (x) (coerce x 'double-float)) iron)
116 (coerce 1 'real)
118 (send m :compute)
119 (send m :sweep-matrix)
120 (format t "~%~A~%" (send m :sweep-matrix))
122 ;; need to get multiple-linear regression working (simple linear regr
123 ;; works)... to do this, we need to redo the whole numeric structure,
124 ;; I'm keeping these in as example of brokenness...
126 (send m :basis) ;; this should be positive?
127 (send m :coef-estimates)
133 (progn ;; FIXME: Need to clean up data examples, licenses, attributions, etc.
135 ;; The following breaks because we should use a package to hold
136 ;; configuration details, and this would be the only package outside
137 ;; of packages.lisp, as it holds the overall defsystem structure.
138 (load-data "iris.lsp") ;; (the above partially fixed).
139 (variables)
140 diabetes
143 (progn
144 ;; FIXME: Data.Frames probably deserve to be related to lists --
145 ;; either lists of cases, or lists of variables. We probably do not
146 ;; want to mix them, but want to be able to convert between such
147 ;; structures.
149 (defparameter *my-case-data*
150 '((:cases
151 (:case1 Y Med 3.4 5)
152 (:case2 N Low 3.2 3)
153 (:case3 Y High 3.1 4))
154 (:var-names (list "Response" "Level" "Pressure" "Size"))))
156 *my-case-data*
158 (elt *my-case-data* 1)
159 (elt *my-case-data* 0)
160 (elt *my-case-data* 2) ;; error
161 (elt (elt *my-case-data* 0) 1)
162 (elt (elt *my-case-data* 0) 0)
163 (elt (elt (elt *my-case-data* 0) 1) 0)
164 (elt (elt (elt *my-case-data* 0) 1) 1)
165 (elt (elt (elt *my-case-data* 0) 1) 2)
166 (elt (elt *my-case-data* 0) 3)
171 (progn ;; FIXME: read data from CSV file. To do.
173 ;; challenge is to ensure that we get mixed arrays when we want them,
174 ;; and single-type (simple) arrays in other cases.
176 (defparameter *csv-num* (read-csv "Data/example-num.csv" :type 'numeric))
177 (defparameter *csv-mix* (read-csv "Data/example-mixed.csv" :type 'data))
179 ;; The handling of these types should be compariable to what we do for
180 ;; matrices, but without the numerical processing. i.e. mref, bind2,
181 ;; make-dataframe, and the class structure should be similar.
183 ;; With numerical data, there should be a straightforward mapping from
184 ;; the data.frame to a matrix. With categorical data (including
185 ;; dense categories such as doc-strings, as well as sparse categories
186 ;; such as binary data), we need to include metadata about ordering,
187 ;; coding, and such. So the structures should probably consider
189 ;; Using the CSV file:
191 (asdf:oos 'asdf:compile-op 'csv :force t)
192 (asdf:oos 'asdf:load-op 'parse-number)
193 (asdf:oos 'asdf:load-op 'csv)
194 (fare-csv:read-csv-file "Data/example-numeric.csv")
196 ;; but I think the cl-csv package is broken, need to use the dsv-style
197 ;; package.
201 (progn
202 (defparameter *x* (make-vector 5 :initial-contents '((1d0 2d0 3d0 4d0 5d0))))
203 (/ (loop for i from 0 to (- (nelts *x*) 1)
204 summing (vref *x* i))
205 (nelts *x*)))
208 (progn
209 ;;; A study in array vs list access
210 (defparameter *x* (list 1 2 3))
211 (defparameter *y* #(1 2 3))
212 (nth 1 *x*)
213 (aref *y* 1)
214 (setf (nth 1 *x*) 6)
216 (setf (aref *y* 1) 6)