summaryrefslogtreecommitdiff
path: root/packages/hmatrix/src/Numeric/GSL/Minimization.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/hmatrix/src/Numeric/GSL/Minimization.hs')
-rw-r--r--packages/hmatrix/src/Numeric/GSL/Minimization.hs25
1 files changed, 10 insertions, 15 deletions
diff --git a/packages/hmatrix/src/Numeric/GSL/Minimization.hs b/packages/hmatrix/src/Numeric/GSL/Minimization.hs
index 1879dab..056d463 100644
--- a/packages/hmatrix/src/Numeric/GSL/Minimization.hs
+++ b/packages/hmatrix/src/Numeric/GSL/Minimization.hs
@@ -1,13 +1,9 @@
1{-# LANGUAGE ForeignFunctionInterface #-}
2-----------------------------------------------------------------------------
3{- | 1{- |
4Module : Numeric.GSL.Minimization 2Module : Numeric.GSL.Minimization
5Copyright : (c) Alberto Ruiz 2006-9 3Copyright : (c) Alberto Ruiz 2006-9
6License : GPL-style 4License : GPL
7 5Maintainer : Alberto Ruiz
8Maintainer : Alberto Ruiz (aruiz at um dot es)
9Stability : provisional 6Stability : provisional
10Portability : uses ffi
11 7
12Minimization of a multidimensional function using some of the algorithms described in: 8Minimization of a multidimensional function using some of the algorithms described in:
13 9
@@ -48,7 +44,7 @@ The nmsimplex2 version is a new O(N) implementation of the earlier O(N^2) nmsimp
48 44
49-} 45-}
50 46
51----------------------------------------------------------------------------- 47
52module Numeric.GSL.Minimization ( 48module Numeric.GSL.Minimization (
53 minimize, minimizeV, MinimizeMethod(..), 49 minimize, minimizeV, MinimizeMethod(..),
54 minimizeD, minimizeVD, MinimizeMethodD(..), 50 minimizeD, minimizeVD, MinimizeMethodD(..),
@@ -60,8 +56,7 @@ module Numeric.GSL.Minimization (
60) where 56) where
61 57
62 58
63import Data.Packed.Internal 59import Data.Packed
64import Data.Packed.Matrix
65import Numeric.GSL.Internal 60import Numeric.GSL.Internal
66 61
67import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr) 62import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr)
@@ -112,7 +107,7 @@ uniMinimizeGen m f xmin xl xu epsrel maxit = unsafePerformIO $ do
112 107
113 108
114foreign import ccall safe "uniMinimize" 109foreign import ccall safe "uniMinimize"
115 c_uniMinize:: CInt -> FunPtr (Double -> Double) -> Double -> CInt -> Double -> Double -> Double -> TM 110 c_uniMinize:: CInt -> FunPtr (Double -> Double) -> Double -> CInt -> Double -> Double -> Double -> TM Res
116 111
117data MinimizeMethod = NMSimplex 112data MinimizeMethod = NMSimplex
118 | NMSimplex2 113 | NMSimplex2
@@ -150,13 +145,13 @@ minimizeV method eps maxit szv f xiv = unsafePerformIO $ do
150 "minimize" 145 "minimize"
151 let it = round (rawpath @@> (maxit-1,0)) 146 let it = round (rawpath @@> (maxit-1,0))
152 path = takeRows it rawpath 147 path = takeRows it rawpath
153 sol = cdat $ dropColumns 3 $ dropRows (it-1) path 148 sol = flatten $ dropColumns 3 $ dropRows (it-1) path
154 freeHaskellFunPtr fp 149 freeHaskellFunPtr fp
155 return (sol, path) 150 return (sol, path)
156 151
157 152
158foreign import ccall safe "gsl-aux.h minimize" 153foreign import ccall safe "gsl-aux.h minimize"
159 c_minimize:: CInt -> FunPtr (CInt -> Ptr Double -> Double) -> Double -> CInt -> TVVM 154 c_minimize:: CInt -> FunPtr (CInt -> Ptr Double -> Double) -> Double -> CInt -> TV(TV(TM Res))
160 155
161---------------------------------------------------------------------------------- 156----------------------------------------------------------------------------------
162 157
@@ -207,7 +202,7 @@ minimizeVD method eps maxit istep tol f df xiv = unsafePerformIO $ do
207 "minimizeD" 202 "minimizeD"
208 let it = round (rawpath @@> (maxit-1,0)) 203 let it = round (rawpath @@> (maxit-1,0))
209 path = takeRows it rawpath 204 path = takeRows it rawpath
210 sol = cdat $ dropColumns 2 $ dropRows (it-1) path 205 sol = flatten $ dropColumns 2 $ dropRows (it-1) path
211 freeHaskellFunPtr fp 206 freeHaskellFunPtr fp
212 freeHaskellFunPtr dfp 207 freeHaskellFunPtr dfp
213 return (sol,path) 208 return (sol,path)
@@ -215,9 +210,9 @@ minimizeVD method eps maxit istep tol f df xiv = unsafePerformIO $ do
215foreign import ccall safe "gsl-aux.h minimizeD" 210foreign import ccall safe "gsl-aux.h minimizeD"
216 c_minimizeD :: CInt 211 c_minimizeD :: CInt
217 -> FunPtr (CInt -> Ptr Double -> Double) 212 -> FunPtr (CInt -> Ptr Double -> Double)
218 -> FunPtr TVV 213 -> FunPtr (TV (TV Res))
219 -> Double -> Double -> Double -> CInt 214 -> Double -> Double -> Double -> CInt
220 -> TVM 215 -> TV (TM Res)
221 216
222--------------------------------------------------------------------- 217---------------------------------------------------------------------
223 218