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

'nearest_neighbour' method should not return the same particle #978

Open
rieder opened this issue Sep 1, 2023 · 5 comments
Open

'nearest_neighbour' method should not return the same particle #978

rieder opened this issue Sep 1, 2023 · 5 comments

Comments

@rieder
Copy link
Member

rieder commented Sep 1, 2023

Currently, the nearest_neighbour method can result in a particle finding itself as its nearest neighbour when checking against another particle set that contains (some of) the same particles:

from amuse.ic.plummer import new_plummer_model
p = new_plummer_model(10)
q = p.copy()
r = q.nearest_neighbour(p)
print(r.key == p.key)

returns

[ True,  True,  True,  True,  True,  True,  True,  True,  True,  True]

There should be an option (probably enabled by default) to ensure a particle with the same key is ignored.

@rieder
Copy link
Member Author

rieder commented Sep 1, 2023

Note that this is not the case when finding nearest neighbours in the same set:

r = q.nearest_neighbour()
print(r.key == p.key)

returns

[False, False, False, False, False, False, False, False, False, False]

Copy link

stale bot commented Oct 31, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 28 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issues that have been around for a while without updates label Oct 31, 2023
@stale stale bot closed this as completed Nov 29, 2023
@rieder rieder added feature request and removed stale Issues that have been around for a while without updates labels Nov 29, 2023
@rieder rieder reopened this Nov 29, 2023
@LourensVeen
Copy link
Collaborator

This sounds like an object/value issue. If particles are values, then two different Particle objects with the same properties should be considered to be identical. (As an example, calendar dates are values because November 29th is November 29th regardless of how many variables you have containing November 29th.) If Particles are objects, then two different Particle objects with the same properties are still different things. (People are objects, because two people with the same date of birth, name, residence, etc. are still two different people.) Objects have an identity independent of their properties, while values haven't.

It seems like Particles are considered objects here, and that makes sense to me actually. As a result, if you copy the particles, you get two different particles in the same place, and since a neighbour is a different particle that is close by, it gets returned. I'd say that that is correct, even if it isn't what you want.

The question is, what were you trying to do?

@rieder
Copy link
Member Author

rieder commented Nov 29, 2023

Maybe in some sense it's expected, but let me give another example.
Say I have two lists of people:

  • one list containing all people in a neighbourhood
  • one list containing a few people of interest

Now, I want to see who in the bigger list is the closest neighbour to each of the people in the smaller list.
I can't remove them from that list (since they might live close to one of the others), but as-is, the algorithm would return themselves as their closest neighbour, which is not desired.
This is analogous to what I was attempting here.

@rieder
Copy link
Member Author

rieder commented Nov 29, 2023

It would be good to at least have an option to check if the nearest neighbour is not (a copy of) the object itself.

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

No branches or pull requests

2 participants