From 93f3939941c0fcd44141e5d3633af06c5091d14b Mon Sep 17 00:00:00 2001 From: AJ Rossini Date: Mon, 27 Aug 2007 23:11:36 +0200 Subject: [PATCH] thinking data frames -- categorical data will be the trick --- init.lisp | 2 ++ matrices.lsp | 7 ++++-- src/data/categorical-types.lisp | 29 +++++++++++++++++++++++ src/data/datatable.lisp | 33 ++++++++++++++++++++++++++ matrices.lsp => src/data/matrix.lisp | 45 ++++++++++++++++++++++++++---------- 5 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 src/data/categorical-types.lisp create mode 100644 src/data/datatable.lisp copy matrices.lsp => src/data/matrix.lisp (92%) diff --git a/init.lisp b/init.lisp index d2ce96c..d69fca7 100644 --- a/init.lisp +++ b/init.lisp @@ -50,6 +50,8 @@ ;;(asdf:oos 'asdf:load-op :lisp-unit) (asdf:oos 'asdf:load-op :clem) + #+nil(asdf:oos 'asdf:load-op :clem-test) + #+nil(asdf:oos 'asdf:load-op :clem-benchmark) ;; Constraint System ;;(asdf:oos 'asdf:load-op :cells) diff --git a/matrices.lsp b/matrices.lsp index 305a201..8c32aab 100644 --- a/matrices.lsp +++ b/matrices.lsp @@ -10,12 +10,15 @@ ;;;; Copyright (c) 1991, by Luke Tierney. Permission is granted for ;;;; unrestricted use. + +;;; Need to extend to use CLEM + + + ;;;; ;;;; Package Setup ;;;; -;;(in-package :lisp-stat-basics) - (defpackage :lisp-stat-matrix (:use :common-lisp :lisp-stat-compound-data diff --git a/src/data/categorical-types.lisp b/src/data/categorical-types.lisp new file mode 100644 index 0000000..27365e4 --- /dev/null +++ b/src/data/categorical-types.lisp @@ -0,0 +1,29 @@ +;;; -*- mode: lisp -*- +;;; +;;; Copyright (c) 2007, by A.J. Rossini +;;; See COPYRIGHT file for any additional restrictions (BSD license). + +;;;; categorical types -- statistical typing of data. + +;;; What is this talk of 'release'? Klingons do not make software +;;; 'releases'. Our software 'escapes', leaving a bloody trail of +;;; designers and quality assurance people in its wake. + + +;;;; +;;;; Package Setup +;;;; + +(defpackage :lisp-stat-data-categorical + (:use :common-lisp) + (:export derived-statistical-type ; construct particular type + nominal-type ordinal-type ; types + levels ; metadata + categorical->integer ; conversion + conformant-p ; type checking + )) + +(in-package :lisp-stat-data-frame) + +;;; Typing for categorical data. + diff --git a/src/data/datatable.lisp b/src/data/datatable.lisp new file mode 100644 index 0000000..231eec8 --- /dev/null +++ b/src/data/datatable.lisp @@ -0,0 +1,33 @@ +;;; -*- mode: lisp -*- +;;; +;;; Copyright (c) 2007, by A.J. Rossini +;;; See COPYRIGHT file for any additional restrictions (BSD license). + +;;;; datatable -- i.e. data.frame for CL. Extends CLEM + +;;; What is this talk of 'release'? Klingons do not make software +;;; 'releases'. Our software 'escapes', leaving a bloody trail of +;;; designers and quality assurance people in its wake. + + +;;;; +;;;; Package Setup +;;;; + +(defpackage :lisp-stat-data-frame + (:use :common-lisp + :clem) + (:export data-frame-p rows cols + row-list column-list + transpose + bind-columns bind-rows + array-data-vector vector-to-array)) + +(in-package :lisp-stat-data-frame) + + +;;; The goal with this data structure is to be able to extract CLEM +;;; types for statistical computations from a more general data type. +;;; The primary difference is that we need a means for ensuring column +;;; "sameness" and this is absolutely critical. + diff --git a/matrices.lsp b/src/data/matrix.lisp similarity index 92% copy from matrices.lsp copy to src/data/matrix.lisp index 305a201..74c16de 100644 --- a/matrices.lsp +++ b/src/data/matrix.lisp @@ -1,25 +1,22 @@ ;;; -*- mode: lisp -*- ;;; -;;; Copyright (c) 2005--2007, by A.J. Rossini +;;; Copyright (c) 2007, by A.J. Rossini ;;; See COPYRIGHT file for any additional restrictions (BSD license). -;;; Since 1991, ANSI was finally finished. Modified to match ANSI -;;; Common Lisp. -;;;; matrices -- Basic matrix operations -;;;; -;;;; Copyright (c) 1991, by Luke Tierney. Permission is granted for -;;;; unrestricted use. +;;;; matrices for statistics. Extends CLEM + +;;; What is this talk of 'release'? Klingons do not make software +;;; 'releases'. Our software 'escapes', leaving a bloody trail of +;;; designers and quality assurance people in its wake. + ;;;; ;;;; Package Setup ;;;; -;;(in-package :lisp-stat-basics) - (defpackage :lisp-stat-matrix (:use :common-lisp - :lisp-stat-compound-data - :lisp-stat-sequence) + :clem) (:export matrixp num-rows num-cols matmult identity-matrix diagonal row-list column-list inner-product outer-product cross-product transpose bind-columns bind-rows @@ -27,7 +24,30 @@ (in-package :lisp-stat-matrix) -(deftype matrix () 'array) ;; temp fix +;; Using CLEM: + +CL-USER> (defparameter tr1 (make-instance 'number-matrix)) +TR1 +CL-USER> tr1 +# +CL-USER> (defparameter tr2 (make-instance 'number-matrix :rows 4 :cols 3)) +TR2 +CL-USER> tr2 +# +CL-USER> (transpose tr2) + + + + + +tr2 + +(defparameter tr3 (make-instance 'clem::base-vector :length 4)) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; @@ -45,6 +65,7 @@ Displaces array A to a vector" (defun vector-to-array (v dims) "Args: (v dims) Displaces vector V to array with dimensions DIMS" +;;; Yes, but using row or column first approach? (make-array dims :displaced-to v :element-type (array-element-type v))) -- 2.11.4.GIT