def run_model(): storage.write_table(table_name = 'households', table_data = household_data) households = HouseholdCharacteristicDataset(in_storage=storage, in_table_name='households') model = HouseholdTransitionModel() model.run(year=2000, household_set=households, control_totals=hct_set, characteristics=hc_set) income = households.get_attribute("income") age = households.get_attribute("age_of_head") idx1 = where(income <= 1000)[0] idx2 = where(logical_and(income <= 5000, income > 1000))[0] idx3 = where(logical_and(income <= 10000, income > 5000))[0] idx4 = where(income > 10000)[0] results = array([age[idx1].mean(), age[idx2].mean(), age[idx3].mean(), age[idx4].mean()]) print results return results
def run_model(): storage.write_table(table_name='households', table_data=household_data) households = HouseholdCharacteristicDataset( in_storage=storage, in_table_name='households') model = HouseholdTransitionModel() model.run(year=2000, household_set=households, control_totals=hct_set, characteristics=hc_set) income = households.get_attribute("income") age = households.get_attribute("age_of_head") idx1 = where(income <= 1000)[0] idx2 = where(logical_and(income <= 5000, income > 1000))[0] idx3 = where(logical_and(income <= 10000, income > 5000))[0] idx4 = where(income > 10000)[0] results = array([ age[idx1].mean(), age[idx2].mean(), age[idx3].mean(), age[idx4].mean() ]) print results return results
def run(self, year, household_set, person_set, control_totals, characteristics, resources=None): self.person_set = person_set return USHouseholdTransitionModel.run(self, year, household_set, control_totals, characteristics, resources=resources)
def run_HTM(niter): nhhs = 5000 ngroups = 4 nhhsg = int(nhhs/ngroups) nhhslg = nhhs-(ngroups-1)*nhhsg should_nhhs = nhhs-2000 storage = StorageFactory().get_storage('dict_storage') hc_set_table_name = 'hc_set' storage.write_table( table_name = hc_set_table_name, table_data = { 'characteristic': array(4*['income']+4*['age_of_head']), 'min':array([0,1001,5001, 10001, 0, 31, 41, 61]), 'max':array([1000, 5000, 10000,-1, 30, 40, 60, -1]) }, ) hct_set_table_name = 'hct_set' storage.write_table( table_name = hct_set_table_name, table_data = { 'year':array([2000]), 'total_number_of_households':array([should_nhhs]) }, ) households_table_name = 'households' storage.write_table( table_name = households_table_name, table_data = { 'age_of_head': array(nhhsg/2*[18]+(nhhsg-nhhsg/2)*[35] + nhhsg/2*[30] + (nhhsg-nhhsg/2)*[40] + nhhsg/2*[38] + (nhhsg-nhhsg/2)*[65] + nhhslg/2*[50] + (nhhslg-nhhslg/2)*[80] ), 'income': array(nhhsg*[500] + nhhsg*[2000] + nhhsg*[7000] + nhhslg*[15000] ), 'household_id':arange(nhhs)+1 }, ) hc_set = HouseholdCharacteristicDataset(in_storage=storage, in_table_name=hc_set_table_name) hct_set = ControlTotalDataset( in_storage = storage, in_table_name = hct_set_table_name, what = 'household', id_name = ['year'] ) logger.be_quiet() result = zeros((niter,4)) for iter in range(niter): households = HouseholdDataset(in_storage=storage, in_table_name=households_table_name) model = HouseholdTransitionModel() model.run(year=2000, household_set=households, control_totals=hct_set, characteristics=hc_set) income = households.get_attribute('income') age = households.get_attribute('age_of_head') idx1 = where(income <= 1000)[0] idx2 = where(logical_and(income <= 5000, income > 1000))[0] idx3 = where(logical_and(income <= 10000, income > 5000))[0] idx4 = where(income > 10000)[0] result[iter,:] = array([age[idx1].mean(), age[idx2].mean(), age[idx3].mean(), age[idx4].mean()]) return result
def run_HTM(niter): nhhs = 5000 ngroups = 4 nhhsg = int(nhhs / ngroups) nhhslg = nhhs - (ngroups - 1) * nhhsg should_nhhs = nhhs - 2000 storage = StorageFactory().get_storage('dict_storage') hc_set_table_name = 'hc_set' storage.write_table( table_name=hc_set_table_name, table_data={ 'characteristic': array(4 * ['income'] + 4 * ['age_of_head']), 'min': array([0, 1001, 5001, 10001, 0, 31, 41, 61]), 'max': array([1000, 5000, 10000, -1, 30, 40, 60, -1]) }, ) hct_set_table_name = 'hct_set' storage.write_table( table_name=hct_set_table_name, table_data={ 'year': array([2000]), 'total_number_of_households': array([should_nhhs]) }, ) households_table_name = 'households' storage.write_table( table_name=households_table_name, table_data={ 'age_of_head': array(nhhsg / 2 * [18] + (nhhsg - nhhsg / 2) * [35] + nhhsg / 2 * [30] + (nhhsg - nhhsg / 2) * [40] + nhhsg / 2 * [38] + (nhhsg - nhhsg / 2) * [65] + nhhslg / 2 * [50] + (nhhslg - nhhslg / 2) * [80]), 'income': array(nhhsg * [500] + nhhsg * [2000] + nhhsg * [7000] + nhhslg * [15000]), 'household_id': arange(nhhs) + 1 }, ) hc_set = HouseholdCharacteristicDataset(in_storage=storage, in_table_name=hc_set_table_name) hct_set = ControlTotalDataset(in_storage=storage, in_table_name=hct_set_table_name, what='household', id_name=['year']) logger.be_quiet() result = zeros((niter, 4)) for iter in range(niter): households = HouseholdDataset(in_storage=storage, in_table_name=households_table_name) model = HouseholdTransitionModel() model.run(year=2000, household_set=households, control_totals=hct_set, characteristics=hc_set) income = households.get_attribute('income') age = households.get_attribute('age_of_head') idx1 = where(income <= 1000)[0] idx2 = where(logical_and(income <= 5000, income > 1000))[0] idx3 = where(logical_and(income <= 10000, income > 5000))[0] idx4 = where(income > 10000)[0] result[iter, :] = array([ age[idx1].mean(), age[idx2].mean(), age[idx3].mean(), age[idx4].mean() ]) return result