summaryrefslogtreecommitdiff
path: root/examples/minimize.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-10-04 14:16:57 +0200
committerAlberto Ruiz <aruiz@um.es>2015-10-04 14:16:57 +0200
commit0500032a1d954058b94cf9a0fa2a662e5666a526 (patch)
treedad39582ff940d2043acf6042470ee63898c3185 /examples/minimize.hs
parent04ec1d6b547d6c48506d66298f7d09f7de22c96e (diff)
update examples
Diffstat (limited to 'examples/minimize.hs')
-rw-r--r--examples/minimize.hs9
1 files changed, 5 insertions, 4 deletions
diff --git a/examples/minimize.hs b/examples/minimize.hs
index 19b2cb3..c27afc2 100644
--- a/examples/minimize.hs
+++ b/examples/minimize.hs
@@ -20,7 +20,7 @@ partialDerivative n f v = fst (derivCentral 0.01 g (v!!n)) where
20 g x = f (concat [a,x:b]) 20 g x = f (concat [a,x:b])
21 (a,_:b) = splitAt n v 21 (a,_:b) = splitAt n v
22 22
23disp = putStrLn . format " " (printf "%.3f") 23disp' = putStrLn . format " " (printf "%.3f")
24 24
25allMethods :: (Enum a, Bounded a) => [a] 25allMethods :: (Enum a, Bounded a) => [a]
26allMethods = [minBound .. maxBound] 26allMethods = [minBound .. maxBound]
@@ -29,22 +29,23 @@ test method = do
29 print method 29 print method
30 let (s,p) = minimize method 1E-2 30 [1,1] f [5,7] 30 let (s,p) = minimize method 1E-2 30 [1,1] f [5,7]
31 print s 31 print s
32 disp p 32 disp' p
33 33
34testD method = do 34testD method = do
35 print method 35 print method
36 let (s,p) = minimizeD method 1E-3 30 1E-2 1E-4 f df [5,7] 36 let (s,p) = minimizeD method 1E-3 30 1E-2 1E-4 f df [5,7]
37 print s 37 print s
38 disp p 38 disp' p
39 39
40testD' method = do 40testD' method = do
41 putStrLn $ show method ++ " with estimated gradient" 41 putStrLn $ show method ++ " with estimated gradient"
42 let (s,p) = minimizeD method 1E-3 30 1E-2 1E-4 f (gradient f) [5,7] 42 let (s,p) = minimizeD method 1E-3 30 1E-2 1E-4 f (gradient f) [5,7]
43 print s 43 print s
44 disp p 44 disp' p
45 45
46main = do 46main = do
47 mapM_ test [NMSimplex, NMSimplex2] 47 mapM_ test [NMSimplex, NMSimplex2]
48 mapM_ testD allMethods 48 mapM_ testD allMethods
49 testD' ConjugateFR 49 testD' ConjugateFR
50 mplot $ drop 3 . toColumns . snd $ minimizeS f [5,7] 50 mplot $ drop 3 . toColumns . snd $ minimizeS f [5,7]
51