summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-04-30 16:10:20 +0200
committerAlberto Ruiz <aruiz@um.es>2014-04-30 16:10:20 +0200
commitcf1379fed234cf99b2ccce6d9311bfc5c58ef4a3 (patch)
tree2532837500eb98af048404e33018fa88d8a7f535 /lib/Numeric/LinearAlgebra
parentb8b7b47450a1007d4d8c77bb7d04e2744c3bfcd4 (diff)
improved documentation
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs23
-rw-r--r--lib/Numeric/LinearAlgebra/Data.hs9
-rw-r--r--lib/Numeric/LinearAlgebra/Data/Devel.hs4
-rw-r--r--lib/Numeric/LinearAlgebra/Util.hs49
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] 375m = (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
3791. 0. 0. 3811. 0. 0.
3800. 1. 0. 3820. 1. 0.
3810. 0. 10000000000. 3830. 0. 10000000000.
382\ -- 384
383\> pinvTol 1E8 m 385>>> pinvTol 1E8 m
3841. 0. 0. 3861. 0. 0.
3850. 1. 0. 3870. 1. 0.
3860. 0. 1.@ 3880. 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-}
606sqrtm :: Field t => Matrix t -> Matrix t 609sqrtm :: Field t => Matrix t -> Matrix t
607sqrtm = sqrtmInv 610sqrtm = 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
13module Numeric.LinearAlgebra.Data( 13module 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
57import Data.Packed.Foreign 57import Data.Packed.Foreign
58import Data.Packed.Development 58import Data.Packed.Development
59import Data.Packed.ST 59import Data.Packed.ST
60import Numeric.Container(Container) 60import Numeric.Container(Container,Contraction,LSDiv,Product)
61import Data.Packed 61import 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
15module Numeric.LinearAlgebra.Util( 15module 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
65import Graphics.Plot 65import 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
712x2
720.33333 0.00000
730.00000 0.33333
74
75-}
68disp :: Int -> Matrix Double -> IO () 76disp :: Int -> Matrix Double -> IO ()
69-- ^ show a matrix with given number of digits after the decimal point 77
70disp n = putStrLn . dispf n 78disp 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
82rand :: Int -> Int -> IO (Matrix Double) 90rand :: Int -> Int -> IO (Matrix Double)
83rand = randm Uniform 91rand = 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
973x5
980.386 -1.141 0.491 -0.510 1.512
990.069 -0.919 1.022 -0.181 0.745
1000.313 -0.670 -0.097 -1.575 -0.583
101
102-}
86randn :: Int -> Int -> IO (Matrix Double) 103randn :: Int -> Int -> IO (Matrix Double)
87randn = randm Gaussian 104randn = randm Gaussian
88 105
@@ -115,9 +132,17 @@ infixl 3 &
115(&) :: Vector Double -> Vector Double -> Vector Double 132(&) :: Vector Double -> Vector Double -> Vector Double
116a & b = vjoin [a,b] 133a & 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-}
121infixl 3 ¦ 146infixl 3 ¦
122(¦) :: Matrix Double -> Matrix Double -> Matrix Double 147(¦) :: Matrix Double -> Matrix Double -> Matrix Double
123a ¦ b = fromBlocks [[a,b]] 148a ¦ b = fromBlocks [[a,b]]
@@ -141,7 +166,15 @@ row = asRow . fromList
141col :: [Double] -> Matrix Double 166col :: [Double] -> Matrix Double
142col = asColumn . fromList 167col = 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-}
145infixl 9 ? 178infixl 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
172unitary :: Vector Double -> Vector Double 205unitary :: Vector Double -> Vector Double
173unitary v = v / scalar (norm v) 206unitary v = v / scalar (norm v)
174 207
175-- | (rows &&& cols) 208-- | ('rows' &&& 'cols')
176size :: Matrix t -> (Int, Int) 209size :: Matrix t -> (Int, Int)
177size m = (rows m, cols m) 210size m = (rows m, cols m)
178 211