Permalink
Browse files

Cosmetic cleanup, following changes in CLNU, removing trailing whites…

…pace.
  • Loading branch information...
1 parent 8302e5c commit b617ae8131d0c5eb25bf63f9ddb76d6c6d71531a @tpapp committed Jan 18, 2012
Showing with 30 additions and 25 deletions.
  1. +2 −2 src/random.lisp
  2. +2 −2 src/statistics.lisp
  3. +2 −1 tests/multivariate.lisp
  4. +5 −5 tests/package.lisp
  5. +2 −2 tests/statistics.lisp
  6. +3 −3 tests/univariate.lisp
  7. +14 −10 tests/utilities.lisp
View
4 src/random.lisp
@@ -56,7 +56,7 @@ Also, within BODY, slots are accessible by their names."
(with-unique-names (a b tolerance)
`((defmethod == ((,a ,name) (,b ,name)
&optional (,tolerance *==-tolerance*))
- (and ,@(mapcar
+ (and ,@(mapcar
(lambda (slot)
(let ((accessor (symbolicate name #\- slot)))
`(== (,accessor ,a) (,accessor ,b)
@@ -84,7 +84,7 @@ Also, within BODY, slots are accessible by their names."
(defmethod sweep (accumulator (replicating replicating) &key (key #'identity))
(let+ (((&structure-r/o replicating- random-variable n) replicating))
- (with-accumulator (accumulator add)
+ (with-conforming-accumulator (accumulator add)
(loop repeat n :do (add (funcall key (draw random-variable)))))))
(defgeneric cdf (random-variable x)
View
4 src/statistics.lisp
@@ -16,7 +16,7 @@
t)))))
(defun demean-matrix (matrix &optional (mean (matrix-mean matrix)))
- (e- matrix (recycle mean :horizontal)))
+ (e- matrix (recycle-row mean (nrow matrix))))
;; (defun matrix-sse (matrix)
;; "Return sum of squared errors from the matrix row mean (as a Hermitian
@@ -79,7 +79,7 @@ a second value."
;; (as-matrix matrix)))
;; ((:lla-vector sum) (make-similar-vector elements ncol)))
;; (dotimes (col ncol)
-;; (setf (sum col)
+;; (setf (sum col)
;; (lla::sum-elements% elements (cm-index2 nrow 0 col)
;; (cm-index2 nrow nrow col))))
;; sum))
View
3 tests/multivariate.lisp
@@ -99,7 +99,8 @@
t)))
(sample (generate-array 50000 (compose #'as-array (generator rv))))
(sample-mean (mean sample)))
- (ensure (< (relative-difference sample-mean (mean rv)) 0.01))))
+ (ensure (< (relative-difference sample-mean (mean rv))
+ 0.01))))
(addtest (multivariate-tests)
inverse-wishart-draws
View
10 tests/package.lisp
@@ -1,6 +1,6 @@
(defpackage cl-random-tests
- (:use cl alexandria iterate let-plus anaphora lift cl-random
- cl-num-utils lla)
- (:shadowing-import-from cl-random mean variance median)
- (:export random-y-x run)
- (:import-from cl-num-utils-tests vector* array*))
+ (:use #:cl #:alexandria #:iterate #:let-plus #:anaphora #:lift #:cl-random
+ #:cl-num-utils #:lla #:transit)
+ (:shadowing-import-from #:cl-random #:mean #:variance #:median)
+ (:export #:random-y-x #:run)
+ (:import-from #:cl-num-utils-tests #:vector* #:array*))
View
4 tests/statistics.lisp
@@ -28,7 +28,7 @@
(26 5)))
;; calculating another way
(mean (matrix-mean m2))
- (demeaned (e- m2 (recycle mean :h)))
+ (demeaned (e- m2 (recycle-row mean (nrow m2))))
(sse (mm t demeaned)))
(ensure-same (as-matrix (matrix-sse m))
(hermitian 'lla-double
@@ -57,6 +57,6 @@
;; ((:values rescaled sd) (rescale-by-sd m)))
;; (ensure-same rescaled (clo :double
;; -1 -1 :/
-;; 0 0
+;; 0 0
;; 1 1))
;; (ensure-same sd (clo :double 1 2))))
View
6 tests/univariate.lisp
@@ -24,7 +24,7 @@
(addtest (cl-random-tests)
exponential-draws
(ensure (same-sample-mean-variance (r-exponential 1)))
- (ensure (same-sample-mean-variance (r-exponential 19)
+ (ensure (same-sample-mean-variance (r-exponential 19)
:var-band 0.3d0)))
;; normal distribution
@@ -130,7 +130,7 @@
(addtest (cl-random-tests)
gamma-draws
- (ensure-error (r-gamma 9 0))
+ (ensure-error (r-gamma 9 0))
(ensure-error (r-gamma -7 1))
(ensure (same-sample-mean-variance (r-gamma 1 1)))
(ensure (same-sample-mean-variance (r-gamma 12 1)))
@@ -197,7 +197,7 @@
(n (reduce #'+ frequencies)))
"Sum of the absolute values of relative deviations from expected probabilities."
(assert (= (length frequencies) (length probabilities)))
- (mean (map 'vector
+ (mean (map 'vector
(lambda (f p)
(let ((e (* n p)))
(/ (abs (- f e)) e)))
View
24 tests/utilities.lisp
@@ -14,7 +14,7 @@ COMPARE-SAMPLE-MEAN-VARIANCE. For univariate and multivariate distributions."
(let+ (((&accessors-r/o mean variance) rv)
(multivariate? (vectorp mean))
(sample (sweep (if multivariate?
- 'mean
+ (conforming-accumulator 'mean )
'variance)
(replicating rv n))))
(if multivariate?
@@ -24,19 +24,23 @@ COMPARE-SAMPLE-MEAN-VARIANCE. For univariate and multivariate distributions."
(and (< (z-score n mean variance (mean sample)) z-band)
(== variance (variance sample) var-band)))))
-(defun number-relative-difference (a b)
- "Relative difference of A and B."
- (/ (abs (- a b))
- (max 1 (abs a) (abs b))))
-
(defgeneric relative-difference (a b)
+ (:documentation "Relative difference of A and B.")
(:method ((a number) (b number))
- (number-relative-difference a b))
- (:method (a b)
- (emax (emap t #'number-relative-difference (as-array a) (as-array b)))))
+ (/ (abs (- a b))
+ (max 1 (abs a) (abs b))))
+ (:method ((a array) (b array))
+ "Relative difference of A and B."
+ (assert (equalp (array-dimensions a) (array-dimensions b)))
+ (with-accumulator (r &maximize)
+ (map nil (lambda (a b)
+ (r (relative-difference a b)))
+ (flatten-array a) (flatten-array b))))
+ (:method ((a array) b)
+ (relative-difference a (as-array b))))
(defun random-y-x (n k
- &optional
+ &optional
(x-rv (r-normal 0 9))
(e-rv (r-normal 0 2))
(beta (generate-array k (generator (r-normal 0 1))

0 comments on commit b617ae8

Please sign in to comment.