working but super-primitive dataset type.
[CommonLispStat.git] / data-clos.lisp
blob76116537bcaa0af6b90aaea715cdafe31b6ff6d6
1 ;;; -*- mode: lisp -*-
3 ;;; File: data-clos.lisp
4 ;;; Author: AJ Rossini <blindglobe@gmail.com>
5 ;;; Copyright: (c)2008, AJ Rossini. BSD, LLGPL, or GPLv2, depending
6 ;;; on how it arrives.
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
16 ;;; version.
18 ;;; data-clos.lisp
19 ;;;
20 ;;; redoing regression in a CLOS based framework.
21 ;;; See regression.lsp for basis of work.
23 (in-package :cl-user)
25 (defpackage :lisp-stat-data-clos
26 (:use :common-lisp
27 :clem ;;?? or :matlisp , or :...?
29 (:export dataset extract set))
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).
41 (defclass table ())
43 (defclass relation ())
45 (defclass dataset ()
46 ((store :initform nil
47 :initarg :storage
48 :accessor dataset)
49 (documentation-string :initform nil
50 :initarg :doc
51 :accessor doc-string)
52 (case-labels :initform nil
53 :initarg :case-labels
54 :accessor case-labels)
55 (var-labels :initform nil
56 :initarg :var-labels
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?
64 (defvar my-ds-1 nil
65 "test ds for experiment.")
66 (setf my-ds-1 (make-instance 'dataset))
67 my-ds-1
69 (defvar my-ds-2 nil
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")))
76 my-ds-2
77 (dataset my-ds-2)
78 (doc-string my-ds-2)
79 (case-labels my-ds-2)
80 (var-labels my-ds-2)
82 (defun print-structure-table (ds)
83 "example of what we want the methods to look like. Should be sort
84 of like a spreadsheet if the storage is a table."
85 (print-as-row (var-labels ds))
86 (let ((j -1))
87 (dolist (i (case-labels ds))
88 (princ "%i %v" i (row-extract (dataset ds) (incr j))))))
90 (defun print-structure-relational (ds)
91 "example of what we want the methods to look like. Should be sort
92 of like a graph of spreadsheets if the storage is a relational
93 structure."
94 (dolist (k (relations ds))
95 (print-as-row (var-labels ds))
96 (let ((j -1))
97 (dolist (i (case-labels ds))
98 (princ "%i %v" i (row-extract (dataset ds) (incr j))))))
103 (defgeneric extract (dataform what into-form))
105 (defmethod extract ((ds dataset) what into-form)
106 (reshape (get ds what) into-form))
110 (defclass data-format())
113 (defun transpose (x)
114 "map NxM to MxN.")
116 (defun reorder-by-rank (x order &key (by-row t))
117 " .")
119 (defun reorder-by-permutation (x perm &key (by-row t))
120 " .")
122 ;;; need a setter for case and var names. I think we can do that in
123 ;;; the class definitinon?