Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- #
- # Simulation of coincidental deaths in vaccination.
- #
- # Code4food at lihkg
- import random
- import sys
- # Approx population of USA
- POPULATION=328000000
- # Approx yearly deaths in USA due to heart disease and stroke.
- SUDDEN_DEATHS=800000
- # As of 5/30 in at least one does in USA is 167,733,972
- TOTAL_DOSES=167000000
- # Days of vaccination, assume same daily rate.
- N_DAYS=90
- def main():
- scale = 0.1 # my computer is too slow for scale of 1.0 :-)
- p_sudden_death = float(SUDDEN_DEATHS) / POPULATION
- sample_population_size = int(POPULATION * scale)
- sample_population = list(range(sample_population_size))
- random.shuffle(sample_population)
- # choose the people who will die in this year suddenly
- # and pick the days they will die.
- n_sudden_deaths = int(sample_population_size * p_sudden_death)
- sudden_death_events = {}
- for s in sample_population[0:n_sudden_deaths]:
- sudden_death_events[s] = random.randint(1,365)
- n_sample_doses = int(TOTAL_DOSES * scale)
- # Spread out vaccinations in N_DAYS evenly.
- prev = 0
- daily_doses = []
- for d in range(N_DAYS):
- current = int(float(d + 1) / N_DAYS * n_sample_doses)
- daily_doses.append(current - prev)
- prev = current
- # Simulate vaccination in N days.
- count = {}
- cursor = 0
- random.shuffle(sample_population)
- for day, doses in enumerate(daily_doses, start=1):
- # simulate n doses and ingore people already dead.
- for i in range(doses):
- death_day = -1
- # Loop exits when death day is at or after today.
- while death_day < day:
- s = sample_population[cursor]
- death_day = sudden_death_events.get(s, 9999)
- cursor = cursor + 1
- # record if the person dies within 7 days of vaccination。
- if death_day < day + 7:
- days_between = death_day - day
- count[days_between] = count.get(days_between,0) + 1
- print count
- print "sum = %d" % sum(count.values())
- return 0
- if __name__ == "__main__":
- sys.exit(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement