[SciPy-User] leastsq and cython
Mon Sep 27 08:50:15 CDT 2010
Am 26.09.2010 00:45, schrieb Till Stensitzki:
> Warren Weckesser<warren.weckesser<at> enthought.com> writes:
>> On 9/25/10 4:27 PM, Charles R Harris wrote:
>> On Sat, Sep 25, 2010 at 3:03 PM, David Baddeley<david_baddeley<at>
>> I've, run into a similar problem, it's due to the fact that
>> native methods (ie
>> ones loaded from c libraries) are not quite the same as pure
>> python function
>> objects& don't possess all the nice attributes. It's been
>> a while, but I seem
>> to remember that this error crops up when leastsq is trying to
>> print some form
>> of status message with the function name in it. I've
>> circumvented the problem by
>> making a thin python wrapper function which just calls my c
>> method. This works,
>> but is not ideal, as you introduce additional function call
>> overhead. If anyone
>> out there knows of a better solution I'd also be interested.
>> Maybe it shouldn't try to print the function name? The context
>> of the message might be enough.
>> The function 'check_func' in minpack.py uses the attribute
>> 'func_name' in an error message. I'm tweaking 'check_func' now so
>> that it first checks for the 'func_name' attribute before trying to
>> use it.
>> Any suggestions for incorporating a cython or ctypes function into a
>> test, so I can include tests of the change?
>> SciPy-User mailing list
>> SciPy-User<at> scipy.org
> Hmm, i tried to change my check_func too, but it seems the error stems also from
> c/fortran code. While cython function don't have the func_name attribute, the
> have the __name__ attribute, maybe it help. While we are at it, i have some
> questions about leastsq:
> 1. it seems to use always the double precision versions of lmdif, is there a way
> to change it? I am using cuda for the calculation of my function values, so no
> double precision for me. Another reason for using the single precision are
> memory concerns, as i am fitting around 70 000 data points with 600 parameters,
> so the size of jacobian is quite big.
I had a similar problem with analyzing images - millions of data points.
I ended up in implementing the Levenberg-Marquardt-algorithm (on which
leastsq is based) in pure Python, so I could use single precision
arithmetic. I can send you the code.
> 2. does it use the same blas/lapack liberays as numpy?
lmdif uses its own implementation of the QR factorization, which is very
memory efficient, but slower than state-of-the-art (multithreaded)
In my case I could achieve a large speed improvement by directly solving
the normal equations instead of using the QR factorization (I know, this
is less accurate and typically not recommended in literature).
> 3. does it copy the Jacobian every time, or is there a way to write directly to
> the right memory?
Don't know how much of copying takes place, but copying is not the
limiting the performance.
> thanks for the fast answers and help,
> SciPy-User mailing list
Dr. Gregor Thalhammer
Sektion für Biomedizinische Physik
Medizinische Universität Innsbruck
+43 512 9003 70875
More information about the SciPy-User