diff options
author | Alberto Ruiz <aruiz@um.es> | 2013-05-21 17:13:08 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2013-05-21 17:13:08 +0200 |
commit | 66fea11dddad6f58e4fb1297b17b0b5ce1d6e8db (patch) | |
tree | b13bfaf139b6d1d09c6429e395408003d5f4ce5a | |
parent | 8c890d59088015865a4e8c6b0ebec13e58d8b295 (diff) |
Util: pairwise2D, rowOuters, null1, null1sym
-rw-r--r-- | CHANGES.md | 12 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Util.hs | 39 |
2 files changed, 50 insertions, 1 deletions
@@ -1,3 +1,15 @@ | |||
1 | 0.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 | |||
1 | 0.14.1.0 | 13 | 0.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 | {- | |
4 | Module : Numeric.LinearAlgebra.Util | 4 | Module : Numeric.LinearAlgebra.Util |
5 | Copyright : (c) Alberto Ruiz 2012 | 5 | Copyright : (c) Alberto Ruiz 2013 |
6 | License : GPL | 6 | License : GPL |
7 | 7 | ||
8 | Maintainer : Alberto Ruiz (aruiz at um dot es) | 8 | Maintainer : 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) | ||
147 | pairwiseD2 :: Matrix Double -> Matrix Double -> Matrix Double | ||
148 | pairwiseD2 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 | ||
163 | rowOuters :: Matrix Double -> Matrix Double -> Matrix Double | ||
164 | rowOuters 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 | ||
172 | null1 :: Matrix Double -> Vector Double | ||
173 | null1 = last . toColumns . snd . rightSV | ||
174 | |||
175 | -- | solution of overconstrained homogeneous symmetric linear system | ||
176 | null1sym :: Matrix Double -> Vector Double | ||
177 | null1sym = last . toColumns . snd . eigSH' | ||
141 | 178 | ||
142 | -------------------------------------------------------------------------------- | 179 | -------------------------------------------------------------------------------- |
143 | 180 | ||