3 ;;; File: data-clos.lisp
4 ;;; Author: AJ Rossini <blindglobe@gmail.com>
5 ;;; Copyright: (c)2008, AJ Rossini. BSD, LLGPL, or GPLv2, depending
7 ;;; Purpose: data package for lispstat
8 ;;; Time-stamp: <2008-03-12 17:18:42 user>
9 ;;; Creation: <2008-03-12 17:18:42 user>
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
15 ;;; This organization and structure is new to the 21st Century
20 ;;; redoing regression in a CLOS based framework.
21 ;;; See regression.lsp for basis of work.
25 (defpackage :lisp-stat-data-clos
27 :clem
;;?? or :matlisp , or :...?
29 (:export dataset varNames caseNames
))
31 (in-package :lisp-stat-data-clos
)
34 ;; Need to figure out typed vectors. We then map a series of typed
35 ;; vectors over to tables where columns are equal typed. In a sense,
36 ;; this is a relation (1-1) of equal-typed arrays. For the most part,
37 ;; this ends up making the R data.frame into a relational building
38 ;; block (considering 1-1 mappings using row ID as a relation).
43 (defclass relation
())
49 (documentation-string :initform nil
52 (case-labels :initform nil
54 :accessor case-labels
)
55 (var-labels :initform nil
57 :accessor var-labels
))
58 (:documentation
"Standard Cases by Variables Dataset."))
60 ;; Need to set up dataset as a table or a relation. One way or
61 ;; another it should all work out. TODO: How do we do multiple
62 ;; inheritance or composite structures?
65 "test ds for experiment.")
66 (setf my-ds-1
(make-instance 'dataset
))
70 "test ds for experiment.")
71 (setf my-ds-2
(make-instance 'dataset
72 :storage
#2((1 2 3 4 5) (10 20 30 40 50))
73 :doc
"This is an interesting dataset"
74 :case-labels
(list "a" "b" "c" "d" "e")
75 :var-labels
(list "x" "y")))
78 (slot-value my-ds-2
'store
)
80 (eq (dataset my-ds-2
) (slot-value my-ds-2
'store
))
85 ;; need to ensure that for things like the following, that we protect
86 ;; this a bit more so that the results are not going to to be wrong.
87 ;; That would be a bit nasty if the dataset becomes inconsistent.
88 (setf (var-labels my-ds-2
) (list "a" "b"))
93 (defun print-structure-table (ds)
94 "example of what we want the methods to look like. Should be sort
95 of like a spreadsheet if the storage is a table."
96 (print-as-row (var-labels ds
))
98 (dolist (i (case-labels ds
))
99 (princ "%i %v" i
(row-extract (dataset ds
) (incr j
))))))
101 (defun print-structure-relational (ds)
102 "example of what we want the methods to look like. Should be sort
103 of like a graph of spreadsheets if the storage is a relational
105 (dolist (k (relations ds
))
106 (print-as-row (var-labels ds
))
108 (dolist (i (case-labels ds
))
109 (princ "%i %v" i
(row-extract (dataset ds
) (incr j
))))))
114 (defgeneric extract
(dataform what into-form
))
116 (defmethod extract ((ds dataset
) what into-form
)
117 (reshape (get ds what
) into-form
))
121 (defclass data-format
())
127 (defun reorder-by-rank (x order
&key
(by-row t
))
130 (defun reorder-by-permutation (x perm
&key
(by-row t
))
134 ;;; Variable-name handling for Tables. Needs error checking.
138 (defun set-varNames (ds vN
)
139 (if (= (length (var-labels ds
))
141 (setf (var-labels ds
) vN
)
142 (error "wrong size.")))
144 (defsetf varNames set-varNames
)
147 (setf (varNames my-ds-2
) (list "a" "b"))
151 ;;; Case-name handling for Tables. Needs error checking.
152 (defun caseNames (ds)
155 (defun set-caseNames (ds vN
)
156 (if (= (length (case-labels ds
))
158 (setf (case-labels ds
) vN
)
159 (error "wrong size.")))
161 (defsetf caseNames set-caseNames
)
164 (setf (caseNames my-ds-2
) (list "a" "b" "c" 4 5))