examples for mean and lispy summing.
[CommonLispStat.git] / TODO.lisp
blob809c1a61a894a6264de6c10e0691bdcb167ddbc1
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2008-12-04 17:29:12 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...
55 (def m (regression-model (list iron aluminum) absorbtion :print nil))
57 (defparameter *indep-vars-1-matrix*
58 (make-matrix 1 (length iron)
59 :initial-contents
60 (list (mapcar #'(lambda (x) (coerce x 'double-float))
61 iron))))
62 ;; *indep-vars-1-matrix*
64 (defparameter *indep-vars-2-matrix*
65 (make-matrix 2 (length iron)
66 :initial-contents
67 (list
68 (mapcar #'(lambda (x) (coerce x 'double-float))
69 iron)
70 (mapcar #'(lambda (x) (coerce x 'double-float))
71 aluminum))))
72 ;; *indep-vars-2-matrix*
75 ;; FAILS due to coercion issues; it just isn't lispy, it's R'y.
76 ;; (defparameter *dep-var* (make-vector (length absorbtion)
77 ;; :initial-contents (list absorbtion)))
78 ;; BUT this should be the right type.
79 (defparameter *dep-var*
80 (make-vector (length absorbtion)
81 :type :row
82 :initial-contents
83 (list
84 (mapcar #'(lambda (x) (coerce x 'double-float))
85 absorbtion))))
86 ;; *dep-var*
89 (defparameter *dep-var-int*
90 (make-vector (length absorbtion)
91 :type :row
92 :element-type 'integer
93 :initial-contents (list absorbtion)))
95 (typep *dep-var* 'matrix-like) ; => T
96 (typep *dep-var* 'vector-like) ; => T
98 (typep *indep-vars-1-matrix* 'matrix-like) ; => T
99 (typep *indep-vars-1-matrix* 'vector-like) ; => T
100 (typep *indep-vars-2-matrix* 'matrix-like) ; => T
101 (typep *indep-vars-2-matrix* 'vector-like) ; => F
103 (def m1 (regression-model-new *indep-vars-1-matrix* *dep-var* ))
104 (def m2 (regression-model-new *indep-vars-2-matrix* *dep-var* ))
106 iron
107 ;; following fails, need to ensure that we work on list elts, not just
108 ;; elts within a list:
109 ;; (coerce iron 'real)
111 ;; the following is a general list-conversion coercion approach -- is
112 ;; there a more efficient way?
113 (mapcar #'(lambda (x) (coerce x 'double-float)) iron)
115 (coerce 1 'real)
117 (send m :compute)
118 (send m :sweep-matrix)
119 (format t "~%~A~%" (send m :sweep-matrix))
121 ;; need to get multiple-linear regression working (simple linear regr
122 ;; works)... to do this, we need to redo the whole numeric structure,
123 ;; I'm keeping these in as example of brokenness...
125 (send m :basis) ;; this should be positive?
126 (send m :coef-estimates)
132 (progn ;; FIXME: Need to clean up data examples, licenses, attributions, etc.
134 ;; The following breaks because we should use a package to hold
135 ;; configuration details, and this would be the only package outside
136 ;; of packages.lisp, as it holds the overall defsystem structure.
137 (load-data "iris.lsp") ;; (the above partially fixed).
138 (variables)
139 diabetes
142 (progn
143 ;; FIXME: Data.Frames probably deserve to be related to lists --
144 ;; either lists of cases, or lists of variables. We probably do not
145 ;; want to mix them, but want to be able to convert between such
146 ;; structures.
148 (defparameter *my-case-data*
149 '((:cases
150 (:case1 Y Med 3.4 5)
151 (:case2 N Low 3.2 3)
152 (:case3 Y High 3.1 4))
153 (:var-names (list "Response" "Level" "Pressure" "Size"))))
155 *my-case-data*
157 (elt *my-case-data* 1)
158 (elt *my-case-data* 0)
159 (elt *my-case-data* 2) ;; error
160 (elt (elt *my-case-data* 0) 1)
161 (elt (elt *my-case-data* 0) 0)
162 (elt (elt (elt *my-case-data* 0) 1) 0)
163 (elt (elt (elt *my-case-data* 0) 1) 1)
164 (elt (elt (elt *my-case-data* 0) 1) 2)
165 (elt (elt *my-case-data* 0) 3)
170 (progn ;; FIXME: read data from CSV file. To do.
172 ;; challenge is to ensure that we get mixed arrays when we want them,
173 ;; and single-type (simple) arrays in other cases.
175 (defparameter *csv-num* (read-csv "Data/example-num.csv" :type 'numeric))
176 (defparameter *csv-mix* (read-csv "Data/example-mixed.csv" :type 'data))
178 ;; The handling of these types should be compariable to what we do for
179 ;; matrices, but without the numerical processing. i.e. mref, bind2,
180 ;; make-dataframe, and the class structure should be similar.
182 ;; With numerical data, there should be a straightforward mapping from
183 ;; the data.frame to a matrix. With categorical data (including
184 ;; dense categories such as doc-strings, as well as sparse categories
185 ;; such as binary data), we need to include metadata about ordering,
186 ;; coding, and such. So the structures should probably consider
188 ;; Using the CSV file:
190 (asdf:oos 'asdf:compile-op 'csv :force t)
191 (asdf:oos 'asdf:load-op 'parse-number)
192 (asdf:oos 'asdf:load-op 'csv)
193 (fare-csv:read-csv-file "Data/example-numeric.csv")
195 ;; but I think the cl-csv package is broken, need to use the dsv-style
196 ;; package.
200 (progn
201 (defparameter *x* (make-vector 5 :initial-contents '((1d0 2d0 3d0 4d0 5d0))))
202 (/ (loop for i from 0 to (- (nelts *x*) 1)
203 summing (vref *x* i))
204 (nelts *x*)))