AllenDowney / ModSimPy

Text and supporting code for Modeling and Simulation in Python
https://allendowney.github.io/ModSimPy/
MIT License
823 stars 1.76k forks source link

fix immunized #89

Closed GianmarcoRasi closed 2 months ago

GianmarcoRasi commented 3 months ago

Multiply 'fraction' by the proportion of susceptible individual to be sure to subtract and add a value that does not exceeds the proportion of susceptible individials

AllenDowney commented 3 months ago

I see the issue you are addressing -- this function is error-prone if fraction exceeds s. But the intention is that fraction is the fraction of the population that is immunized, so the responsibility is on the caller to make sure the argument is sensible. I'm inclined to leave it as is. What do you think?

AllenDowney commented 3 months ago

BTW, ignore the failing test -- that has nothing to do with this PR.

GianmarcoRasi commented 3 months ago

Thank you for answering, and for asking about my opinion.

I think that sweeping over fraction would result in incorrect estimates of the count of overall infected individuals, since when s < fraction <= 1 the amount of susceptible individuals becomes negative. So, if we want to leave the function as it is then we should sweep between $0$ and the fraction of susceptible individuals s, not between $0$ and $1$.

However, leaving the code untouched would make it easier for a reader to internalize the concept (as it worked for me) even if the result is not 100% correct.