summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/minimize.hs9
-rw-r--r--examples/tests.hs4
-rw-r--r--lib/Data/Packed/Matrix.hs11
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs2
4 files changed, 13 insertions, 13 deletions
diff --git a/examples/minimize.hs b/examples/minimize.hs
index d7bc350..5beba3b 100644
--- a/examples/minimize.hs
+++ b/examples/minimize.hs
@@ -2,6 +2,7 @@
2import Numeric.GSL 2import Numeric.GSL
3import Numeric.LinearAlgebra 3import Numeric.LinearAlgebra
4import Graphics.Plot 4import Graphics.Plot
5import Text.Printf(printf)
5 6
6-- the function to be minimized 7-- the function to be minimized
7f [x,y] = 10*(x-1)^2 + 20*(y-2)^2 + 30 8f [x,y] = 10*(x-1)^2 + 20*(y-2)^2 + 30
@@ -26,18 +27,20 @@ main = do
26 -- conjugate gradient with true gradient 27 -- conjugate gradient with true gradient
27 let (s,p) = minimizeCG f df [5,7] 28 let (s,p) = minimizeCG f df [5,7]
28 print s -- solution 29 print s -- solution
29 dispR 2 p -- evolution of the algorithm 30 disp p -- evolution of the algorithm
30 let [x,y] = drop 2 (toColumns p) 31 let [x,y] = drop 2 (toColumns p)
31 mplot [x,y] -- path from the starting point to the solution 32 mplot [x,y] -- path from the starting point to the solution
32 33
33 -- conjugate gradient with estimated gradient 34 -- conjugate gradient with estimated gradient
34 let (s,p) = minimizeCG f (gradient f) [5,7] 35 let (s,p) = minimizeCG f (gradient f) [5,7]
35 print s 36 print s
36 dispR 2 p 37 disp p
37 mplot $ drop 2 (toColumns p) 38 mplot $ drop 2 (toColumns p)
38 39
39 -- without gradient, using the NM Simplex method 40 -- without gradient, using the NM Simplex method
40 let (s,p) = minimizeS f [5,7] 41 let (s,p) = minimizeS f [5,7]
41 print s 42 print s
42 dispR 2 p 43 disp p
43 mplot $ drop 3 (toColumns p) 44 mplot $ drop 3 (toColumns p)
45
46disp = putStrLn . format " " (printf "%.2f") \ No newline at end of file
diff --git a/examples/tests.hs b/examples/tests.hs
index 974ec24..b44d140 100644
--- a/examples/tests.hs
+++ b/examples/tests.hs
@@ -83,7 +83,7 @@ her (Her a) = a
83instance {-(Field a, Arbitrary a, Num a) =>-} Arbitrary Her where 83instance {-(Field a, Arbitrary a, Num a) =>-} Arbitrary Her where
84 arbitrary = do 84 arbitrary = do
85 SqM m <- arbitrary 85 SqM m <- arbitrary
86 return $ Her (m + conjTrans m) 86 return $ Her (m + ctrans m)
87 coarbitrary = undefined 87 coarbitrary = undefined
88 88
89data PairSM a = PairSM (Matrix a) (Matrix a) deriving Show 89data PairSM a = PairSM (Matrix a) (Matrix a) deriving Show
@@ -125,7 +125,7 @@ pseudorandomC seed (n,m) = toComplex (pseudorandomR seed (n,m), pseudorandomR (s
125 125
126bigmat = m + trans m :: RM 126bigmat = m + trans m :: RM
127 where m = pseudorandomR 18 (1000,1000) 127 where m = pseudorandomR 18 (1000,1000)
128bigmatc = mc + conjTrans mc ::CM 128bigmatc = mc + ctrans mc ::CM
129 where mc = pseudorandomC 19 (1000,1000) 129 where mc = pseudorandomC 19 (1000,1000)
130 130
131---------------------------------------------------------------------- 131----------------------------------------------------------------------
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 260c1e0..e94d038 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -16,10 +16,11 @@
16module Data.Packed.Matrix ( 16module Data.Packed.Matrix (
17 Field, 17 Field,
18 Matrix,rows,cols, 18 Matrix,rows,cols,
19 (><), reshape, flatten, 19 (><),
20 trans,
21 reshape, flatten,
20 fromLists, toLists, 22 fromLists, toLists,
21 (@@>), 23 (@@>),
22 trans, conjTrans,
23 asRow, asColumn, 24 asRow, asColumn,
24 fromRows, toRows, fromColumns, toColumns, 25 fromRows, toRows, fromColumns, toColumns,
25 fromBlocks, repmat, 26 fromBlocks, repmat,
@@ -28,7 +29,7 @@ module Data.Packed.Matrix (
28 extractRows, 29 extractRows,
29 ident, diag, diagRect, takeDiag, 30 ident, diag, diagRect, takeDiag,
30 liftMatrix, liftMatrix2, 31 liftMatrix, liftMatrix2,
31 format, dispR, readMatrix, fromFile, fromArray2D 32 format, readMatrix, fromFile, fromArray2D
32) where 33) where
33 34
34import Data.Packed.Internal 35import Data.Packed.Internal
@@ -154,10 +155,6 @@ flatten = cdat
154fromLists :: Field t => [[t]] -> Matrix t 155fromLists :: Field t => [[t]] -> Matrix t
155fromLists = fromRows . map fromList 156fromLists = fromRows . map fromList
156 157
157-- | conjugate transpose
158conjTrans :: Matrix (Complex Double) -> Matrix (Complex Double)
159conjTrans = trans . liftMatrix conj
160
161-- | creates a 1-row matrix from a vector 158-- | creates a 1-row matrix from a vector
162asRow :: Field a => Vector a -> Matrix a 159asRow :: Field a => Vector a -> Matrix a
163asRow v = reshape (dim v) v 160asRow v = reshape (dim v) v
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 425532d..84c399a 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -91,7 +91,7 @@ instance GenMat (Complex Double) where
91 lu = GSL.luC 91 lu = GSL.luC
92 linearSolve = linearSolveC 92 linearSolve = linearSolveC
93 linearSolveSVD = linearSolveSVDC Nothing 93 linearSolveSVD = linearSolveSVDC Nothing
94 ctrans = conjTrans 94 ctrans = conj . trans
95 eig = eigC 95 eig = eigC
96 eigSH' = eigH 96 eigSH' = eigH
97 cholSH = cholH 97 cholSH = cholH