diff options
author | Alberto Ruiz <aruiz@um.es> | 2012-03-19 11:59:53 +0100 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2012-03-19 11:59:53 +0100 |
commit | b0424cacf0453d8294fb37ab1325be256fd7be3e (patch) | |
tree | 852f11d979ce39897681361bd184e5415b1c956d /lib/Numeric/LinearAlgebra/Real.hs | |
parent | 1a6d3168d0182b868ac3a87ab69a88f22e03b836 (diff) |
rename module to Util, some changes, add cross product and disp
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Real.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Real.hs | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/lib/Numeric/LinearAlgebra/Real.hs b/lib/Numeric/LinearAlgebra/Real.hs deleted file mode 100644 index 8478ee7..0000000 --- a/lib/Numeric/LinearAlgebra/Real.hs +++ /dev/null | |||
@@ -1,117 +0,0 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | {- | | ||
3 | Module : Numeric.LinearAlgebra.Real | ||
4 | Copyright : (c) Alberto Ruiz 2012 | ||
5 | License : GPL | ||
6 | |||
7 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
8 | Stability : provisional | ||
9 | |||
10 | Additional functions for real arrays. | ||
11 | |||
12 | -} | ||
13 | ----------------------------------------------------------------------------- | ||
14 | |||
15 | module Numeric.LinearAlgebra.Real( | ||
16 | (<>), (<\>), | ||
17 | vector, | ||
18 | linspace, | ||
19 | eye, | ||
20 | zeros, ones, | ||
21 | diagl, | ||
22 | row, | ||
23 | col, | ||
24 | (#),(&), (//), blocks, | ||
25 | rand, randn, | ||
26 | module Numeric.LinearAlgebra | ||
27 | ) where | ||
28 | |||
29 | import Numeric.LinearAlgebra hiding ((<>), (<\>), linspace) | ||
30 | import qualified Numeric.LinearAlgebra as LA | ||
31 | import System.Random(randomIO) | ||
32 | |||
33 | linspace :: Int -> (Double,Double) -> Vector Double | ||
34 | linspace = LA.linspace | ||
35 | |||
36 | |||
37 | infixl 7 <> | ||
38 | -- | Matrix product | ||
39 | (<>) ::Mul a b c => a Double -> b Double -> c Double | ||
40 | (<>) = (LA.<>) | ||
41 | |||
42 | |||
43 | infixl 7 <\> | ||
44 | -- | Least squares solution of a linear system | ||
45 | (<\>) ::LSDiv b c => Matrix Double -> b Double -> c Double | ||
46 | (<\>) = (LA.<\>) | ||
47 | |||
48 | |||
49 | -- | Pseudorandom matrix with uniform elements between 0 and 1. | ||
50 | randm :: RandDist | ||
51 | -> Int -- ^ rows | ||
52 | -> Int -- ^ columns | ||
53 | -> IO (Matrix Double) | ||
54 | randm d r c = do | ||
55 | seed <- randomIO | ||
56 | return (reshape c $ randomVector seed d (r*c)) | ||
57 | |||
58 | -- | Pseudorandom matrix with uniform elements between 0 and 1. | ||
59 | rand :: Int -> Int -> IO (Matrix Double) | ||
60 | rand = randm Uniform | ||
61 | |||
62 | -- | Pseudorandom matrix with normal elements | ||
63 | randn :: Int -> Int -> IO (Matrix Double) | ||
64 | randn = randm Gaussian | ||
65 | |||
66 | -- | Real identity matrix. | ||
67 | eye :: Int -> Matrix Double | ||
68 | eye = ident | ||
69 | |||
70 | -- | Create a real vector from a list. | ||
71 | vector :: [Double] -> Vector Double | ||
72 | vector = fromList | ||
73 | |||
74 | -- | Create a real diagonal matrix from a list. | ||
75 | diagl :: [Double] -> Matrix Double | ||
76 | diagl = diag . vector | ||
77 | |||
78 | -- | Create a matrix or zeros. | ||
79 | zeros :: Int -- ^ rows | ||
80 | -> Int -- ^ columns | ||
81 | -> Matrix Double | ||
82 | zeros r c = konst 0 (r,c) | ||
83 | |||
84 | -- | Create a matrix or ones. | ||
85 | ones :: Int -- ^ rows | ||
86 | -> Int -- ^ columns | ||
87 | -> Matrix Double | ||
88 | ones r c = konst 1 (r,c) | ||
89 | |||
90 | -- | Concatenation of real vectors. | ||
91 | infixl 3 # | ||
92 | (#) :: Vector Double -> Vector Double -> Vector Double | ||
93 | a # b = join [a,b] | ||
94 | |||
95 | -- | Horizontal concatenation of real matrices. | ||
96 | infixl 3 ! | ||
97 | (!) :: Matrix Double -> Matrix Double -> Matrix Double | ||
98 | a ! b = fromBlocks [[a,b]] | ||
99 | |||
100 | -- | Vertical concatenation of real matrices. | ||
101 | (#) :: Matrix Double -> Matrix Double -> Matrix Double | ||
102 | infixl 2 # | ||
103 | a # b = fromBlocks [[a],[b]] | ||
104 | |||
105 | |||
106 | -- | Real block matrix from a rectangular list of lists. | ||
107 | blocks :: [[Matrix Double]] -> Matrix Double | ||
108 | blocks = fromBlocks | ||
109 | |||
110 | -- | A real matrix with a single row, created from a list of elements. | ||
111 | row :: [Double] -> Matrix Double | ||
112 | row = asRow . vector | ||
113 | |||
114 | -- | A real matrix with a single column, created from a list of elements. | ||
115 | col :: [Double] -> Matrix Double | ||
116 | col = asColumn . vector | ||
117 | |||