diff options
author | Alberto Ruiz <aruiz@um.es> | 2009-06-04 09:01:56 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2009-06-04 09:01:56 +0000 |
commit | 6e0dd472ef8c570ec1924ac641e5872db30ac142 (patch) | |
tree | 64963c6af75cdbc02336de82b51136964f36dc73 /lib/Numeric/LinearAlgebra/Tests.hs | |
parent | f49ac4def26b38d3d084375007715156be347412 (diff) |
added some root finding algorithms
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Tests.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests.hs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs index 278df78..4f73e3a 100644 --- a/lib/Numeric/LinearAlgebra/Tests.hs +++ b/lib/Numeric/LinearAlgebra/Tests.hs | |||
@@ -36,6 +36,8 @@ a ^ b = a Prelude.^ (b :: Int) | |||
36 | 36 | ||
37 | utest str b = TestCase $ assertBool str b | 37 | utest str b = TestCase $ assertBool str b |
38 | 38 | ||
39 | a ~~ b = fromList a |~| fromList b | ||
40 | |||
39 | feye n = flipud (ident n) :: Matrix Double | 41 | feye n = flipud (ident n) :: Matrix Double |
40 | 42 | ||
41 | detTest1 = det m == 26 | 43 | detTest1 = det m == 26 |
@@ -112,12 +114,17 @@ minimizationTest = TestList [ utest "minimization conj grad" (minim1 f df [5,7] | |||
112 | ] | 114 | ] |
113 | where f [x,y] = 10*(x-1)^2 + 20*(y-2)^2 + 30 | 115 | where f [x,y] = 10*(x-1)^2 + 20*(y-2)^2 + 30 |
114 | df [x,y] = [20*(x-1), 40*(y-2)] | 116 | df [x,y] = [20*(x-1), 40*(y-2)] |
115 | a ~~ b = fromList a |~| fromList b | ||
116 | minim1 g dg ini = fst $ minimizeConjugateGradient 1E-2 1E-4 1E-3 30 g dg ini | 117 | minim1 g dg ini = fst $ minimizeConjugateGradient 1E-2 1E-4 1E-3 30 g dg ini |
117 | minim2 g dg ini = fst $ minimizeVectorBFGS2 1E-2 1E-2 1E-3 30 g dg ini | 118 | minim2 g dg ini = fst $ minimizeVectorBFGS2 1E-2 1E-2 1E-3 30 g dg ini |
118 | 119 | ||
119 | --------------------------------------------------------------------- | 120 | --------------------------------------------------------------------- |
120 | 121 | ||
122 | rootFindingTest = utest "root Hybrids" (sol ~~ [1,1]) | ||
123 | where sol = fst $ root Hybrids 1E-7 30 (rosenbrock 1 10) [-10,-5] | ||
124 | rosenbrock a b [x,y] = [ a*(1-x), b*(y-x^2) ] | ||
125 | |||
126 | --------------------------------------------------------------------- | ||
127 | |||
121 | rot :: Double -> Matrix Double | 128 | rot :: Double -> Matrix Double |
122 | rot a = (3><3) [ c,0,s | 129 | rot a = (3><3) [ c,0,s |
123 | , 0,1,0 | 130 | , 0,1,0 |
@@ -217,6 +224,7 @@ runTests n = do | |||
217 | , utest "integrate" (abs (volSphere 2.5 - 4/3*pi*2.5^3) < 1E-8) | 224 | , utest "integrate" (abs (volSphere 2.5 - 4/3*pi*2.5^3) < 1E-8) |
218 | , utest "polySolve" (polySolveProp [1,2,3,4]) | 225 | , utest "polySolve" (polySolveProp [1,2,3,4]) |
219 | , minimizationTest | 226 | , minimizationTest |
227 | , rootFindingTest | ||
220 | ] | 228 | ] |
221 | return () | 229 | return () |
222 | 230 | ||