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

FIX Major bugfix in python refinement #377

Merged
merged 9 commits into from
Jul 6, 2016

Conversation

caspervdw
Copy link
Member

This removes any discrepancy between the python and numba engines:

  • the neighborhood should be calculated from rounded coordinates
  • the ndimage interpolation makes the code different from the numba engine and appears to add nothing in my tests

Fixes #376

In the pure python refinement code, the image slices were done
with floats, which get floored to an int by numpy, instead of
the intened round operation.
Fixes warning at multiplication with np.bool array.
@tacaswell
Copy link
Member

👍 makes sense to me. @danielballan or @nkeim should merge this as I am only passingly familiar with this code.

@caspervdw
Copy link
Member Author

In view of the API change this will give, some more testing data below. Apparently, the numba code was made more accurate by #242 without us realizing it. Now the python code is also fixed.

I guess this pure python refine could use some streamlining, but that is for another time.

this PR:
refine_trackpy_tests_pr

v0.3.0:
refine_trackpy_tests_master

v0.2.4:
refine_trackpy_tests_v0 2 4

@nkeim
Copy link
Contributor

nkeim commented Jun 17, 2016

@caspervdw This is great!! Thank you for tracking this down.

Your test results suggest that there are reliable upper bounds on positional error. Do you think this would work as an automated test? At this point I think that creating an issue would suffice.

@caspervdw
Copy link
Member Author

I was thinking the same. There is a test already, test_ep. I wonder why it passed. Maybe we need to sharpen the tolerances.

@danielballan
Copy link
Member

Probably. If you have the code that generated those plots handy, maybe we should start a stash of "human-in-the-loop" tests to be run before releases and on PRs that touch critical code.

@caspervdw
Copy link
Member Author

Shall we add this to v0.3.1?

@danielballan
Copy link
Member

Is the signal-to-noise ratio on the plots actually a noise-to-signal ratio? The trends are the opposite of what I would expect, unless I am confused.

My vote is that this is a bug fix, not an API change, and thus can go into v0.3.1 (not v0.4.0).

@tacaswell
Copy link
Member

I am also 👍 on this being a bugfix, not an API change.

On Sun, Jun 19, 2016 at 5:49 PM Dan Allan [email protected] wrote:

Is the signal-to-noise ratio on the plots actually a noise-to-signal
ratio? The trends are the opposite of what I would expect, unless I am
confused.

My vote is that this is a bug fix, not an API change, and thus can go into
v0.3.1 (not v0.4.0).


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#377 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAMMhbtg8vxu52_vr2HBqXnIi4tsy-_tks5qNblxgaJpZM4I0slI
.

@caspervdw
Copy link
Member Author

@danielballan Yes it should be noise-to-signal ratio... I will have a quick look at test_ep today so that we can merge soon.

@caspervdw caspervdw added this to the 0.3.1 milestone Jun 20, 2016
@caspervdw
Copy link
Member Author

Done, ready to merge

@nkeim
Copy link
Contributor

nkeim commented Jun 22, 2016

Sorry for taking a closer look so late. It looks like this removes the shift code that was the principal difference between the python and numba engines, going all the way back to the beginning. I had always thought that this made the python engine slightly superior! But the data don't lie.

@caspervdw
Copy link
Member Author

I'll quickly run a test today to check if there is a difference @nkeim

@caspervdw
Copy link
Member Author

Apparently, it really doesn't make a difference whether you interpolate or not:

refine_trackpy_tests

Or, the differences with numba (negative = better, positive = worse):
refine_trackpy_iterpolation_tests

@danielballan
Copy link
Member

Interesting! I had wondered about that too. It's in the original Crocker-Grier implementation but, IIRC correctly, not in Blair's code. I wonder if Crocker tried it without interpolation first or what motivated that in the first place.

# order=2, mode='constant', cval=0)
# new_coord = coord + off_center
# # Disallow any whole-pixels moves on future iterations.
# allow_moves = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All references to allow_moves can be removed. It will always be True.

Copy link
Member Author

@caspervdw caspervdw Jun 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look at it and refactor. Also the shift_thresh and break_thresh will be the same thing: if the code does not shift, it will break (as in break on line 371). Calculating the CoM without shifting makes no sense because the outcome will not change.

To test specific numba refine codes.
Drop `break_thresh` because it is not used anymore. Add deprecation
warning to `refine`, change API of `_refine` and numba codes.
@caspervdw
Copy link
Member Author

Done the refactor at @danielballan suggestion. Because the interpolation went out, the refinement loop could be simplified substantially: break_thresh and shift_thresh both resulted in stopping of the refinement loop. break_thresh basically did not have a function anymore. I dropped it as parameter for refine, I have added a deprecation warning.

I ran the tests again and the performance is better than before. Maybe I solved another bug: the off_center might have been subtracted one time too much, previously. But I am not sure of the origin of this difference. It is for sure much better at low noise values.

refine_trackpy_tests_refactored

@caspervdw
Copy link
Member Author

The test should be fixed now, the resulting tracking errors are now lower, agreeing much better (within 10%) with the theoretical ones.

@caspervdw
Copy link
Member Author

Could anyone check this and merge? The amount of code that is changed is substantial, but also fairly straightforward. I think that this increase of accuracy should be released asap so that people can make use of it.

Potentially as a v0.4, not v0.3.1? What do you think? This PR will result in different refined coordinates.

@nkeim
Copy link
Contributor

nkeim commented Jul 6, 2016

I suspect that the "python" engine is used by only a small minority. There is zero downside to this PR except that it changes output. And putting out a release is a fair amount of work. So I vote to include it in 0.3.1. I would like to focus on #361 (and maybe #333) for v0.4.

@nkeim
Copy link
Contributor

nkeim commented Jul 6, 2016

I've looked at the code and am happy with it. If I had more time I would test this with my application (1D feature finding). But if there is a problem with that very rare use case, I will find it soon enough.

So I also want to merge if we are OK with this being in v0.3.1.

@danielballan
Copy link
Member

Yep, this is a bugfix and can go into v0.3.1. Merging!

@danielballan danielballan merged commit 1db5743 into soft-matter:master Jul 6, 2016
caspervdw added a commit to caspervdw/trackpy that referenced this pull request Jul 6, 2016
Because of the refine refactor in soft-matter#377, one iteratation is
the same as no iteration previously. Zero iterations is not
possible, because the center of mass is then undefined.
@caspervdw caspervdw mentioned this pull request Sep 29, 2016
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

Successfully merging this pull request may close these issues.

4 participants