3 (setf x
'#2a
((1 2)(3 4)(5 6)(7 8)))
4 (setf y
'#2a
((9 10 11) (12 13 14)))
10 (let* ((m (array-dimension x
0))
11 (k (array-dimension x
1))
12 (n (array-dimension y
1))
13 (z (make-array (list m n
) :initial-element
0)))
17 (incf (aref z i j
) (* (aref x i l
) (aref y l j
))))))
21 (let* ((m (array-dimension x
0))
22 (n (array-dimension x
1))
23 (z (make-array m
:initial-element
0)))
26 (incf (aref z i
) (* (aref x i j
) (aref y j
)))))
30 (let* ((m (array-dimension y
0))
31 (n (array-dimension y
1))
32 (z (make-array n
:initial-element
0)))
35 (incf (aref z j
) (* (aref x i
) (aref y i j
)))))
38 (defun ip (x y
&optional
(conj t
))
39 (sum (* x
(if conj
(conjugate y
) y
))))
41 (defun test-report (name val
)
42 ;(format t "~&~a: ~9t~f~%" name val)
47 (test-report "MATMULT"
48 (let ((cx (complex x
(* 2 x
)))
49 (cy (complex y
(* 3 y
)))
50 (cxv (complex xv
(* 4 xv
)))
51 (cyv (complex yv
(* 5 yv
))))
52 (max (abs (- (matmult x y
) (mm x y
)))
53 (abs (- (matmult cx cy
) (mm cx cy
)))
54 (abs (- (matmult x yv
) (mv x yv
)))
55 (abs (- (matmult cx cyv
) (mv cx cyv
)))
56 (abs (- (matmult xv y
) (vm xv y
)))
57 (abs (- (matmult cxv cy
) (vm cxv cy
)))
58 (abs (- (matmult xv yv
) (ip xv yv
)))
59 (abs (- (matmult cxv cyv
) (ip cxv cyv nil
))))))
61 (test-report "CROSS-PRODUCT"
62 (max (abs (- (cross-product x
) (mm (transpose x
) x
)))
63 (let ((cx (complex x
(* 2 x
))))
64 (abs (- (cross-product cx
)
65 (mm (transpose cx
) (conjugate cx
)))))
66 (let ((cx (complex x
(* 2 x
))))
67 (abs (- (cross-product cx nil
)
68 (mm (transpose cx
) cx
))))))
70 (test-report "INNER-PRODUCT"
71 (let ((cxv (complex xv
(* 4 xv
)))
72 (cyv (complex yv
(* 5 yv
))))
73 (max (abs (- (inner-product xv yv
) (ip xv yv
)))
74 (abs (- (inner-product cxv cyv
) (ip cxv cyv
)))
75 (abs (- (inner-product cxv cyv nil
) (ip cxv cyv nil
))))))
77 (let* ((x (list (iseq 1 4) (^
(iseq 1 4) 2)))
80 (m1 (regression-model x y
:print nil
))
81 (mw (regression-model x y
:print nil
:weights w
))
82 (xm (apply #'bind-columns
(repeat 1 4) x
))
85 (b1 (matmult (inverse (matmult xmt xm
)) xmt y
))
86 (bw (matmult (inverse (matmult xmt wm xm
)) xmt wm y
)))
87 (test-report "REGRESS"
88 (max (abs (- (send m1
:coef-estimates
) b1
))
89 (abs (- (send mw
:coef-estimates
) bw
)))))