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

ENH: Revise the implementation of FuzzyOverlap #2530

Merged
merged 5 commits into from
Apr 25, 2018

Conversation

oesteban
Copy link
Contributor

@oesteban oesteban commented Apr 6, 2018

  • Accept calculating overlap within an in_mask
  • Drop calculation of the difference image

- [x] Accept calculating overlap within an ``in_mask``
- [x] Drop calculation of the difference image
Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Not sure if this is ready for review, but had a look through and saw a few things that look a little redundant. I didn't thoroughly check the math for consistency between the old and new versions. That might be easier if you could make a few comments on your intended differences. (Whenever you're ready for review.)

self._results['jaccard'] = float(np.sum(weights * jaccards))
self._results['dice'] = float(np.sum(weights * dices))
self._results['class_fji'] = [
float(v) for v in jaccards.astype(float).tolist()]
Copy link
Member

Choose a reason for hiding this comment

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

jaccards.astype(float).tolist() seems like it should be fine? I think this and the next comprehension are redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is me over-worrying about output traits. In the past I've seen that ndarray.astype(float).tolist() returned a list of numpy floats that traits didn't like. I'll check if this is not necessary anymore.

Copy link
Member

Choose a reason for hiding this comment

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

Ah. If that's the case, then [float(v) for v in jaccards] is another option. There shouldn't be any change to values or iteration by dropping astype(float) or tolist().

if self.inputs.weighting != "none":
volumes = np.sum((refdata + tstdata) > 0, axis=1).reshape((-1, ncomp))
weights = 1.0 / np.array(volumes)
Copy link
Member

Choose a reason for hiding this comment

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

volumes is already an array.

numerators = np.atleast_2d(
np.minimum(refdata, tstdata).reshape((-1, ncomp)))
denominators = np.atleast_2d(
np.maximum(refdata, tstdata).reshape((-1, ncomp)))
Copy link
Member

Choose a reason for hiding this comment

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

These shapes look guaranteed to be 2D, already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If only one item in the input lists are passed, numpy squeezes the redundant dimension. This was necessary for this interface to work.

Copy link
Member

Choose a reason for hiding this comment

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

Well that's surprising and annoying. Okay.

nb.load(self.inputs.in_ref[0]).header),
self.inputs.out_file)
# Fill-in the results object
self._results['jaccard'] = float(np.sum(weights * jaccards))
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just use the dot product here?

self._results['jaccard'] = weights.dot(jaccards)

@effigies
Copy link
Member

Do you want to target this for 1.0.3?

@oesteban
Copy link
Contributor Author

Sure, let's do that 👍

@effigies effigies added this to the 1.0.3 milestone Apr 17, 2018
@effigies
Copy link
Member

@oesteban What's the status of this one?

@oesteban
Copy link
Contributor Author

Unless we want to add regression tests (which would be advisable), this would be good to go.

@oesteban
Copy link
Contributor Author

I see we have three tissue probability maps within the test that that could be used here.

@oesteban
Copy link
Contributor Author

Actually, hold on. I'll add the tests.

@effigies effigies merged commit 9c237fc into nipy:master Apr 25, 2018
@oesteban oesteban deleted the enh/add-masks-overlap branch April 25, 2018 17:47
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.

2 participants