From 998f5710d43e860987f43217ca57a5721e3eabb0 Mon Sep 17 00:00:00 2001 From: Matthew Peddie Date: Wed, 22 Jul 2015 22:44:07 +1000 Subject: Add a unit test for the GSL simulated annealing module --- packages/tests/src/Numeric/GSL/Tests.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'packages/tests/src/Numeric') 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) import Numeric.LinearAlgebra.HMatrix import Numeric.GSL +import Numeric.GSL.SimulatedAnnealing import Numeric.LinearAlgebra.Tests (qCheck, utest) import Numeric.LinearAlgebra.Tests.Properties ((|~|), (~~), (~=)) @@ -106,6 +107,21 @@ interpolationTest = TestList [ --------------------------------------------------------------------- +simanTest = TestList [ + -- We use a slightly more relaxed tolerance here because the + -- simulated annealer is randomized + utest "simulated annealing manual example" $ abs (result - 1.3631300) < 1e-6 + ] + where + -- This is the example from the GSL manual. + result = simanSolve 0 1 exampleParams 15.5 exampleE exampleM exampleS Nothing + exampleParams = SimulatedAnnealingParams 200 10000 1.0 1.0 0.008 1.003 2.0e-6 + exampleE x = exp (-(x - 1)**2) * sin (8 * x) + exampleM x y = abs $ x - y + exampleS rands stepSize current = (rands ! 0) * 2 * stepSize - stepSize + current + +--------------------------------------------------------------------- + minimizationTest = TestList [ utest "minimization conjugatefr" (minim1 f df [5,7] ~~ [1,2]) , utest "minimization nmsimplex2" (minim2 f [5,7] `elem` [24,25]) @@ -162,6 +178,7 @@ runTests n = do , rootFindingTest , minimizationTest , interpolationTest + , simanTest , utest "deriv" derivTest , utest "integrate" (abs (volSphere 2.5 - 4/3*pi*2.5**3) < 1E-8) , utest "polySolve" (polySolveProp [1,2,3,4]) -- cgit v1.2.3