Broyden with complex numbers [Was Re: ANN: SciPy 0.11.0 beta 1 released]
On Tue, Jun 26, 2012 at 3:49 PM, Denis Laxalde <denis@laxalde.org> wrote:
Skipper Seabold a écrit :
Fixed in master.
Thanks for having a look, btw.
Should this be backported for 0.11 as well?
I think yes. This points out that the test coverage is incomplete here.
Done.
I uncovered some more unusual behavior doing root finding on functions with complex numbers. Is this assumed to be supported? If so, I can file more bug reports.
The nonlin module has tests with complex functions, so I guess it is supposed to be supported. Other modules don't apparently.
This is using broyden. Maybe it's my numpy? '1.8.0.dev-6a06466' I've since figured out there's a closed form solution to this function, but ... from scipy import optimize import numpy as np z = np.array([ 1.01839781-0.j, 0.29594979-0.9802577j, 0.29594979+0.9802577j, -1.47466178-0.j]) r = np.abs(z) func = lambda x : (r*np.exp(2j*np.pi*np.array(x))) - z # correct result optimize.broyden1(func, [0, -.203, .203, .5]) # raises an error optimize.broyden1(func, [0, -.203, .203, .5], line_search=None) <snip> TypeError: Cannot cast ufunc add output from dtype('complex128') to dtype('float64') with casting rule 'same_kind' Skipper
26.06.2012 22:04, Skipper Seabold kirjoitti:
This is using broyden. Maybe it's my numpy? '1.8.0.dev-6a06466' [clip] # raises an error optimize.broyden1(func, [0, -.203, .203, .5], line_search=None)
<snip>
TypeError: Cannot cast ufunc add output from dtype('complex128') to dtype('float64') with casting rule 'same_kind'
I get "nonlin.py:314: ComplexWarning: Casting complex values to real discards the imaginary part" with Numpy 1.6.1. There's indeed a probable bug on line 314 --- should maybe do "x = x + d" instead of "x += d". And yes, I think the inexact Newton should work OK also on the complex plane. I'm not sure whether all the Jacobian approximations are fully complex-safe, though. Pauli
Pauli Virtanen a écrit :
TypeError: Cannot cast ufunc add output from dtype('complex128') to dtype('float64') with casting rule 'same_kind' I get "nonlin.py:314: ComplexWarning: Casting complex values to real discards the imaginary part" with Numpy 1.6.1.
There's indeed a probable bug on line 314 --- should maybe do "x = x + d" instead of "x += d".
I agree. That would be consistent with what's done with line_search. -- Denis
Denis Laxalde a écrit :
TypeError: Cannot cast ufunc add output from dtype('complex128') to dtype('float64') with casting rule 'same_kind' I get "nonlin.py:314: ComplexWarning: Casting complex values to real discards the imaginary part" with Numpy 1.6.1.
There's indeed a probable bug on line 314 --- should maybe do "x = x + d" instead of "x += d".
I agree. That would be consistent with what's done with line_search.
Fixed in master and maintenance/0.11.x. -- Denis
On Wed, Jun 27, 2012 at 9:57 AM, Denis Laxalde <denis@laxalde.org> wrote:
Denis Laxalde a écrit :
TypeError: Cannot cast ufunc add output from dtype('complex128') to dtype('float64') with casting rule 'same_kind' I get "nonlin.py:314: ComplexWarning: Casting complex values to real discards the imaginary part" with Numpy 1.6.1.
There's indeed a probable bug on line 314 --- should maybe do "x = x + d" instead of "x += d".
I agree. That would be consistent with what's done with line_search.
Fixed in master and maintenance/0.11.x.
Great, thanks for looking into this. Skipper
Skipper Seabold a écrit :
TypeError: Cannot cast ufunc add output from dtype('complex128') to dtype('float64') with casting rule 'same_kind' I get "nonlin.py:314: ComplexWarning: Casting complex values to real discards the imaginary part" with Numpy 1.6.1.
There's indeed a probable bug on line 314 --- should maybe do "x = x + d" instead of "x += d".
I agree. That would be consistent with what's done with line_search.
Fixed in master and maintenance/0.11.x.
Great, thanks for looking into this.
That being said, your example still fails for me because of NaNs... -- Denis
On Wed, Jun 27, 2012 at 1:25 PM, Denis Laxalde <denis@laxalde.org> wrote:
Skipper Seabold a écrit :
> TypeError: Cannot cast ufunc add output from dtype('complex128') to > dtype('float64') with casting rule 'same_kind' I get "nonlin.py:314: ComplexWarning: Casting complex values to real discards the imaginary part" with Numpy 1.6.1.
There's indeed a probable bug on line 314 --- should maybe do "x = x + d" instead of "x += d".
I agree. That would be consistent with what's done with line_search.
Fixed in master and maintenance/0.11.x.
Great, thanks for looking into this.
That being said, your example still fails for me because of NaNs...
Hmm, I'm not sure if it's a 'typlcal' root finding problem, but I was definitely having problems with most of the solvers trying to get a solution when I don't know good starting values. It's why I ended up finding the closed form solution. Skipper
participants (3)
-
Denis Laxalde
-
Pauli Virtanen
-
Skipper Seabold