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

Improve handling of non-integer sizes in demes models. #930

Merged
merged 1 commit into from Apr 22, 2022

Conversation

molpopgen
Copy link
Owner

@molpopgen molpopgen commented Apr 22, 2022

See issue #929

@molpopgen
Copy link
Owner Author

molpopgen commented Apr 22, 2022

@apragsdale -- one issue here is that np.rint is (or claims to be) an "unbiased" round, meaning that round-to-even is the default. So, 100.5 -> 100, yet 101.5 -> 102. That behavior could cause problems.

@molpopgen molpopgen force-pushed the non_integer_times_in_demes_models branch from 78efdc9 to f80e5c8 Compare April 22, 2022 18:31
@@ -517,22 +517,19 @@ def _process_epoch(
if e.start_time != math.inf:
assert size_history.deme_exists_at(idmap[deme_id], when + 1)

start_size = int(np.rint(e.start_size))
Copy link
Owner Author

Choose a reason for hiding this comment

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

Here is a good place to ensure that:

  • end_size > start_size (???)
  • the duration is > 0 when converted to integer?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to check that end_size > start_size?

But yes, we need to check that duration is 1 generation or greater, I agree.

Copy link
Owner Author

Choose a reason for hiding this comment

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

My mistake -- I meant start/end time, meaning epoch length > 0. We'll take care of that in another PR so that the git history reflects both this change and the check on epoch lengths.

Copy link
Collaborator

@apragsdale apragsdale left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me. Do we want to handle positive epoch duration here as well?

@@ -517,22 +517,19 @@ def _process_epoch(
if e.start_time != math.inf:
assert size_history.deme_exists_at(idmap[deme_id], when + 1)

start_size = int(np.rint(e.start_size))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to check that end_size > start_size?

But yes, we need to check that duration is 1 generation or greater, I agree.

@molpopgen
Copy link
Owner Author

This looks reasonable to me. Do we want to handle positive epoch duration here as well?

Let's do that separately. Are you worried about the round to even behavior?

@molpopgen molpopgen force-pushed the non_integer_times_in_demes_models branch 2 times, most recently from 9873217 to 2c5a5ea Compare April 22, 2022 20:07
@molpopgen molpopgen changed the title Improve handling of non-integer times in demes models. Improve handling of non-integer sizes in demes models. Apr 22, 2022
@apragsdale
Copy link
Collaborator

I’m not specifically concerned by the round the even behavior. I could come up with some specific scenario where it matters, like if all integer times are then scaled by 1/2. In practice, it’s not that likely to be an issue.

* Add tests based on examples from GitHub issue #929
* Apply int(np.rint(X)) for all X in [epoch.start_size, epoch.end_size]

Fixes #929
@molpopgen molpopgen force-pushed the non_integer_times_in_demes_models branch from 2c5a5ea to 595b0cf Compare April 22, 2022 20:18
@molpopgen molpopgen merged commit 560c1da into dev Apr 22, 2022
@molpopgen molpopgen deleted the non_integer_times_in_demes_models branch April 22, 2022 20:44
@molpopgen molpopgen mentioned this pull request May 23, 2022
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

2 participants