Пример #1
0
def generate_donors(d, patients, weight_dists):
    donors = []
    d_id = 0
    for patient in patients:
        n_donors = patient.draw_number_of_donors()
        for i in range(n_donors):
            if random.random() < 0.5:
                sex = "F"
                age_d = d["donor_age_dist_f"]
            else:
                sex = "M"
                age_d = d["donor_age_dist_m"]
            age_dist = DiscreteDist(age_d["ages"], age_d["probs"])
            age = age_dist.sample1()

            bt_d = d["donor_bt_dist"]
            bt_dist = DiscreteDist(bt_d["bts"], bt_d["probs"])
            bt = bt_dist.sample1()               
            weight = weight_dists.draw_weight(sex, age)

            donor = Donor(sex, age, bt, weight, d_id, patient)
            donors.append(donor)
            d_id += 1

    return donors
Пример #2
0
def generate_patients(d, n_patients, weight_dists):
    patients = []

    for p_id in range(n_patients):
        if rand() < d["prob_cystic_fibrosis"]:
            disease = "CF"
            dd = d["cystic_f_dists"]
        else:
            disease = "PH"
            dd = d["pulm_h_dists"]

        if rand() < dd["prob_female"]:
            gender = "F"
            age_d = dd["age_dist_f"]
        else:
            gender = "M"
            age_d = dd["age_dist_m"]

        age_dist = DiscreteDist(age_d["age_bands"], age_d["probs"])
        age_band = age_dist.sample1()
        age = randint(age_band["min"], age_band["max"])

        bt_d = dd["bt_dist"]
        bt_dist = DiscreteDist(bt_d["bts"], bt_d["probs"])
        bt = bt_dist.sample1()

        weight = weight_dists.draw_weight(gender, age)

        patient = Patient(disease, gender, age, bt, weight, p_id)
        patients.append(patient)
    return patients
Пример #3
0
 def __init__(self, weight_dist_data):
     self.weight_dist_data = weight_dist_data
     for w_dist in weight_dist_data:
         w_dist["wt_dist"] = DiscreteDist(w_dist["weight_bands"],
                                w_dist["cum_probs"],
                                are_cumulative=True)