diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Util.hs | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/lib/Numeric/LinearAlgebra/Util.hs b/lib/Numeric/LinearAlgebra/Util.hs deleted file mode 100644 index 24317e3..0000000 --- a/lib/Numeric/LinearAlgebra/Util.hs +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | {- | | ||
3 | Module : Numeric.LinearAlgebra.Util | ||
4 | Copyright : (c) Alberto Ruiz 2010 | ||
5 | License : GPL | ||
6 | |||
7 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
8 | Stability : provisional | ||
9 | Portability : portable | ||
10 | |||
11 | Alternative interface and utilities for creation of real arrays, useful to work in interactive mode. | ||
12 | |||
13 | -} | ||
14 | ----------------------------------------------------------------------------- | ||
15 | |||
16 | module Numeric.LinearAlgebra.Util( | ||
17 | module Numeric.LinearAlgebra, | ||
18 | (<>), (*>), (<*), (<\>), (\>), | ||
19 | vector, | ||
20 | eye, | ||
21 | zeros, ones, | ||
22 | diagl, | ||
23 | row, | ||
24 | col, | ||
25 | (#),(&), (//), blocks, | ||
26 | rand, | ||
27 | splitEvery, | ||
28 | table | ||
29 | ) where | ||
30 | |||
31 | import Numeric.LinearAlgebra hiding ((<>), (<|>), (<->), (<\>), (.*), (*/)) | ||
32 | import Data.Packed.Internal.Common(table,splitEvery) | ||
33 | import System.Random(randomIO) | ||
34 | |||
35 | infixl 7 <> | ||
36 | -- | Matrix product ('multiply') | ||
37 | (<>) :: Field t => Matrix t -> Matrix t -> Matrix t | ||
38 | (<>) = multiply | ||
39 | |||
40 | infixl 7 *> | ||
41 | -- | matrix x vector | ||
42 | (*>) :: Field t => Matrix t -> Vector t -> Vector t | ||
43 | m *> v = flatten $ m <> (asColumn v) | ||
44 | |||
45 | infixl 7 <* | ||
46 | -- | vector x matrix | ||
47 | (<*) :: Field t => Vector t -> Matrix t -> Vector t | ||
48 | v <* m = flatten $ (asRow v) <> m | ||
49 | |||
50 | |||
51 | -- | Least squares solution of a linear system for several right-hand sides, similar to the \\ operator of Matlab\/Octave. (\<\\\>) = 'linearSolveSVD'. | ||
52 | (<\>) :: (Field a) => Matrix a -> Matrix a -> Matrix a | ||
53 | infixl 7 <\> | ||
54 | (<\>) = linearSolveSVD | ||
55 | |||
56 | -- | Least squares solution of a linear system for a single right-hand side. See '(\<\\\>)'. | ||
57 | (\>) :: (Field a) => Matrix a -> Vector a -> Vector a | ||
58 | infixl 7 \> | ||
59 | m \> v = flatten (m <\> reshape 1 v) | ||
60 | |||
61 | -- | Pseudorandom matrix with uniform elements between 0 and 1. | ||
62 | rand :: Int -- ^ rows | ||
63 | -> Int -- ^ columns | ||
64 | -> IO (Matrix Double) | ||
65 | rand r c = do | ||
66 | seed <- randomIO | ||
67 | return (reshape c $ randomVector seed Uniform (r*c)) | ||
68 | |||
69 | -- | Real identity matrix. | ||
70 | eye :: Int -> Matrix Double | ||
71 | eye = ident | ||
72 | |||
73 | -- | Create a real vector from a list. | ||
74 | vector :: [Double] -> Vector Double | ||
75 | vector = fromList | ||
76 | |||
77 | -- | Create a real diagonal matrix from a list. | ||
78 | diagl :: [Double] -> Matrix Double | ||
79 | diagl = diag . vector | ||
80 | |||
81 | -- | Create a matrix or zeros. | ||
82 | zeros :: Int -- ^ rows | ||
83 | -> Int -- ^ columns | ||
84 | -> Matrix Double | ||
85 | zeros r c = reshape c (constant 0 (r*c)) | ||
86 | |||
87 | -- | Create a matrix or ones. | ||
88 | ones :: Int -- ^ rows | ||
89 | -> Int -- ^ columns | ||
90 | -> Matrix Double | ||
91 | ones r c = reshape c (constant 1 (r*c)) | ||
92 | |||
93 | |||
94 | -- | Concatenation of real vectors. | ||
95 | infixl 9 # | ||
96 | (#) :: Vector Double -> Vector Double -> Vector Double | ||
97 | a # b = join [a,b] | ||
98 | |||
99 | |||
100 | -- | Horizontal concatenation of real matrices. | ||
101 | infixl 8 & | ||
102 | (&) :: Matrix Double -> Matrix Double -> Matrix Double | ||
103 | a & b = fromBlocks [[a,b]] | ||
104 | |||
105 | -- | Vertical concatenation of real matrices. | ||
106 | infixl 7 // | ||
107 | (//) :: Matrix Double -> Matrix Double -> Matrix Double | ||
108 | a // b = fromBlocks [[a],[b]] | ||
109 | |||
110 | -- | Real block matrix from a rectangular list of lists. | ||
111 | blocks :: [[Matrix Double]] -> Matrix Double | ||
112 | blocks = fromBlocks | ||
113 | |||
114 | -- | A real matrix with a single row, create from a list of elements. | ||
115 | row :: [Double] -> Matrix Double | ||
116 | row = asRow . vector | ||
117 | |||
118 | -- | A real matrix with a single column, created from a list of elements. | ||
119 | col :: [Double] -> Matrix Double | ||
120 | col = asColumn . vector | ||
121 | |||
122 | |||