Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- women_possibly_fertile_until = 45
- neighborhood = []
- for sampled_hh in households:
- print 'new sample ################################'
- print '###########################################'
- print 'sampled_hh', sampled_hh
- ## This time lets start with kids first
- num_child = sampled_hh[3]
- num_dep_child = sampled_hh[4]
- num_non_dep_child = num_child - num_dep_child
- num_dep_student = 0
- if num_dep_child > 0:
- for i in range(num_dep_child):
- if np.random.random() < percentage_of_dependent_students:
- num_dep_student += 1
- num_dep_child -= 1
- print "num_dep_child", num_dep_child, "num_dep_student", num_dep_student, "num_non_dep_child", num_non_dep_child
- dep_child_age_range_tuple = (0,14)
- dep_child_age_range = range(dep_child_age_range_tuple[0], dep_child_age_range_tuple[1] + 1)
- dep_student_age_range_tuple = (15,24)
- dep_student_age_range = range(dep_student_age_range_tuple[0], dep_student_age_range_tuple[1] + 1)
- non_dep_child_age_range_tuple = (15,100-15)
- non_dep_child_age_range = range(non_dep_child_age_range_tuple[0], non_dep_child_age_range_tuple[1] + 1)
- mom_age_range_tuple = (15,100)
- first_sampled_kids = []
- ## Here I am creating a maximum age range for mother based on what kind of kid she can have
- ## be careful and thoughtful, this should be if elif statement
- if num_dep_child > 0:
- mom_age_range_tuple = (16 + dep_child_age_range_tuple[0], women_possibly_fertile_until + dep_child_age_range_tuple[1])
- elif num_dep_student > 0:
- mom_age_range_tuple = (16 + dep_student_age_range_tuple[0], women_possibly_fertile_until + dep_student_age_range_tuple[1])
- elif num_non_dep_child > 0:
- mom_age_range_tuple = (16 + non_dep_child_age_range_tuple[0], 100)
- ## Now I am sampling the first kids based on the type that is possible for this family
- ## these should be if statements rather than if elif
- if num_dep_child > 0:
- first_sampled_dep_childs = []
- for c in range(num_dep_child):
- first_sampled_dep_child = sample_children_age_by_children_type('dep_child', num_kids=1)[0]
- while True:
- if first_sampled_dep_child in molded_age_distribution['one_fam_one_parent_with_child']:
- if molded_age_distribution['one_fam_one_parent_with_child'][first_sampled_dep_child] > 0:
- print "found allowed dep kid from the mold", first_sampled_dep_child
- break
- first_sampled_dep_child = sample_children_age_by_children_type('dep_child', num_kids=1)[0]
- first_sampled_dep_childs.append(first_sampled_dep_child)
- print "found all the kids from the mold", first_sampled_dep_childs
- first_sampled_kids.extend(first_sampled_dep_childs)
- if num_dep_student > 0:
- first_sampled_dep_students = []
- for c in range(num_dep_student):
- first_sampled_dep_student = sample_children_age_by_children_type('dep_student', num_kids=1)[0]
- while True:
- if first_sampled_dep_student in molded_age_distribution['one_fam_one_parent_with_child']:
- if molded_age_distribution['one_fam_one_parent_with_child'][first_sampled_dep_student] > 0:
- break
- first_sampled_dep_student = sample_children_age_by_children_type('dep_student', num_kids=1)[0]
- first_sampled_dep_students.append(first_sampled_dep_student)
- first_sampled_kids.extend(first_sampled_dep_students)
- if num_non_dep_child > 0:
- first_sampled_non_dep_childs = sample_children_age_by_children_type('non_dep_child', num_kids=num_non_dep_child)
- first_sampled_kids.extend(first_sampled_non_dep_childs)
- print 'first_sampled_kids', first_sampled_kids
- oldest_kid = max(first_sampled_kids)
- youngest_kid = min(first_sampled_kids)
- sampled_mom_age = sample_moms_age_based_on_kids_age(oldest_kid)
- ## Sometimes we ge t asampled mom age that is more than 100
- if sampled_mom_age > 100:
- sampled_mom_age = 100
- print "sampled_mom_age", sampled_mom_age
- while True:
- if sampled_mom_age < women_possibly_fertile_until + youngest_kid + 3:
- break
- else:
- first_sampled_kids = []
- if num_dep_child > 0:
- first_sampled_dep_childs = []
- for c in range(num_dep_child):
- first_sampled_dep_child = sample_children_age_by_children_type('dep_child', num_kids=1)[0]
- while True:
- if first_sampled_dep_child in molded_age_distribution['one_fam_one_parent_with_child']:
- if molded_age_distribution['one_fam_one_parent_with_child'][first_sampled_dep_child] > 0:
- print "found allowed dep kid from the mold", first_sampled_dep_child
- break
- first_sampled_dep_child = sample_children_age_by_children_type('dep_child', num_kids=1)[0]
- first_sampled_dep_childs.append(first_sampled_dep_child)
- print "found all the kids from the mold", first_sampled_dep_childs
- first_sampled_kids.extend(first_sampled_dep_childs)
- if num_dep_student > 0:
- first_sampled_dep_students = []
- for c in range(num_dep_student):
- first_sampled_dep_student = sample_children_age_by_children_type('dep_student', num_kids=1)[0]
- while True:
- if first_sampled_dep_student in molded_age_distribution['one_fam_one_parent_with_child']:
- if molded_age_distribution['one_fam_one_parent_with_child'][first_sampled_dep_student] > 0:
- break
- first_sampled_dep_student = sample_children_age_by_children_type('dep_student', num_kids=1)[0]
- first_sampled_dep_students.append(first_sampled_dep_student)
- first_sampled_kids.extend(first_sampled_dep_students)
- if num_non_dep_child > 0:
- first_sampled_non_dep_childs = sample_children_age_by_children_type('non_dep_child', num_kids=num_non_dep_child)
- first_sampled_kids.extend(first_sampled_non_dep_childs)
- print 'first_sampled_kids', first_sampled_kids
- oldest_kid = max(first_sampled_kids)
- youngest_kid = min(first_sampled_kids)
- ## Sometimes we get asampled mom age that is more than 100
- if sampled_mom_age > 100:
- sampled_mom_age = 100
- sampled_mom_age = sample_moms_age_based_on_kids_age(oldest_kid)
- print "sampled_mom_age", sampled_mom_age
- print "chosen anchor mom age",sampled_mom_age
- # print "mom age range tuple", mom_age_range_tuple
- # anchored_mom_age_range_tuple = max(mom_age_range_tuple[0], sampled_mom_age - 2), min(mom_age_range_tuple[1], sampled_mom_age + 2)
- # print 'anchored_mom_age_range_tuple', anchored_mom_age_range_tuple
- # anchored_mom_age_range = range(max(mom_age_range_tuple[0],anchored_mom_age_range_tuple[0]),min(mom_age_range_tuple[1],anchored_mom_age_range_tuple[1])+1)
- sampled_anchored_mom_age = sampled_mom_age #get_mom_age_based_based_on_num_kids(num_child,allowed_age_range=anchored_mom_age_range)
- print "sampled_anchored_mom_age", sampled_anchored_mom_age
- final_sampled_kids = []
- if num_dep_child > 0:
- sampled_dep_childs = get_kids_based_on_mom_age(sampled_anchored_mom_age, num_dep_child, allowed_kid_age_range=dep_child_age_range)
- #sampled_dep_childs_with_noise = []
- for age in sampled_dep_childs:
- #sampled_noise = sample_from_a_dict(noise)[0]
- #age_with_noise = age + sampled_noise
- #sampled_dep_childs_with_noise.append(age_with_noise)
- if age in children_age_by_children_type_australia['dep_child']:
- children_age_by_children_type_australia['dep_child'][age] -= 1
- final_sampled_kids.extend(sampled_dep_childs)
- if num_dep_student > 0:
- sampled_dep_students = get_kids_based_on_mom_age(sampled_anchored_mom_age, num_dep_student, allowed_kid_age_range=dep_student_age_range)
- for age in sampled_dep_students:
- children_age_by_children_type_australia['dep_student'][age] -= 1
- final_sampled_kids.extend(sampled_dep_students)
- if num_non_dep_child > 0:
- sampled_non_dep_childs = get_kids_based_on_mom_age(sampled_anchored_mom_age, num_non_dep_child, allowed_kid_age_range=non_dep_child_age_range)
- for age in sampled_non_dep_childs:
- children_age_by_children_type_australia['non_dep_child'][age] -= 1
- final_sampled_kids.extend(sampled_non_dep_childs)
- print 'final_sampled_kids', final_sampled_kids
- ## check if the sampled_mom was the lone person ref person male or female
- if np.random.random() < probability_male_lone_parent_in_primary_family:
- gender = 'male'
- else:
- gender = 'female'
- if gender == 'male':
- ## we need to sample a father based on the anchored moms age
- sampled_age_gap_tuple = sample_from_a_dict(age_gap_distribution)
- print 'sampled_age_gap_tuple', sampled_age_gap_tuple
- ## I am adding a plus one and minus one in the range in case we have a range of [0,0] from the age gap tuple
- male_lone_parent_age_range_tuple = max(16, sampled_anchored_mom_age+ sampled_age_gap_tuple[0]) - 1, min(100, sampled_anchored_mom_age + sampled_age_gap_tuple[1] + 1) + 1
- male_lone_parent_age_range_tuple = check_and_correct_for_extreme_age_ranges(male_lone_parent_age_range_tuple)
- male_lone_parent_age_range = range(male_lone_parent_age_range_tuple[0], male_lone_parent_age_range_tuple[1] + 1)
- print "male lone parent age_rage", male_lone_parent_age_range
- allowed_male_lone_parent_tuples = product(['male'], male_lone_parent_age_range)
- sampled_final_lone_parent_age = sample_from_a_dict(ref_person_lone_parent_age_count_by_sex_flattened, allowed_keys=allowed_male_lone_parent_tuples)[1]
- print 'sampled_final_lone_parent_age', sampled_final_lone_parent_age
- elif gender == 'female':
- female_lone_parent_age_range_tuple = (max(15,sampled_anchored_mom_age - 1), min(100, sampled_anchored_mom_age + 1))
- female_lone_parent_age_range_tuple = check_and_correct_for_extreme_age_ranges(female_lone_parent_age_range_tuple)
- female_lone_parent_age_range = range(female_lone_parent_age_range_tuple[0], female_lone_parent_age_range_tuple[1] + 1)
- allowed_female_lone_parent_tuples = product(['female'], female_lone_parent_age_range)
- #print list(allowed_female_lone_parent_tuples)
- sampled_final_lone_parent_age = sample_from_a_dict(ref_person_lone_parent_age_count_by_sex_flattened, allowed_keys=allowed_female_lone_parent_tuples)[1]
- print 'sampled_final_lone_parent_age', sampled_final_lone_parent_age
- household = []
- household.append(sampled_final_lone_parent_age)
- household.extend(final_sampled_kids)
- for age in household:
- if age in molded_age_distribution['one_fam_one_parent_with_child'] and molded_age_distribution['one_fam_one_parent_with_child'][age] > 0:
- molded_age_distribution['one_fam_one_parent_with_child'][age] -= 1
- print 'final household', household
- print
- print
- neighborhood.append(household)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement