ihmeuw / vivarium

A python microsimulation framework
http://www.healthdata.org
BSD 3-Clause "New" or "Revised" License
46 stars 15 forks source link

Possible Bug: is rate required to be a pd.Series in framework.utilities.rate_to_probability? #257

Open aflaxman opened 1 year ago

aflaxman commented 1 year ago

I tried using a float for a simple example and found that the rate variable uses rate[rate>250] pattern now:

https://github.com/ihmeuw/vivarium/blob/262c48bcbffb96e9e8496200bc990eec85baf6c0/src/vivarium/framework/utilities.py#L29

I would like to change this to np.clip(rate, -np.inf, 250.0), so that it works with scalars, but I thought I'd see if anyone sees a risk in this before making a PR.

collijk commented 1 year ago

Can you post your example? The safer option may be to coerce the scalar to a series

aflaxman commented 1 year ago

Here is a code snippet that shows where I ran into the issue

    def on_time_step(self, event):
        population = self.population_view.get(
            event.index, query='alive == "alive" and sex =="Female" and age >= 15 and age < 45'
        )
        had_children = self.randomness.filter_for_rate(population, (2.5/30/365) # FIXME: float does not work here

Here is a notebook that puts this in context. Cell 6 shows how this fails, and Cell 7 shows a simple work-around.