summaryrefslogtreecommitdiff
path: root/packages/gsl/src/Numeric/GSL/Minimization.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gsl/src/Numeric/GSL/Minimization.hs')
-rw-r--r--packages/gsl/src/Numeric/GSL/Minimization.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/packages/gsl/src/Numeric/GSL/Minimization.hs b/packages/gsl/src/Numeric/GSL/Minimization.hs
index 056d463..00e0619 100644
--- a/packages/gsl/src/Numeric/GSL/Minimization.hs
+++ b/packages/gsl/src/Numeric/GSL/Minimization.hs
@@ -1,3 +1,6 @@
1{-# LANGUAGE FlexibleContexts #-}
2
3
1{- | 4{- |
2Module : Numeric.GSL.Minimization 5Module : Numeric.GSL.Minimization
3Copyright : (c) Alberto Ruiz 2006-9 6Copyright : (c) Alberto Ruiz 2006-9
@@ -56,7 +59,7 @@ module Numeric.GSL.Minimization (
56) where 59) where
57 60
58 61
59import Data.Packed 62import Numeric.LinearAlgebra.HMatrix hiding(step)
60import Numeric.GSL.Internal 63import Numeric.GSL.Internal
61 64
62import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr) 65import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr)
@@ -99,7 +102,7 @@ uniMinimizeGen m f xmin xl xu epsrel maxit = unsafePerformIO $ do
99 rawpath <- createMIO maxit 4 102 rawpath <- createMIO maxit 4
100 (c_uniMinize m fp epsrel (fi maxit) xmin xl xu) 103 (c_uniMinize m fp epsrel (fi maxit) xmin xl xu)
101 "uniMinimize" 104 "uniMinimize"
102 let it = round (rawpath @@> (maxit-1,0)) 105 let it = round (rawpath `atIndex` (maxit-1,0))
103 path = takeRows it rawpath 106 path = takeRows it rawpath
104 [sol] = toLists $ dropRows (it-1) path 107 [sol] = toLists $ dropRows (it-1) path
105 freeHaskellFunPtr fp 108 freeHaskellFunPtr fp
@@ -137,13 +140,13 @@ minimize method eps maxit sz f xi = v2l $ minimizeV method eps maxit (fromList s
137ww2 w1 o1 w2 o2 f = w1 o1 $ \a1 -> w2 o2 $ \a2 -> f a1 a2 140ww2 w1 o1 w2 o2 f = w1 o1 $ \a1 -> w2 o2 $ \a2 -> f a1 a2
138 141
139minimizeV method eps maxit szv f xiv = unsafePerformIO $ do 142minimizeV method eps maxit szv f xiv = unsafePerformIO $ do
140 let n = dim xiv 143 let n = size xiv
141 fp <- mkVecfun (iv f) 144 fp <- mkVecfun (iv f)
142 rawpath <- ww2 vec xiv vec szv $ \xiv' szv' -> 145 rawpath <- ww2 vec xiv vec szv $ \xiv' szv' ->
143 createMIO maxit (n+3) 146 createMIO maxit (n+3)
144 (c_minimize (fi (fromEnum method)) fp eps (fi maxit) // xiv' // szv') 147 (c_minimize (fi (fromEnum method)) fp eps (fi maxit) // xiv' // szv')
145 "minimize" 148 "minimize"
146 let it = round (rawpath @@> (maxit-1,0)) 149 let it = round (rawpath `atIndex` (maxit-1,0))
147 path = takeRows it rawpath 150 path = takeRows it rawpath
148 sol = flatten $ dropColumns 3 $ dropRows (it-1) path 151 sol = flatten $ dropColumns 3 $ dropRows (it-1) path
149 freeHaskellFunPtr fp 152 freeHaskellFunPtr fp
@@ -191,7 +194,7 @@ minimizeD method eps maxit istep tol f df xi = v2l $ minimizeVD
191 194
192 195
193minimizeVD method eps maxit istep tol f df xiv = unsafePerformIO $ do 196minimizeVD method eps maxit istep tol f df xiv = unsafePerformIO $ do
194 let n = dim xiv 197 let n = size xiv
195 f' = f 198 f' = f
196 df' = (checkdim1 n . df) 199 df' = (checkdim1 n . df)
197 fp <- mkVecfun (iv f') 200 fp <- mkVecfun (iv f')
@@ -200,7 +203,7 @@ minimizeVD method eps maxit istep tol f df xiv = unsafePerformIO $ do
200 createMIO maxit (n+2) 203 createMIO maxit (n+2)
201 (c_minimizeD (fi (fromEnum method)) fp dfp istep tol eps (fi maxit) // xiv') 204 (c_minimizeD (fi (fromEnum method)) fp dfp istep tol eps (fi maxit) // xiv')
202 "minimizeD" 205 "minimizeD"
203 let it = round (rawpath @@> (maxit-1,0)) 206 let it = round (rawpath `atIndex` (maxit-1,0))
204 path = takeRows it rawpath 207 path = takeRows it rawpath
205 sol = flatten $ dropColumns 2 $ dropRows (it-1) path 208 sol = flatten $ dropColumns 2 $ dropRows (it-1) path
206 freeHaskellFunPtr fp 209 freeHaskellFunPtr fp
@@ -217,6 +220,6 @@ foreign import ccall safe "gsl-aux.h minimizeD"
217--------------------------------------------------------------------- 220---------------------------------------------------------------------
218 221
219checkdim1 n v 222checkdim1 n v
220 | dim v == n = v 223 | size v == n = v
221 | otherwise = error $ "Error: "++ show n 224 | otherwise = error $ "Error: "++ show n
222 ++ " components expected in the result of the gradient supplied to minimizeD" 225 ++ " components expected in the result of the gradient supplied to minimizeD"