diff options
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Tests/Instances.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests/Instances.hs | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/lib/Numeric/LinearAlgebra/Tests/Instances.hs index 583143a..af486c8 100644 --- a/lib/Numeric/LinearAlgebra/Tests/Instances.hs +++ b/lib/Numeric/LinearAlgebra/Tests/Instances.hs | |||
@@ -14,10 +14,13 @@ Arbitrary instances for vectors, matrices. | |||
14 | -} | 14 | -} |
15 | 15 | ||
16 | module Numeric.LinearAlgebra.Tests.Instances( | 16 | module Numeric.LinearAlgebra.Tests.Instances( |
17 | Sq(..), | 17 | Sq(..), rSq,cSq, |
18 | Rot(..), | 18 | Rot(..), rRot,cRot, |
19 | Her(..), | 19 | Her(..), rHer,cHer, |
20 | WC(..) | 20 | WC(..), rWC,cWC, |
21 | SqWC(..), rSqWC, cSqWC, | ||
22 | PosDef(..), rPosDef, cPosDef, | ||
23 | RM,CM, rM,cM | ||
21 | ) where | 24 | ) where |
22 | 25 | ||
23 | import Numeric.LinearAlgebra | 26 | import Numeric.LinearAlgebra |
@@ -74,7 +77,7 @@ instance (Field a, Arbitrary a) => Arbitrary (Her a) where | |||
74 | return $ Her (m' + ctrans m') | 77 | return $ Her (m' + ctrans m') |
75 | coarbitrary = undefined | 78 | coarbitrary = undefined |
76 | 79 | ||
77 | -- a well-conditioned matrix (the singular values are between 1 and 100) | 80 | -- a well-conditioned general matrix (the singular values are between 1 and 100) |
78 | newtype (WC a) = WC (Matrix a) deriving Show | 81 | newtype (WC a) = WC (Matrix a) deriving Show |
79 | instance (Field a, Arbitrary a) => Arbitrary (WC a) where | 82 | instance (Field a, Arbitrary a) => Arbitrary (WC a) where |
80 | arbitrary = do | 83 | arbitrary = do |
@@ -87,3 +90,53 @@ instance (Field a, Arbitrary a) => Arbitrary (WC a) where | |||
87 | let s = diagRect (fromList sv) r c | 90 | let s = diagRect (fromList sv) r c |
88 | return $ WC (u <> real s <> trans v) | 91 | return $ WC (u <> real s <> trans v) |
89 | coarbitrary = undefined | 92 | coarbitrary = undefined |
93 | |||
94 | -- a well-conditioned square matrix (the singular values are between 1 and 100) | ||
95 | newtype (SqWC a) = SqWC (Matrix a) deriving Show | ||
96 | instance (Field a, Arbitrary a) => Arbitrary (SqWC a) where | ||
97 | arbitrary = do | ||
98 | Sq m <- arbitrary | ||
99 | let (u,_,v) = svd m | ||
100 | n = rows m | ||
101 | sv <- replicateM n (choose (1,100)) | ||
102 | let s = diag (fromList sv) | ||
103 | return $ SqWC (u <> real s <> trans v) | ||
104 | coarbitrary = undefined | ||
105 | |||
106 | -- a positive definite square matrix (the eigenvalues are between 0 and 100) | ||
107 | newtype (PosDef a) = PosDef (Matrix a) deriving Show | ||
108 | instance (Field a, Arbitrary a) => Arbitrary (PosDef a) where | ||
109 | arbitrary = do | ||
110 | Her m <- arbitrary | ||
111 | let (_,v) = eigSH m | ||
112 | n = rows m | ||
113 | l <- replicateM n (choose (0,100)) | ||
114 | let s = diag (fromList l) | ||
115 | p = v <> real s <> ctrans v | ||
116 | return $ PosDef (0.5 .* p + 0.5 .* ctrans p) | ||
117 | coarbitrary = undefined | ||
118 | |||
119 | type RM = Matrix Double | ||
120 | type CM = Matrix (Complex Double) | ||
121 | |||
122 | rM m = m :: RM | ||
123 | cM m = m :: CM | ||
124 | |||
125 | rHer (Her m) = m :: RM | ||
126 | cHer (Her m) = m :: CM | ||
127 | |||
128 | rRot (Rot m) = m :: RM | ||
129 | cRot (Rot m) = m :: CM | ||
130 | |||
131 | rSq (Sq m) = m :: RM | ||
132 | cSq (Sq m) = m :: CM | ||
133 | |||
134 | rWC (WC m) = m :: RM | ||
135 | cWC (WC m) = m :: CM | ||
136 | |||
137 | rSqWC (SqWC m) = m :: RM | ||
138 | cSqWC (SqWC m) = m :: CM | ||
139 | |||
140 | rPosDef (PosDef m) = m :: RM | ||
141 | cPosDef (PosDef m) = m :: CM | ||
142 | |||