def ipf_config_run(db, synthesis_type, control_variables, dimensions, pumano,
                   tract, bg):
    dbc = db.cursor()
    # Creating objective joint distributions to match the resulting sunthetic populations against
    adjusting_pums_joint_distribution.create_joint_dist(
        db, synthesis_type, control_variables, dimensions, pumano, tract, bg)
    adjusting_pums_joint_distribution.adjust_weights(db, synthesis_type,
                                                     control_variables, pumano,
                                                     tract, bg)
    order_dummy = adjusting_pums_joint_distribution.create_aggregation_string(
        control_variables)
    dbc.execute(
        'select frequency from %s_%s_joint_dist where tract = %s and bg = %s order by %s'
        % (synthesis_type, pumano, tract, bg, order_dummy))
    objective_frequency = numpy.asarray(dbc.fetchall())
    # Creating the joint distributions corrected for Zero-cell and Zero-marginal problems
    # Example puma x composite_type adjustment for the synthesis type obtained as a parameter
    adjusting_pums_joint_distribution.create_joint_dist(
        db, synthesis_type, control_variables, dimensions, pumano, tract, bg)
    adjusting_pums_joint_distribution.create_adjusted_frequencies(
        db, synthesis_type, control_variables, pumano, tract, bg)
    adjusting_pums_joint_distribution.adjust_weights(db, synthesis_type,
                                                     control_variables, pumano,
                                                     tract, bg)
    dbc.execute(
        'select frequency from %s_%s_joint_dist where tract = %s and bg = %s order by %s'
        % (synthesis_type, pumano, tract, bg, order_dummy))
    estimated_constraint = numpy.asarray(dbc.fetchall())
    return objective_frequency, estimated_constraint
Esempio n. 2
0
def ipf_config_run (db, synthesis_type, control_variables, dimensions, pumano, tract, bg):
    dbc = db.cursor()
# Creating objective joint distributions to match the resulting sunthetic populations against
    adjusting_pums_joint_distribution.create_joint_dist(db, synthesis_type, control_variables, dimensions, pumano, tract, bg)
    adjusting_pums_joint_distribution.adjust_weights(db, synthesis_type, control_variables, pumano, tract, bg)
    order_dummy = adjusting_pums_joint_distribution.create_aggregation_string(control_variables)
    dbc.execute('select frequency from %s_%s_joint_dist where tract = %s and bg = %s order by %s'%(synthesis_type, pumano, tract, bg, order_dummy))
    objective_frequency = numpy.asarray(dbc.fetchall())
# Creating the joint distributions corrected for Zero-cell and Zero-marginal problems
# Example puma x composite_type adjustment for the synthesis type obtained as a parameter
    adjusting_pums_joint_distribution.create_joint_dist(db, synthesis_type, control_variables, dimensions, pumano, tract, bg)
    adjusting_pums_joint_distribution.create_adjusted_frequencies(db, synthesis_type, control_variables, pumano, tract, bg)
    adjusting_pums_joint_distribution.adjust_weights(db, synthesis_type, control_variables, pumano, tract, bg)
    dbc.execute('select frequency from %s_%s_joint_dist where tract = %s and bg = %s order by %s'%(synthesis_type, pumano, tract, bg, order_dummy))
    estimated_constraint = numpy.asarray(dbc.fetchall())
    return objective_frequency, estimated_constraint
def prepare_data(db):
#    Processes/ methods to be called at the beginning of the pop_synthesis process 
    dbc = db.cursor()

# Identifying the number of housing units to build the Master Matrix
    dbc.execute('select * from housing_pums')
    housing_units = dbc.rowcount
    ti = time.clock()
# Identifying the control variables for the households, gq's, and persons
    hhld_control_variables = adjusting_pums_joint_distribution.choose_control_variables(db, 'hhld')
    gq_control_variables = adjusting_pums_joint_distribution.choose_control_variables(db, 'gq')
    person_control_variables = adjusting_pums_joint_distribution.choose_control_variables(db, 'person')

# Identifying the number of categories within each control variable for the households, gq's, and persons
    hhld_dimensions = numpy.asarray(adjusting_pums_joint_distribution.create_dimensions(db, 'hhld', hhld_control_variables))
    gq_dimensions = numpy.asarray(adjusting_pums_joint_distribution.create_dimensions(db, 'gq', gq_control_variables))
    person_dimensions = numpy.asarray(adjusting_pums_joint_distribution.create_dimensions(db, 'person', person_control_variables))
        
    print 'Dimensions and Control Variables created in %.4f' %(time.clock()-ti)
    ti = time.clock()
    
    update_string = adjusting_pums_joint_distribution.create_update_string(db, hhld_control_variables, hhld_dimensions)
    adjusting_pums_joint_distribution.add_unique_id(db, 'hhld', update_string)
    update_string = adjusting_pums_joint_distribution.create_update_string(db, gq_control_variables, gq_dimensions)
    adjusting_pums_joint_distribution.add_unique_id(db, 'gq', update_string)
    update_string = adjusting_pums_joint_distribution.create_update_string(db, person_control_variables, person_dimensions)
    adjusting_pums_joint_distribution.add_unique_id(db, 'person', update_string)
    
    print 'Uniqueid\'s created in %.4f' %(time.clock()-ti)
    ti = time.clock()
    
# Populating the Master Matrix	
    populated_matrix = psuedo_sparse_matrix.populate_master_matrix(db, 0, housing_units, hhld_dimensions, 
                                                                                               gq_dimensions, person_dimensions)
    print 'Frequency Matrix Populated in %.4f' %(time.clock()-ti)
    ti = time.clock()

# Sparse representation of the Master Matrix    
    ps_sp_matrix = psuedo_sparse_matrix.psuedo_sparse_matrix(db, populated_matrix, 0)
    print 'Psuedo Sparse Representation of the Frequency Matrix created in %.4f' %(time.clock()-ti)
    ti = time.clock()
#______________________________________________________________________
#Creating Index Matrix
    index_matrix = psuedo_sparse_matrix.generate_index_matrix(db, 0)
    print 'Index matrix created in %.4f' %(time.clock()-ti)
    ti = time.clock()
    dbc.close()
#______________________________________________________________________
# creating synthetic_population tables in MySQL
    drawing_households.create_synthetic_attribute_tables(db)

# Total PUMS Sample x composite_type adjustment for hhld    
    adjusting_pums_joint_distribution.create_joint_dist(db, 'hhld', hhld_control_variables, hhld_dimensions, 0, 0, 0)

# Total PUMS Sample x composite_type adjustment for gq    
    adjusting_pums_joint_distribution.create_joint_dist(db, 'gq', gq_control_variables, gq_dimensions, 0, 0, 0)

# Total PUMS Sample x composite_type adjustment for person    
    adjusting_pums_joint_distribution.create_joint_dist(db, 'person', person_control_variables, person_dimensions, 0, 0, 0)
Esempio n. 4
0
def prepare_data(db):
    #    Processes/ methods to be called at the beginning of the pop_synthesis process
    dbc = db.cursor()

    # Identifying the number of housing units to build the Master Matrix
    dbc.execute('select * from housing_pums')
    housing_units = dbc.rowcount
    ti = time.clock()
    # Identifying the control variables for the households, gq's, and persons
    hhld_control_variables = adjusting_pums_joint_distribution.choose_control_variables(
        db, 'hhld')
    gq_control_variables = adjusting_pums_joint_distribution.choose_control_variables(
        db, 'gq')
    person_control_variables = adjusting_pums_joint_distribution.choose_control_variables(
        db, 'person')

    # Identifying the number of categories within each control variable for the households, gq's, and persons
    hhld_dimensions = numpy.asarray(
        adjusting_pums_joint_distribution.create_dimensions(
            db, 'hhld', hhld_control_variables))
    gq_dimensions = numpy.asarray(
        adjusting_pums_joint_distribution.create_dimensions(
            db, 'gq', gq_control_variables))
    person_dimensions = numpy.asarray(
        adjusting_pums_joint_distribution.create_dimensions(
            db, 'person', person_control_variables))

    print 'Dimensions and Control Variables created in %.4f' % (time.clock() -
                                                                ti)
    ti = time.clock()

    update_string = adjusting_pums_joint_distribution.create_update_string(
        db, hhld_control_variables, hhld_dimensions)
    adjusting_pums_joint_distribution.add_unique_id(db, 'hhld', update_string)
    update_string = adjusting_pums_joint_distribution.create_update_string(
        db, gq_control_variables, gq_dimensions)
    adjusting_pums_joint_distribution.add_unique_id(db, 'gq', update_string)
    update_string = adjusting_pums_joint_distribution.create_update_string(
        db, person_control_variables, person_dimensions)
    adjusting_pums_joint_distribution.add_unique_id(db, 'person',
                                                    update_string)

    print 'Uniqueid\'s created in %.4f' % (time.clock() - ti)
    ti = time.clock()

    # Populating the Master Matrix
    populated_matrix = psuedo_sparse_matrix.populate_master_matrix(
        db, 0, housing_units, hhld_dimensions, gq_dimensions,
        person_dimensions)
    print 'Frequency Matrix Populated in %.4f' % (time.clock() - ti)
    ti = time.clock()

    # Sparse representation of the Master Matrix
    ps_sp_matrix = psuedo_sparse_matrix.psuedo_sparse_matrix(
        db, populated_matrix, 0)
    print 'Psuedo Sparse Representation of the Frequency Matrix created in %.4f' % (
        time.clock() - ti)
    ti = time.clock()
    #______________________________________________________________________
    #Creating Index Matrix
    index_matrix = psuedo_sparse_matrix.generate_index_matrix(db, 0)
    print 'Index matrix created in %.4f' % (time.clock() - ti)
    ti = time.clock()
    dbc.close()
    #______________________________________________________________________
    # creating synthetic_population tables in MySQL
    drawing_households.create_synthetic_attribute_tables(db)

    # Total PUMS Sample x composite_type adjustment for hhld
    adjusting_pums_joint_distribution.create_joint_dist(
        db, 'hhld', hhld_control_variables, hhld_dimensions, 0, 0, 0)

    # Total PUMS Sample x composite_type adjustment for gq
    adjusting_pums_joint_distribution.create_joint_dist(
        db, 'gq', gq_control_variables, gq_dimensions, 0, 0, 0)

    # Total PUMS Sample x composite_type adjustment for person
    adjusting_pums_joint_distribution.create_joint_dist(
        db, 'person', person_control_variables, person_dimensions, 0, 0, 0)