From d53ca42bf1326443396a7502b77457c262861bf4 Mon Sep 17 00:00:00 2001 From: AJ Rossini Date: Sat, 21 Mar 2009 09:37:12 +0100 Subject: [PATCH] update and inclusion of listoflist transform code. Signed-off-by: AJ Rossini --- lispstat.asd | 5 ++-- src/data/listoflist.lisp | 72 ++++++++++++++++++++++-------------------------- src/packages.lisp | 29 +++++++++++++++++-- 3 files changed, 62 insertions(+), 44 deletions(-) diff --git a/lispstat.asd b/lispstat.asd index bfc5a2b..26d4108 100644 --- a/lispstat.asd +++ b/lispstat.asd @@ -1,5 +1,5 @@ ;; -*- mode: lisp -*- -;;; Time-stamp: <2009-03-18 12:11:44 tony> +;;; Time-stamp: <2009-03-21 09:27:37 tony> ;;; Created: <2005-05-30 17:09:47 blindglobe> ;;; File: lispstat.asd ;;; Author: AJ Rossini @@ -191,7 +191,8 @@ "numerics-internal") :components ((:file "data-clos") - (:file "data"))) + (:file "data") + (:file "listoflist"))) (:module "lispstat-basics" diff --git a/src/data/listoflist.lisp b/src/data/listoflist.lisp index eba5fdd..df65c00 100644 --- a/src/data/listoflist.lisp +++ b/src/data/listoflist.lisp @@ -1,6 +1,6 @@ ;;; -*- mode: lisp -*- -;;; Time-stamp: <2009-03-11 16:04:26 tony> +;;; Time-stamp: <2009-03-21 09:30:48 tony> ;;; Creation: <2008-09-08 08:06:30 tony> ;;; File: listoflist.lisp ;;; Author: AJ Rossini @@ -14,7 +14,7 @@ ;; Where should this go? -(in-package :cls-data) +(in-package :cls-data-listoflist) ;; Glib commentary: @@ -30,25 +30,27 @@ ;; the top-level list with a property to check orientation ;; (row-major/column-major), but this hasn't been done yet. +;; This file contains code for going between listoflists, +;; arrays/vectors, and matrix-like/vector-like data structures. #| ;; Test cases: -(and T T nil T) -(and T T T) -(defparameter *x1* (list 1 2 3)) -(defparameter *x2* (list 1 2 3)) -(defparameter *x3* (list 1 2 3 4)) -(defparameter *x4* (list 1 2 3)) -(reduce #'(lambda (x y) + (and T T nil T) + (and T T T) + (defparameter *x1* (list 1 2 3)) + (defparameter *x2* (list 1 2 3)) + (defparameter *x3* (list 1 2 3 4)) + (defparameter *x4* (list 1 2 3)) + (reduce #'(lambda (x y) (if (= x y) y -1)) (mapcar #'length (list *x1* *x2* *x3*))) -(reduce #'(lambda (x y) + (reduce #'(lambda (x y) (if (= x y) y -1)) (list 2 3 2)) -(lists-of-same-size *x1* *x2* *x4*) ; => T -(lists-of-same-size *x1* *x3* *x4*) ; => F -(lists-of-same-size *x1* *x2* *x3*) ; => F -(lists-of-same-size *x3* *x1* *x3*) ; => F + (lists-of-same-size *x1* *x2* *x4*) ; => T + (lists-of-same-size *x1* *x3* *x4*) ; => F + (lists-of-same-size *x1* *x2* *x3*) ; => F + (lists-of-same-size *x3* *x1* *x3*) ; => F |# @@ -62,9 +64,9 @@ justify further processing and initial conditions." ;; the following will be handy to help out folks adjust. It should ;; provide a means to write code faster and better. -(defmacro make-data-set-from-lists (datasetname - &optional (force-overwrite nil) - &rest lists-of-data-lists) +(defmacro make-dataframe-from-listoflist (datasetname + &optional (force-overwrite nil) + &rest lists-of-data-lists) "Create a cases-by-variables data frame consisting of numeric data, from a ROW-MAJOR list-of-lists representation. A COLUMN-MAJOR representation should be handled using the transpose-listoflists @@ -90,31 +92,32 @@ function." (princ this-data) |# -(defun transpose-listoflists (listoflists) +(defun transpose-listoflist (listoflist) "This function does the moral-equivalent of a matrix transpose on a list-of-lists data structure" - (apply #'mapcar #'list listoflists)) + (apply #'mapcar #'list listoflist)) ;; (defparameter LOL-2by3 (list (list 1 2) (list 3 4) (list 5 6))) ;; (defparameter LOL-3by2 (list (list 1 3 5) (list 2 4 6))) ;; (transpose-listoflists (transpose-listoflists LOL-2by3)) ;; (transpose-listoflists (transpose-listoflists LOL-3by2)) -(defun equal-listoflists (x y) +(defun equal-listoflist (x y) "FIXME: This function, when written, should walk through 2 listoflists and return T/nil based on equality." - (and - ;; top-level length same - (= (list-length x) - (list-length y)) - ;; FIXME: within-level lengths same - () - ;; FIXME: flattened values same, walking through - (loop over x and verify same tree as y))) + (and (= (list-length x) ;; top-level length same + (list-length y)) + ;; FIXME: within-level lengths same + ;; FIXME: flattened values same, walking through + ;; (loop over x and verify same tree as y) + )) -(defun make-datatable-from-listoflists (lol) ; &key (type 'row-major) - "From a listoflists structure, make a datatable. +(defun make-array-from-listoflist (lol) ; &key (type 'row-major) + "From a listoflists structure, make an array. + +FIXME: need to verify that the listoflists is a valid structure (same +size rows, typing if required, etc. (defparameter *mdfl-test* @@ -149,12 +152,3 @@ return T/nil based on equality." (array-dimensions *mdfl-test-dt*) |# - -(defun ensure-consistent-datatable-type (dt lot) - "given a datatable and a listoftypes, ensure that the datatble - variables are consistent." - (destructuring-bind (n p) - (array-dimensions dt) - (dotimes (i n) - (dotimes (j p) - (check-type (aref dt i j) (elt lot j)))))) \ No newline at end of file diff --git a/src/packages.lisp b/src/packages.lisp index 1feb8e6..fa63c96 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -1,6 +1,6 @@ ;;; -*- mode: lisp -*- -;;; Time-stamp: <2009-03-18 12:12:51 tony> +;;; Time-stamp: <2009-03-21 09:28:46 tony> ;;; Creation: <2008-03-11 19:18:34 user> ;;; File: packages.lisp ;;; Author: AJ Rossini @@ -108,6 +108,8 @@ ;;; NEW CLOS STRUCTURE + + (defpackage :lisp-stat-data-clos (:use :common-lisp :lisp-matrix) @@ -116,8 +118,26 @@ ;; could be value, otherwise might be reference. dataframe-like dataframe-array + + ;; accessors + dataset + nrows ncols + list-of-columns ;; list-of-variables + list-of-rows ;; list-of-observations + + ;; ??? get-variable-matrix get-variable-vector - data-pointer)) + data-pointer + )) + +(defpackage :cls-data-listoflist + (:use :common-lisp + :lisp-stat-data-clos) ; for dataframe + (:export lists-of-same-size + equal-listoflist + transpose-listoflist + make-dataframe-from-listoflist + make-array-from-listoflist)) #| (defpackage :lisp-stat-regression-linear-clos @@ -440,7 +460,10 @@ dataframe-like dataframe-array - + ;; listoflist + lists-of-same-size equal-listoflist + transpose-listoflist + make-dataframe-from-listoflist make-array-from-listoflist ;; statistics.lsp (descriptions, should probably be moved ;; later...? -- 2.11.4.GIT