-
Notifications
You must be signed in to change notification settings - Fork 33
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
Position sampling in Environments with holes. #100
Position sampling in Environments with holes. #100
Conversation
…lso now has a boolean flag that watches whether to force samplig method.
Thanks for the PR!! I left a couple of comments. Can you provide a description of what bug this fixes/functionality this provides, I'm a bit lost as to the purpose of the PR |
Hi ! Thanks. I could not find your comments but let me describe the purpose of the PR (I think in the process of submitting the PR, VisualCode Studio did not attach my description so it is empty somehow..)/
Thanks a lot !! |
ratinabox/Environment.py
Outdated
@@ -548,7 +548,7 @@ def plot_environment(self, | |||
|
|||
return fig, ax | |||
|
|||
def sample_positions(self, n=10, method="uniform_jitter"): | |||
def sample_positions(self, n=10, method="uniform_jitter",force_method=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reference this param in the doc string
ratinabox/utils.py
Outdated
scalar: area of the hole. | ||
""" | ||
x, y = zip(*hole) | ||
return round(0.5*np.abs(np.dot(x,np.roll(y,1))-np.dot(y,np.roll(x,1))),2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this formula come from? Also is it limited to holes with four points? By the way we already list shapely as a requirement so we could use shapely.Polygon.area
for this...just a thought
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting I've never heard of this formula before. Could you (a) either refer to it as the shoelace formula in the doc string or (b) use shapely.geometry.Polygon(hole).area
instead.
Also, clarify that isn't just 4-corner holes that works, its any sized holes. Finally, in the docstrng make sure you remember to clarify the intended shape of holes ((N, 2) for N >= 3 presumably). Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, excellent! I did not realize shapely was imported. This is the same formula that shapely uses: the formula to calculate the area of a polygon given the list of points considering connectedness across the list of points. So we do not this in utils.py.
Ok, nice! I took a better look. So basically, if there are holes in the Environment its area is accountably smaller so the "delta" (distance between uniform samples) is smaller too. This then uniformly scatters points but presumably lots of them fall in the holes which, when removed, brings the numbers to roughly what we want. I would recommend:
Did I understand correctly, and do you agree? |
Yes, you're correct. This PR basically accounts for the holes or illegal spaces in the environment and adjusts "delta" accordingly so that uniform samples fall into a more fine-grained sample-able space. If this is not accounted for, lots of sampled positions are then randomly sampled and the final location of these positions looks entirely random. I think you may be misguided by the amount of samples you typically use in your examples. In the simulations that I wish to run, I have many Poisson units that have receptive fields (e.g. 1000) and this number results in a lot of random positions scattered across the environment with little structure . But imagine these are, say, grid cells: such grid structure then is almost impossible to achieve if the sample_positions returns random positions. This is why I argue in favor of a force_method flag to allow for repeated positions (e.g. cells that have similar receptive field in terms of the receptive field center). Thus, regarding your recommended changes, I feel like it should be OK to allow sampling from the same because duplicates, while not ideal, do not necessarily have the same width or shape; these would only be regarding the center of a given receptive field. On the other hand, force_method = false would fall back to allow random sampling. Let me know your thoughts! I will update the PR with the changes considering the previous comments. |
…olygon area function. Included 'force_method' parameter reference in the docstring of sample_positions()
I see your point about the scale of the issue once N gets large but my issue is that I don't think many people will (ever) want sampled positions to have repeats in them. So we're adding a whole extra param potentially just for this one use case. Maybe instead, illegal positions could be resampled from the existing ones (like you propose) plus some random jitter of size delta / 2. This would actually just be one extra line. I'd be happy to go for this instead of randomly resampling the illegal points to save the extra kwarg. Something like:
Sorry to push back on this, just trying to prevent feature creep. |
I like your approach. I think this is a better approach in fact because if one samples at uniform and exceeds the available sampleable positions, a jittered sample at delta/2 is better than at delta (as it will look as if method was uniform_jittered when the user wanted uniform). Double check if the code makes sense to you, and let me know your thoughts! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look and these look good to me!
thanks for the PR Gaston! really appreciate the effort :)) |
No description provided.