Intermittent hangs in the "newton's method" function.
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
PyEphem |
Fix Released
|
High
|
Brandon Rhodes |
Bug Description
I have observed a strange behavior with pyephem. Sometimes there can be what appears to be an infinite loop in the newton method.
If you try the following you will see what I mean.
import pyephem
mars = ephem.Mars()
boston = ephem.city(
boston.date = ephem.Date(
boston.
This seems to fix the problem for me, but it is probably not a permanent solution.
[CODE]
def newton(f, x0, x1):
"""Return an x-value at which the given function reaches zero."""
TOL = 0.0000001
ITERLIMIT = 1000
close_runs = 10
count = 0
f0, f1 = f(x0), f(x1)
while f1 and x1 != x0 and f1 != f0 and close_runs > 0 and count < ITERLIMIT:
count += 1
x0, x1 = x1, x1 + (x1 - x0) / (f0/f1 - 1)
f0, f1 = f1, f(x1)
if abs(f1-f0) < TOL:
return x1
[/CODE]
As you can see it is looping in the newton method in the __init__.py for ephem.
Thank you! There are lots of different ways to bound Newton's method searches, and I need to investigate all of the various techniques. But in the short term, I will go ahead and do something very much like this — though I might be tempted to watch for the times to converge rather than the value of the function. Look for a fix soon!