diff options
author | Kristof Bastiaensen <kristof@vleeuwen.org> | 2013-08-16 14:16:32 +0200 |
---|---|---|
committer | Kristof Bastiaensen <kristof@vleeuwen.org> | 2013-08-16 14:16:32 +0200 |
commit | e208b972e38eff84c0287ae6bf32db7b42cce0f6 (patch) | |
tree | 82a65722ae7a8fd67fd60a47e74d0d8c2bb358a5 /lib/Numeric/GSL/Minimization.hs | |
parent | 374194ee454622e66c931dce8f315c68167c7ac9 (diff) |
Added onedimensional minimization.
Diffstat (limited to 'lib/Numeric/GSL/Minimization.hs')
-rw-r--r-- | lib/Numeric/GSL/Minimization.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Numeric/GSL/Minimization.hs b/lib/Numeric/GSL/Minimization.hs index af85135..7ccca81 100644 --- a/lib/Numeric/GSL/Minimization.hs +++ b/lib/Numeric/GSL/Minimization.hs | |||
@@ -53,6 +53,7 @@ The nmsimplex2 version is a new O(N) implementation of the earlier O(N^2) nmsimp | |||
53 | module Numeric.GSL.Minimization ( | 53 | module Numeric.GSL.Minimization ( |
54 | minimize, minimizeV, MinimizeMethod(..), | 54 | minimize, minimizeV, MinimizeMethod(..), |
55 | minimizeD, minimizeVD, MinimizeMethodD(..), | 55 | minimizeD, minimizeVD, MinimizeMethodD(..), |
56 | uniMinimize, UniMinimizeMethod(..), | ||
56 | 57 | ||
57 | minimizeNMSimplex, | 58 | minimizeNMSimplex, |
58 | minimizeConjugateGradient, | 59 | minimizeConjugateGradient, |
@@ -81,6 +82,39 @@ minimizeVectorBFGS2 step tol eps maxit f g xi = minimizeD VectorBFGS2 eps maxit | |||
81 | 82 | ||
82 | ------------------------------------------------------------------------- | 83 | ------------------------------------------------------------------------- |
83 | 84 | ||
85 | data UniMinimizeMethod = GoldenSection | ||
86 | | BrentMini | ||
87 | | QuadGolden | ||
88 | deriving (Enum, Eq, Show, Bounded) | ||
89 | |||
90 | -- | Onedimensional minimization. | ||
91 | |||
92 | uniMinimize :: UniMinimizeMethod -- ^ The method used. | ||
93 | -> Double -- ^ desired precision of the solution | ||
94 | -> Int -- ^ maximum number of iterations allowed | ||
95 | -> (Double -> Double) -- ^ function to minimize | ||
96 | -> Double -- ^ guess for the location of the minimum | ||
97 | -> Double -- ^ lower bound of search interval | ||
98 | -> Double -- ^ upper bound of search interval | ||
99 | -> (Double, Matrix Double) -- ^ solution and optimization path | ||
100 | |||
101 | uniMinimize method epsrel maxit fun xmin xl xu = uniMinimizeGen (fi (fromEnum method)) fun xmin xl xu epsrel maxit | ||
102 | |||
103 | uniMinimizeGen m f xmin xl xu epsrel maxit = unsafePerformIO $ do | ||
104 | fp <- mkDoublefun f | ||
105 | rawpath <- createMIO maxit 4 | ||
106 | (c_uniMinize m fp epsrel (fi maxit) xmin xl xu) | ||
107 | "uniMinimize" | ||
108 | let it = round (rawpath @@> (maxit-1,0)) | ||
109 | path = takeRows it rawpath | ||
110 | [sol] = toLists $ dropRows (it-1) path | ||
111 | freeHaskellFunPtr fp | ||
112 | return (sol !! 1, path) | ||
113 | |||
114 | |||
115 | foreign import ccall safe "uniMinimize" | ||
116 | c_uniMinize:: CInt -> FunPtr (Double -> Double) -> Double -> CInt -> Double -> Double -> Double -> TM | ||
117 | |||
84 | data MinimizeMethod = NMSimplex | 118 | data MinimizeMethod = NMSimplex |
85 | | NMSimplex2 | 119 | | NMSimplex2 |
86 | deriving (Enum,Eq,Show,Bounded) | 120 | deriving (Enum,Eq,Show,Bounded) |