Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Lally vs LesterNachman differences in test-suite #34

Open
kesterlester opened this issue Feb 14, 2021 · 17 comments
Open

Resolve Lally vs LesterNachman differences in test-suite #34

kesterlester opened this issue Feb 14, 2021 · 17 comments
Assignees

Comments

@kesterlester
Copy link
Contributor

kesterlester commented Feb 14, 2021

Reminder to self that it would be a good idea for @kesterlester to check out the events and MT2 discrepancies talked about in Appendix B of Lally's https://arxiv.org/pdf/1509.01831.pdf ....

@kesterlester
Copy link
Contributor Author

To do this @kesterlester will need @tpgillam to have first solved issue #35 .

@tpgillam
Copy link
Owner

I have written a fuzz-test, which very quickly identified some very different cases.

For example, on MacOS I see:

bad_args = (
    29.359184426449335, -41.66748425813935, 2.4727555091581337, 
    68.86316293078755, 88.10079057588052, -39.0193751229873, 
    27.644883008122292, -29.00097683721164, 
    69.60314069891137, 28.917825385644313)
print(mt2(*bad_args))  # 101.71793913068785
print(mt2_lally(*bad_args))  # 100.58558700648662

Interestingly, varying the precision argument on mt2_lally makes no difference to the answer, even when set to very large answers. For mt2 the difference in final result can be quite significant.

@kesterlester
Copy link
Contributor Author

kesterlester commented Feb 15, 2021 via email

@tpgillam
Copy link
Owner

There are indeed loads. Currently my random sampler is almost guaranteed to fail after more than about 100 draws.

@tpgillam
Copy link
Owner

tpgillam commented Feb 15, 2021

Here is the fuzz test, which is currently skipped as it would fail:

@pytest.mark.skip(reason="Currently failing due to inconsistencies")
def test_fuzz():
batch_size = 100
num_tests = 1000
numpy.random.seed(42)
def _random_batch(min_, max_):
return numpy.random.uniform(min_, max_, (batch_size,))
for _ in range(num_tests):
m_vis_1 = _random_batch(0, 100)
px_vis_1 = _random_batch(-100, 100)
py_vis_1 = _random_batch(-100, 100)
m_vis_2 = _random_batch(0, 100)
px_vis_2 = _random_batch(-100, 100)
py_vis_2 = _random_batch(-100, 100)
px_miss = _random_batch(-100, 100)
py_miss = _random_batch(-100, 100)
m_invis_1 = _random_batch(0, 100)
m_invis_2 = _random_batch(0, 100)
args = (
m_vis_1,
px_vis_1,
py_vis_1,
m_vis_2,
px_vis_2,
py_vis_2,
px_miss,
py_miss,
m_invis_1,
m_invis_2,
)
result_lester = mt2(*args)
result_lally = mt2_lally(*args)
numpy.testing.assert_allclose(result_lester, result_lally, rtol=1e-12)

@tpgillam
Copy link
Owner

Here is a visualisation of the bad_args event above. I'll push the code to generate this plot soon, once it's tidied up a bit.

image

In this case the Lester method is correct.

@kesterlester
Copy link
Contributor Author

One nill! [to be said with two syllables on each word]

@kesterlester
Copy link
Contributor Author

5 hours ago is 3:45 am!

@kesterlester
Copy link
Contributor Author

Lally makes a point somewhere in his paper that in some events the rate-of-change-of-size of ellipse wrt M is very large, and he comments that some of the places where he thinks I am wrong is in such cases.
Is it possible to add a +- to your ellipses. I.e. show not only lester(M2T) but also lester(MT2+-small perturbation). to check that things just don't look unreasonably good for me merely because of a rounding coincidence.

@tpgillam
Copy link
Owner

image

This is +- 0.1% in MT2 for each method. Code to reproduce is now pushed:

PYTHONPATH=. python examples/plot_constraints.py

@Rupt
Copy link
Collaborator

Rupt commented Mar 10, 2021

In case it is of any use, here is a csv with some examples where test_collinear_endpoint_cases reports 1% relative error or more with the Lally calculator: lally_1em2.zip.

@kesterlester
Copy link
Contributor Author

kesterlester commented Mar 10, 2021 via email

@Rupt
Copy link
Collaborator

Rupt commented Mar 10, 2021

@kesterlester Very nice to hear - I certainly had the advantage of a fresh perspective.

The file is available on the git issue here #34 (comment), so I don't think it needs to be committed (but am open to persuasion.)

Yes Tom puts my keyboard skills to shame also ;)

@kesterlester
Copy link
Contributor Author

kesterlester commented Mar 10, 2021 via email

@kesterlester
Copy link
Contributor Author

image

@Rupt
Copy link
Collaborator

Rupt commented Mar 11, 2021

Vile heresy against our Lord Kahan!

This would be internally consistent with inf == inf, log(hypot(inf, inf), atan2(inf, inf) etc.

But my standard library returns inf +nan*i for both of these.

@tpgillam
Copy link
Owner

Ah, but which nan? 🙂

Looking at everywhere where pi is appearing, I was thinking at first that they’d switched to a polar representation... but then they hadn’t. So very strange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants