diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-04-30 16:10:20 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-04-30 16:10:20 +0200 |
commit | cf1379fed234cf99b2ccce6d9311bfc5c58ef4a3 (patch) | |
tree | 2532837500eb98af048404e33018fa88d8a7f535 /lib/Numeric/LinearAlgebra/Util.hs | |
parent | b8b7b47450a1007d4d8c77bb7d04e2744c3bfcd4 (diff) |
improved documentation
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Util.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Util.hs | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/lib/Numeric/LinearAlgebra/Util.hs b/lib/Numeric/LinearAlgebra/Util.hs index be01bc1..21b6188 100644 --- a/lib/Numeric/LinearAlgebra/Util.hs +++ b/lib/Numeric/LinearAlgebra/Util.hs | |||
@@ -13,7 +13,7 @@ Stability : provisional | |||
13 | {-# OPTIONS_HADDOCK hide #-} | 13 | {-# OPTIONS_HADDOCK hide #-} |
14 | 14 | ||
15 | module Numeric.LinearAlgebra.Util( | 15 | module Numeric.LinearAlgebra.Util( |
16 | 16 | ||
17 | -- * Convenience functions | 17 | -- * Convenience functions |
18 | size, disp, | 18 | size, disp, |
19 | zeros, ones, | 19 | zeros, ones, |
@@ -65,8 +65,16 @@ import Numeric.LinearAlgebra.Util.Convolution | |||
65 | import Graphics.Plot | 65 | import Graphics.Plot |
66 | 66 | ||
67 | 67 | ||
68 | {- | print a real matrix with given number of digits after the decimal point | ||
69 | |||
70 | >>> disp 5 $ ident 2 / 3 | ||
71 | 2x2 | ||
72 | 0.33333 0.00000 | ||
73 | 0.00000 0.33333 | ||
74 | |||
75 | -} | ||
68 | disp :: Int -> Matrix Double -> IO () | 76 | disp :: Int -> Matrix Double -> IO () |
69 | -- ^ show a matrix with given number of digits after the decimal point | 77 | |
70 | disp n = putStrLn . dispf n | 78 | disp n = putStrLn . dispf n |
71 | 79 | ||
72 | -- | pseudorandom matrix with uniform elements between 0 and 1 | 80 | -- | pseudorandom matrix with uniform elements between 0 and 1 |
@@ -82,7 +90,16 @@ randm d r c = do | |||
82 | rand :: Int -> Int -> IO (Matrix Double) | 90 | rand :: Int -> Int -> IO (Matrix Double) |
83 | rand = randm Uniform | 91 | rand = randm Uniform |
84 | 92 | ||
85 | -- | pseudorandom matrix with normal elements | 93 | {- | pseudorandom matrix with normal elements |
94 | |||
95 | >>> x <- randn 3 5 | ||
96 | >>> disp 3 x | ||
97 | 3x5 | ||
98 | 0.386 -1.141 0.491 -0.510 1.512 | ||
99 | 0.069 -0.919 1.022 -0.181 0.745 | ||
100 | 0.313 -0.670 -0.097 -1.575 -0.583 | ||
101 | |||
102 | -} | ||
86 | randn :: Int -> Int -> IO (Matrix Double) | 103 | randn :: Int -> Int -> IO (Matrix Double) |
87 | randn = randm Gaussian | 104 | randn = randm Gaussian |
88 | 105 | ||
@@ -115,9 +132,17 @@ infixl 3 & | |||
115 | (&) :: Vector Double -> Vector Double -> Vector Double | 132 | (&) :: Vector Double -> Vector Double -> Vector Double |
116 | a & b = vjoin [a,b] | 133 | a & b = vjoin [a,b] |
117 | 134 | ||
118 | -- | horizontal concatenation of real matrices | 135 | {- | horizontal concatenation of real matrices |
119 | -- | 136 | |
120 | -- (0x00a6 broken bar) | 137 | (0x00a6 broken bar) |
138 | |||
139 | >>> ident 3 ¦ konst 7 (3,4) | ||
140 | (3><7) | ||
141 | [ 1.0, 0.0, 0.0, 7.0, 7.0, 7.0, 7.0 | ||
142 | , 0.0, 1.0, 0.0, 7.0, 7.0, 7.0, 7.0 | ||
143 | , 0.0, 0.0, 1.0, 7.0, 7.0, 7.0, 7.0 ] | ||
144 | |||
145 | -} | ||
121 | infixl 3 ¦ | 146 | infixl 3 ¦ |
122 | (¦) :: Matrix Double -> Matrix Double -> Matrix Double | 147 | (¦) :: Matrix Double -> Matrix Double -> Matrix Double |
123 | a ¦ b = fromBlocks [[a,b]] | 148 | a ¦ b = fromBlocks [[a,b]] |
@@ -141,7 +166,15 @@ row = asRow . fromList | |||
141 | col :: [Double] -> Matrix Double | 166 | col :: [Double] -> Matrix Double |
142 | col = asColumn . fromList | 167 | col = asColumn . fromList |
143 | 168 | ||
144 | -- | extract selected rows | 169 | {- | extract selected rows |
170 | |||
171 | >>> (20><4) [1..] ? [2,1,1] | ||
172 | (3><4) | ||
173 | [ 9.0, 10.0, 11.0, 12.0 | ||
174 | , 5.0, 6.0, 7.0, 8.0 | ||
175 | , 5.0, 6.0, 7.0, 8.0 ] | ||
176 | |||
177 | -} | ||
145 | infixl 9 ? | 178 | infixl 9 ? |
146 | (?) :: Element t => Matrix t -> [Int] -> Matrix t | 179 | (?) :: Element t => Matrix t -> [Int] -> Matrix t |
147 | (?) = flip extractRows | 180 | (?) = flip extractRows |
@@ -172,7 +205,7 @@ norm = pnorm PNorm2 | |||
172 | unitary :: Vector Double -> Vector Double | 205 | unitary :: Vector Double -> Vector Double |
173 | unitary v = v / scalar (norm v) | 206 | unitary v = v / scalar (norm v) |
174 | 207 | ||
175 | -- | (rows &&& cols) | 208 | -- | ('rows' &&& 'cols') |
176 | size :: Matrix t -> (Int, Int) | 209 | size :: Matrix t -> (Int, Int) |
177 | size m = (rows m, cols m) | 210 | size m = (rows m, cols m) |
178 | 211 | ||