def create_person_callback(mcw, age, gender): """ This callback is required by dtk_nodedemographic during population initialization. It can be named anything as long as it is registered via the appropriate callback. It takes 3 parameters: monte-carlo weight, age, and sex. """ if random.random() <= 0.23: age = random.randrange(0, ADULT_CHILD_AGE_THRESHOLD) else: age = random.randrange(ADULT_CHILD_AGE_THRESHOLD, 36500) # print("Creating {}.".format("ADULT" if age >= ADULT_CHILD_AGE_THRESHOLD else "CHILD")) # TODO: move some of this to core. global human_pop # make sure Python knows to use module-level variable human_pop #global timestep global nursery person = {} person["mcw"] = mcw person["age"] = age / 365 person["sex"] = gender new_id = gi.create(gender, age, mcw) person["id"] = new_id human_pop.append(person) if age == 0: month_step = int(timestep / 30.0) #print( "Made a baby on timestep {0}/month {1}.".format( str( timestep ), str( month_step ) ) ) if month_step not in nursery: nursery[month_step] = (0, 0) boys = nursery[month_step][0] girls = nursery[month_step][1] if gender == 0: boys += mcw else: girls += mcw nursery[month_step] = (boys, girls)
def perf_bench(): sillypop = [] for _ in range(1000): sillypop.append( gi.create( ( 1, 1.0, 1.0 ) ) ) start_time = timeit.default_timer() for t in range(7300): for human in sillypop: gi.update( human ) elapsed = timeit.default_timer() - start_time print( str( elapsed ) )
def create_population(self, population_count, age_gaussian_mean=20, age_gaussian_sigma=7, probability_male=0.5): total_population = 0 monte_carlo_weight = 1.0 while total_population < population_count: sex_draw = random.random() current_sex = 0 if sex_draw < probability_male: current_sex = 1 pass current_age = int( np.random.normal(loc=age_gaussian_mean, scale=age_gaussian_sigma) * DAYS_YEAR) # TODO: It would be nice if I didn't have to talk to numpy here human = dgi.create((current_sex, current_age, monte_carlo_weight)) self.humans.append(human) total_population += 1
def create_person_callback(self, mcw, age, gender): self.humans.append(dgi.create((gender, age, mcw)))
import dtk_generic_intrahost as dgi people = [] # First, make 100 people. Half men half women, age all 20 for x in range(100): sex = x%2 person = dgi.create((sex, 7300, 1.0)) people.append(person) pass print("Created people.") # Now, touch each one with an infection before we spin time for victim in people: dgi.force_infect(victim) pass print("Forced infections.") for x in range(25): for person in people: dgi.update(person) pass pass incubating = 0 infected = 0 for person in people: if dgi.is_incubating(person): incubating += 1 pass