summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2013-05-21 17:13:08 +0200
committerAlberto Ruiz <aruiz@um.es>2013-05-21 17:13:08 +0200
commit66fea11dddad6f58e4fb1297b17b0b5ce1d6e8db (patch)
treeb13bfaf139b6d1d09c6429e395408003d5f4ce5a
parent8c890d59088015865a4e8c6b0ebec13e58d8b295 (diff)
Util: pairwise2D, rowOuters, null1, null1sym
-rw-r--r--CHANGES.md12
-rw-r--r--lib/Numeric/LinearAlgebra/Util.hs39
2 files changed, 50 insertions, 1 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 3b19ec9..18eab3b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,15 @@
10.15.0.0
2--------
3
4- diagBlock
5
6- NFData instance of Matrix
7
8- Unidimensional root finding
9
10- In Numeric.LinearAlgebra.Util:
11 pairwise2D, rowOuters, null1, null1sym, size, unitary, mt
12
10.14.1.0 130.14.1.0
2-------- 14--------
3 15
diff --git a/lib/Numeric/LinearAlgebra/Util.hs b/lib/Numeric/LinearAlgebra/Util.hs
index d92ed76..3e4f6a9 100644
--- a/lib/Numeric/LinearAlgebra/Util.hs
+++ b/lib/Numeric/LinearAlgebra/Util.hs
@@ -2,7 +2,7 @@
2----------------------------------------------------------------------------- 2-----------------------------------------------------------------------------
3{- | 3{- |
4Module : Numeric.LinearAlgebra.Util 4Module : Numeric.LinearAlgebra.Util
5Copyright : (c) Alberto Ruiz 2012 5Copyright : (c) Alberto Ruiz 2013
6License : GPL 6License : GPL
7 7
8Maintainer : Alberto Ruiz (aruiz at um dot es) 8Maintainer : Alberto Ruiz (aruiz at um dot es)
@@ -25,6 +25,10 @@ module Numeric.LinearAlgebra.Util(
25 norm, 25 norm,
26 unitary, 26 unitary,
27 mt, 27 mt,
28 pairwiseD2,
29 rowOuters,
30 null1,
31 null1sym,
28 -- * Convolution 32 -- * Convolution
29 -- ** 1D 33 -- ** 1D
30 corr, conv, corrMin, 34 corr, conv, corrMin,
@@ -138,6 +142,39 @@ mt = trans . inv
138 142
139---------------------------------------------------------------------- 143----------------------------------------------------------------------
140 144
145-- | Matrix of pairwise squared distances of row vectors
146-- (using the matrix product trick in blog.smola.org)
147pairwiseD2 :: Matrix Double -> Matrix Double -> Matrix Double
148pairwiseD2 x y | ok = x2 `outer` oy + ox `outer` y2 - 2* x <> trans y
149 | otherwise = error $ "pairwiseD2 with different number of columns: "
150 ++ show (size x) ++ ", " ++ show (size y)
151 where
152 ox = one (rows x)
153 oy = one (rows y)
154 oc = one (cols x)
155 one k = constant 1 k
156 x2 = x * x <> oc
157 y2 = y * y <> oc
158 ok = cols x == cols y
159
160--------------------------------------------------------------------------------
161
162-- | outer products of rows
163rowOuters :: Matrix Double -> Matrix Double -> Matrix Double
164rowOuters a b = a' * b'
165 where
166 a' = kronecker a (ones 1 (cols b))
167 b' = kronecker (ones 1 (cols a)) b
168
169--------------------------------------------------------------------------------
170
171-- | solution of overconstrained homogeneous linear system
172null1 :: Matrix Double -> Vector Double
173null1 = last . toColumns . snd . rightSV
174
175-- | solution of overconstrained homogeneous symmetric linear system
176null1sym :: Matrix Double -> Vector Double
177null1sym = last . toColumns . snd . eigSH'
141 178
142-------------------------------------------------------------------------------- 179--------------------------------------------------------------------------------
143 180