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 | |
parent | b8b7b47450a1007d4d8c77bb7d04e2744c3bfcd4 (diff) |
improved documentation
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Algorithms.hs | 23 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Data.hs | 9 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Data/Devel.hs | 4 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Util.hs | 49 |
4 files changed, 62 insertions, 23 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index 7223cd9..7c1c032 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -371,19 +371,21 @@ pinv = pinvTol 1 | |||
371 | 371 | ||
372 | {- | @pinvTol r@ computes the pseudoinverse of a matrix with tolerance @tol=r*g*eps*(max rows cols)@, where g is the greatest singular value. | 372 | {- | @pinvTol r@ computes the pseudoinverse of a matrix with tolerance @tol=r*g*eps*(max rows cols)@, where g is the greatest singular value. |
373 | 373 | ||
374 | @\> let m = 'fromLists' [[1,0, 0] | 374 | @ |
375 | ,[0,1, 0] | 375 | m = (3><3) [ 1, 0, 0 |
376 | ,[0,0,1e-10]] | 376 | , 0, 1, 0 |
377 | \ -- | 377 | , 0, 0, 1e-10] :: Matrix Double |
378 | \> 'pinv' m | 378 | @ |
379 | |||
380 | >>> pinv m | ||
379 | 1. 0. 0. | 381 | 1. 0. 0. |
380 | 0. 1. 0. | 382 | 0. 1. 0. |
381 | 0. 0. 10000000000. | 383 | 0. 0. 10000000000. |
382 | \ -- | 384 | |
383 | \> pinvTol 1E8 m | 385 | >>> pinvTol 1E8 m |
384 | 1. 0. 0. | 386 | 1. 0. 0. |
385 | 0. 1. 0. | 387 | 0. 1. 0. |
386 | 0. 0. 1.@ | 388 | 0. 0. 1. |
387 | 389 | ||
388 | -} | 390 | -} |
389 | 391 | ||
@@ -598,10 +600,11 @@ It only works with invertible matrices that have a real solution. For diagonaliz | |||
598 | @m = (2><2) [4,9 | 600 | @m = (2><2) [4,9 |
599 | ,0,4] :: Matrix Double@ | 601 | ,0,4] :: Matrix Double@ |
600 | 602 | ||
601 | @\>sqrtm m | 603 | >>> sqrtm m |
602 | (2><2) | 604 | (2><2) |
603 | [ 2.0, 2.25 | 605 | [ 2.0, 2.25 |
604 | , 0.0, 2.0 ]@ | 606 | , 0.0, 2.0 ] |
607 | |||
605 | -} | 608 | -} |
606 | sqrtm :: Field t => Matrix t -> Matrix t | 609 | sqrtm :: Field t => Matrix t -> Matrix t |
607 | sqrtm = sqrtmInv | 610 | sqrtm = sqrtmInv |
diff --git a/lib/Numeric/LinearAlgebra/Data.hs b/lib/Numeric/LinearAlgebra/Data.hs index 6e5dcef..a3639d5 100644 --- a/lib/Numeric/LinearAlgebra/Data.hs +++ b/lib/Numeric/LinearAlgebra/Data.hs | |||
@@ -12,6 +12,8 @@ Stability : provisional | |||
12 | 12 | ||
13 | module Numeric.LinearAlgebra.Data( | 13 | module Numeric.LinearAlgebra.Data( |
14 | -- * Vector | 14 | -- * Vector |
15 | -- | 1D arrays are storable vectors from the vector package. | ||
16 | |||
15 | Vector, (|>), dim, (@>), | 17 | Vector, (|>), dim, (@>), |
16 | 18 | ||
17 | -- * Matrix | 19 | -- * Matrix |
@@ -49,13 +51,13 @@ module Numeric.LinearAlgebra.Data( | |||
49 | 51 | ||
50 | -- * Products | 52 | -- * Products |
51 | 53 | ||
52 | (<>), (·), scale, outer, kronecker, cross, | 54 | (<>), (·), outer, kronecker, cross, |
53 | sumElements, prodElements, absSum, | 55 | sumElements, prodElements, absSum, |
54 | optimiseMult, | 56 | optimiseMult, |
55 | 57 | ||
56 | corr, conv, corrMin, corr2, conv2, | 58 | corr, conv, corrMin, corr2, conv2, |
57 | 59 | ||
58 | LSDiv(..), | 60 | (<\>), |
59 | 61 | ||
60 | -- * Random arrays | 62 | -- * Random arrays |
61 | 63 | ||
@@ -80,7 +82,8 @@ module Numeric.LinearAlgebra.Data( | |||
80 | module Data.Complex, | 82 | module Data.Complex, |
81 | 83 | ||
82 | -- * Misc | 84 | -- * Misc |
83 | meanCov, arctan2, | 85 | scale, meanCov, arctan2, |
86 | rows, cols, | ||
84 | separable, | 87 | separable, |
85 | fromArray2D | 88 | fromArray2D |
86 | 89 | ||
diff --git a/lib/Numeric/LinearAlgebra/Data/Devel.hs b/lib/Numeric/LinearAlgebra/Data/Devel.hs index 6358d1f..88c980c 100644 --- a/lib/Numeric/LinearAlgebra/Data/Devel.hs +++ b/lib/Numeric/LinearAlgebra/Data/Devel.hs | |||
@@ -51,13 +51,13 @@ module Numeric.LinearAlgebra.Data.Devel( | |||
51 | liftMatrix, liftMatrix2, liftMatrix2Auto, | 51 | liftMatrix, liftMatrix2, liftMatrix2Auto, |
52 | 52 | ||
53 | -- * Misc | 53 | -- * Misc |
54 | Element, Container | 54 | Element, Container, Product, Contraction, LSDiv |
55 | ) where | 55 | ) where |
56 | 56 | ||
57 | import Data.Packed.Foreign | 57 | import Data.Packed.Foreign |
58 | import Data.Packed.Development | 58 | import Data.Packed.Development |
59 | import Data.Packed.ST | 59 | import Data.Packed.ST |
60 | import Numeric.Container(Container) | 60 | import Numeric.Container(Container,Contraction,LSDiv,Product) |
61 | import Data.Packed | 61 | import Data.Packed |
62 | 62 | ||
63 | 63 | ||
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 | ||