[SciPy-User] scipy.optimize lmder_ and dlopen / dlsym
David Baddeley
david_baddeley at yahoo.com.au
Tue Jan 18 15:26:13 EST 2011
Should have also mentioned that I've given levmar a whirl, and although you got
a subtle performance increase (I think it was ~ 2 fold), it wasn't as
spectactular as I'd have hoped and in general I didn't think it worth the hassle
(the GPL bit might have also put me off somewhat). That said, if you do decide
to go that route I could probably give you a copy of the python module I drummed
up using lmderr to fit a Gaussian. I don't remember having too much trouble
getting it to compile under linux (ubuntu) (although I might have had to hack
one or two parts - I know my strategy regarding dependencies was going to be to
put a local copy in the source tree and statically link it).
cheers,
David
----- Original Message ----
From: David Baddeley <david_baddeley at yahoo.com.au>
To: SciPy Users List <scipy-user at scipy.org>
Sent: Wed, 19 January, 2011 9:16:30 AM
Subject: Re: [SciPy-User] scipy.optimize lmder_ and dlopen / dlsym
Hi Sebastian,
I've done something similar - I can tell you that writing a c objective function
definitely speeds things up, even with the function call overhead from python,
although I too would like to be able to call the fortran methods directly from
c. Had a quick look at the leastsq code, but it was sufficiently intractable
that I put it towards the back of my priority list. If writing a c objective
function I'd suggest you avoid SWIG and go with the numpy c api as SWIG does
introduce a bit of overhead. You can also get a speed up by generating the
Gaussian into a pre-allocated numpy array, although you have to be a bit careful
if you do this for the residuals as lmderr holds a pointer/reference to the last
set of residuals so if you overwrite these things don't work. I also found that
you can't give leastsq a c goal function directly & that you have to wrap it in
a python function (it does some introspection on the function object to get the
function name to print a nice message about convergence, or lack thereof). Even
with these caveats, I did find a substantial improvement over just using a
Gaussian coded in python. I could probably give you my c coded objective
functions to give you something to work from, if desired.
cheers,
David
----- Original Message ----
From: Sebastian Haase <seb.haase at gmail.com>
To: SciPy Users List <SciPy-user at scipy.org>
Sent: Wed, 19 January, 2011 4:38:14 AM
Subject: [SciPy-User] scipy.optimize lmder_ and dlopen / dlsym
Hi,
I was trying to do some 2d Gaussian fitting on my image data using
scipy.optimize.leastsq.
This worked, but it still takes about 1ms for fitting sigma and
peakHeight on a 7x7 pixel image area.
So I'm thinking about speeding things up:
Writing the objective function and the Jacobian in C (I like using
SWIG) would be one thing.
But I'm also thinking that for such small problems, theHi overhead of
function calls back and forth in Python (for each parameter set
evaluation) would be problematic.
So my question is:
Can I access the underlying lmder_ function (which is normally called
from leastsq via minpack [ _minpackmodule.c ])
directly from my SWIGged extenstion module ?
I'm thinking of LoadLibrary (win32) and dlopen/dlsym (linux) ...
The advantage would be that I would _not_ have to find another C
implementation of Levenberg-Marquardt.
I found http://www.ics.forth.gr/~lourakis/levmar/index.html, but that
didn't even compile on debian and would be another dependency.
Thanks,
Sebastian Haase
_______________________________________________
SciPy-User mailing list
SciPy-User at scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
_______________________________________________
SciPy-User mailing list
SciPy-User at scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list