-
Notifications
You must be signed in to change notification settings - Fork 906
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
Add sample and choices to CellCollection #2536
Conversation
for more information, see https://pre-commit.ci
Performance benchmarks:
|
Awesome, thanks for working on this! Personally, since they are so similar, I would go for a single method (i.e. # Without replacement (equivalent to previous sample_random_cells)
cells = collection.random(k=10, replace=False)
# With replacement (equivalent to previous choices_random_cells)
cells = collection.random(k=10, replace=True) But curious what others find intuitive naming. |
I have been going back and forth on this and in the end decided to stick close to the naming in the random library. Note that this also makes it possible to fully shadow the arguments from both methods which is virtually impossible if we collapse it into a single method with a boolean. |
That's a fair point. In that case I would maybe suggest |
That is not true. We already have a |
I would say that’s because those are agents selected from a collection of cells. That warrant naming it that way. In the AgentSet we also name methods |
Ok, but than I prefer simply |
I think the |
I'll make up my mind and finalize it tomorrow. |
This is awesome! I had some nitpicky comments that I am not tied to at all. I am good with merging I think only issue is changing the |
Oh, just saw this PR after my comments in #2530 . It does indeed seems to work to use |
I had overlooked the cells property when I made this PR. I am now, like @Corvince, not sure whether we need to merge this. I prefer to keep the API simple. Accidentally, we still have @EwoutH what do you think? |
Co-authored-by: Corvince <[email protected]>
I agree it's more Pythonic to use built-ins. Good catch @Corvince. The fact that we didn't realize it for this long, does say something about the discoverability. I think we can cover it with good documentation, but definitely something we would want to highlight in example models and a future tutorial. I'm also good with deprecating/removing |
closing this as not needed as @Corvince pointed out. Should we add a deprecation warning to |
This adds 2 new methods to cell collection:
sample_random_cells
andchoices_random_cells
. These methods make it possible to sample cells with or without replacement from a cell collection. This closes #2530.Implementation-wise, the methods are CellCollection specific wrappers around
random.sample
andrandom.choices
. Note also that both methods return a list. A CellCollection cannot contain duplicates (it is, in essence, a fixed set). But both sampling and choices can return duplicates, so we cannot return a cell collection.The main use case for these methods is in conjunction with the
Agent.create_agents
. You can. now do