summaryrefslogtreecommitdiff
path: root/packages/tests/src
diff options
context:
space:
mode:
authorMatthew Peddie <mpeddie@gmail.com>2015-07-22 22:44:07 +1000
committerMatthew Peddie <mpeddie@gmail.com>2015-07-22 22:44:07 +1000
commit998f5710d43e860987f43217ca57a5721e3eabb0 (patch)
tree5f5babd0feff6c0ecbf9631dc1df457e56a460e0 /packages/tests/src
parentf6a23683ae87810b8673c069eda4a8c0958ce84f (diff)
Add a unit test for the GSL simulated annealing module
Diffstat (limited to 'packages/tests/src')
-rw-r--r--packages/tests/src/Numeric/GSL/Tests.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/packages/tests/src/Numeric/GSL/Tests.hs b/packages/tests/src/Numeric/GSL/Tests.hs
index 3065fd8..025427b 100644
--- a/packages/tests/src/Numeric/GSL/Tests.hs
+++ b/packages/tests/src/Numeric/GSL/Tests.hs
@@ -21,6 +21,7 @@ import Test.HUnit (runTestTT, failures, Test(..), errors)
21 21
22import Numeric.LinearAlgebra.HMatrix 22import Numeric.LinearAlgebra.HMatrix
23import Numeric.GSL 23import Numeric.GSL
24import Numeric.GSL.SimulatedAnnealing
24import Numeric.LinearAlgebra.Tests (qCheck, utest) 25import Numeric.LinearAlgebra.Tests (qCheck, utest)
25import Numeric.LinearAlgebra.Tests.Properties ((|~|), (~~), (~=)) 26import Numeric.LinearAlgebra.Tests.Properties ((|~|), (~~), (~=))
26 27
@@ -106,6 +107,21 @@ interpolationTest = TestList [
106 107
107--------------------------------------------------------------------- 108---------------------------------------------------------------------
108 109
110simanTest = TestList [
111 -- We use a slightly more relaxed tolerance here because the
112 -- simulated annealer is randomized
113 utest "simulated annealing manual example" $ abs (result - 1.3631300) < 1e-6
114 ]
115 where
116 -- This is the example from the GSL manual.
117 result = simanSolve 0 1 exampleParams 15.5 exampleE exampleM exampleS Nothing
118 exampleParams = SimulatedAnnealingParams 200 10000 1.0 1.0 0.008 1.003 2.0e-6
119 exampleE x = exp (-(x - 1)**2) * sin (8 * x)
120 exampleM x y = abs $ x - y
121 exampleS rands stepSize current = (rands ! 0) * 2 * stepSize - stepSize + current
122
123---------------------------------------------------------------------
124
109minimizationTest = TestList 125minimizationTest = TestList
110 [ utest "minimization conjugatefr" (minim1 f df [5,7] ~~ [1,2]) 126 [ utest "minimization conjugatefr" (minim1 f df [5,7] ~~ [1,2])
111 , utest "minimization nmsimplex2" (minim2 f [5,7] `elem` [24,25]) 127 , utest "minimization nmsimplex2" (minim2 f [5,7] `elem` [24,25])
@@ -162,6 +178,7 @@ runTests n = do
162 , rootFindingTest 178 , rootFindingTest
163 , minimizationTest 179 , minimizationTest
164 , interpolationTest 180 , interpolationTest
181 , simanTest
165 , utest "deriv" derivTest 182 , utest "deriv" derivTest
166 , utest "integrate" (abs (volSphere 2.5 - 4/3*pi*2.5**3) < 1E-8) 183 , utest "integrate" (abs (volSphere 2.5 - 4/3*pi*2.5**3) < 1E-8)
167 , utest "polySolve" (polySolveProp [1,2,3,4]) 184 , utest "polySolve" (polySolveProp [1,2,3,4])