Intermittent hangs in the "newton's method" function.

Bug #236872 reported by slash2314
2
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')
boston.date = ephem.Date('2008/5/29 15:59:16')
boston.next_rising(mars)

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:
            close_runs -= 1
    return x1
[/CODE]

As you can see it is looping in the newton method in the __init__.py for ephem.

slash2314 (slash2314)
description: updated
slash2314 (slash2314)
description: updated
Revision history for this message
Brandon Rhodes (brandon-rhodes) wrote :

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!

Changed in pyephem:
assignee: nobody → brandon-rhodes
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Brandon Rhodes (brandon-rhodes) wrote :

I have just released a new version of PyEphem, 3.7.3.1, which fixes this problem. I have adjusted the Newton's Method function so that it stops once it is within half a second of clock time of the actual event it is searching for. Your example in this bug report is now one of the permanent tests in PyEphem's unit test suite, so the problem should not be repeated. Thanks for your report!

Changed in pyephem:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.