diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-04-24 10:30:01 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-04-24 10:30:01 +0200 |
commit | 6fbed842525491e280448a00a4b5426e6830ccaa (patch) | |
tree | b78d2712f7ac23845fc29120d3a9fbcd7d189004 /lib/Numeric/LinearAlgebra | |
parent | 7c5adb83c9cb632c39eb2d844a1496e2a7a23e8b (diff) |
cdot and (×)
added cdot
dot renamed to udot
<.> changed to cdot and moved to Numeric.LinearAlgebra.Util
new general contraction operator (×)
Plot functions moved to Numeric.LinearAlgebra.Util
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Util.hs | 24 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Util/Convolution.hs | 2 |
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/Numeric/LinearAlgebra/Util.hs b/lib/Numeric/LinearAlgebra/Util.hs index f7c40d7..f6aa7da 100644 --- a/lib/Numeric/LinearAlgebra/Util.hs +++ b/lib/Numeric/LinearAlgebra/Util.hs | |||
@@ -19,10 +19,11 @@ module Numeric.LinearAlgebra.Util( | |||
19 | diagl, | 19 | diagl, |
20 | row, | 20 | row, |
21 | col, | 21 | col, |
22 | (&),(!), (¦), (#), | 22 | (&), (¦), (#), |
23 | (?),(¿), | 23 | (?), (¿), |
24 | rand, randn, | 24 | rand, randn, |
25 | cross, | 25 | cross, |
26 | (<.>), | ||
26 | norm, | 27 | norm, |
27 | unitary, | 28 | unitary, |
28 | mt, | 29 | mt, |
@@ -45,7 +46,13 @@ module Numeric.LinearAlgebra.Util( | |||
45 | vec, | 46 | vec, |
46 | vech, | 47 | vech, |
47 | dup, | 48 | dup, |
48 | vtrans | 49 | vtrans, |
50 | -- * Plot | ||
51 | mplot, | ||
52 | plot, parametricPlot, | ||
53 | splot, mesh, meshdom, | ||
54 | matrixToPGM, imshow, | ||
55 | gnuplotX, gnuplotpdf, gnuplotWin | ||
49 | ) where | 56 | ) where |
50 | 57 | ||
51 | import Numeric.Container | 58 | import Numeric.Container |
@@ -55,6 +62,7 @@ import Numeric.Vector() | |||
55 | 62 | ||
56 | import System.Random(randomIO) | 63 | import System.Random(randomIO) |
57 | import Numeric.LinearAlgebra.Util.Convolution | 64 | import Numeric.LinearAlgebra.Util.Convolution |
65 | import Graphics.Plot | ||
58 | 66 | ||
59 | 67 | ||
60 | disp :: Int -> Matrix Double -> IO () | 68 | disp :: Int -> Matrix Double -> IO () |
@@ -99,11 +107,6 @@ infixl 3 & | |||
99 | (&) :: Vector Double -> Vector Double -> Vector Double | 107 | (&) :: Vector Double -> Vector Double -> Vector Double |
100 | a & b = vjoin [a,b] | 108 | a & b = vjoin [a,b] |
101 | 109 | ||
102 | -- | horizontal concatenation of real matrices | ||
103 | infixl 3 ! | ||
104 | (!) :: Matrix Double -> Matrix Double -> Matrix Double | ||
105 | a ! b = fromBlocks [[a,b]] | ||
106 | |||
107 | -- | (00A6) horizontal concatenation of real matrices | 110 | -- | (00A6) horizontal concatenation of real matrices |
108 | infixl 3 ¦ | 111 | infixl 3 ¦ |
109 | (¦) :: Matrix Double -> Matrix Double -> Matrix Double | 112 | (¦) :: Matrix Double -> Matrix Double -> Matrix Double |
@@ -161,6 +164,11 @@ size m = (rows m, cols m) | |||
161 | mt :: Matrix Double -> Matrix Double | 164 | mt :: Matrix Double -> Matrix Double |
162 | mt = trans . inv | 165 | mt = trans . inv |
163 | 166 | ||
167 | -- | dot product: @u \<.\> v = 'cdot' u v@ | ||
168 | (<.>) :: (Container Vector t, Product t) => Vector t -> Vector t -> t | ||
169 | infixl 7 <.> | ||
170 | u <.> v = cdot u v | ||
171 | |||
164 | ---------------------------------------------------------------------- | 172 | ---------------------------------------------------------------------- |
165 | 173 | ||
166 | -- | Matrix of pairwise squared distances of row vectors | 174 | -- | Matrix of pairwise squared distances of row vectors |
diff --git a/lib/Numeric/LinearAlgebra/Util/Convolution.hs b/lib/Numeric/LinearAlgebra/Util/Convolution.hs index be9b1eb..1043614 100644 --- a/lib/Numeric/LinearAlgebra/Util/Convolution.hs +++ b/lib/Numeric/LinearAlgebra/Util/Convolution.hs | |||
@@ -75,7 +75,7 @@ matSS dr m = map (reshape c) [ subVector (k*c) n v | k <- [0 .. r - dr] ] | |||
75 | corr2 :: Product a => Matrix a -> Matrix a -> Matrix a | 75 | corr2 :: Product a => Matrix a -> Matrix a -> Matrix a |
76 | -- ^ 2D correlation | 76 | -- ^ 2D correlation |
77 | corr2 ker mat = dims | 77 | corr2 ker mat = dims |
78 | . concatMap (map ((<.> ker') . flatten) . matSS c . trans) | 78 | . concatMap (map (udot ker' . flatten) . matSS c . trans) |
79 | . matSS r $ mat | 79 | . matSS r $ mat |
80 | where | 80 | where |
81 | r = rows ker | 81 | r = rows ker |