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

NF: Find the closest vertex on a sphere for an input vector. #483

Merged
merged 4 commits into from Dec 2, 2014

Conversation

arokem
Copy link
Contributor

@arokem arokem commented Nov 26, 2014

This is useful for both #460 and #419 so needs to take precedence. It's not quite done yet, though. Will hopefully have a chance to finish this later today.

vertex (in angle).
"""
ang = np.arccos(np.dot(self.vertices, xyz))
ang = np.min(np.vstack([ang, np.pi - ang]), 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been using something like the following for this:

cos_sim = abs(np.dot(self.vertices, xyz))
return np.argmax(cos_sim)

If this is being done repeatedly it might be worth building a KDtree for it.

@arokem arokem changed the title WIP: Find the closest vertex on a sphere for an input vector. NF: Find the closest vertex on a sphere for an input vector. Nov 26, 2014
@arokem
Copy link
Contributor Author

arokem commented Nov 26, 2014

Thanks for the comments and suggestions.

How about the following solution? Have each of these classes have it's own (just very slightly different) implementation of this function, taking or not taking the absolute value, as needed.

I have also added a test to demonstrate that scaling by l2norm is not necessary, as long as you are not interested in the angle, but rather just in finding the index of the minimal.

@arokem
Copy link
Contributor Author

arokem commented Dec 2, 2014

Just rebased on master. Could someone take a look and merge this? It's a no-brainer (if I may say so myself).

@Garyfallidis
Copy link
Contributor

Will have a look first thing tomorrow morning. Sorry for the delay.

@Garyfallidis
Copy link
Contributor

Hi @arokem. The tests are a bit too tight because you only test finding an already existing point to itself. I would like to see in the future a test showing that if you add a new point that is equal to old point + tiny random shift you will still get the same point. But because this is a trivial problem and this PR is needed for other more complex PRs I believe is pointless to wait right now for extra testing on this and will go ahead and merge. Inf+!!!

Garyfallidis added a commit that referenced this pull request Dec 2, 2014
NF: Find the closest vertex on a sphere for an input vector.
@Garyfallidis Garyfallidis merged commit 0fbe1ee into dipy:master Dec 2, 2014
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.

None yet

4 participants