def get_model(self, location_set, sampler = "opus_core.samplers.weighted_sampler", utilities = "opus_core.linear_utilities", choices = "opus_core.random_choices", probabilities = "opus_core.mnl_probabilities", estimation = "opus_core.bhhh_mnl_estimation", sample_proportion_locations = None, sample_size_locations = 20, estimation_size_agents = 1.0, compute_capacity_flag = False, filter = None, submodel_string = "sector_id", run_config = None, estimate_config=None, debuglevel=0): run_config = merge_resources_if_not_None(run_config, [ ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("compute_capacity_flag", compute_capacity_flag)]) run_config = merge_resources_with_defaults(run_config, [("capacity_string", self.capacity_string_default)]) estimate_config = merge_resources_if_not_None(estimate_config, [ ("estimation", estimation), ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("estimation_size_agents", estimation_size_agents)]) estimate_config = merge_resources_with_defaults(estimate_config, [("weights_for_estimation_string", self.estimation_weight_string_default)]) return AgentLocationChoiceModel(location_set, agent_name="job", model_name="Employment Location Choice Model", \ short_name="ELCM", sampler=sampler, utilities=utilities, probabilities=probabilities, choices=choices, filter=filter, submodel_string=submodel_string, run_config=run_config, estimate_config=estimate_config, debuglevel=debuglevel)
def __init__(self, project_type, location_set, model_configuration, sampler = "opus_core.samplers.weighted_sampler", utilities = "opus_core.linear_utilities", choices = "urbansim.first_agent_first_choices", probabilities = "opus_core.mnl_probabilities", estimation = "opus_core.bhhh_mnl_estimation", sample_proportion_locations = None, sample_size_locations = 30, estimation_size_agents = 1.0, compute_capacity_flag = True, filter = "", submodel_string = "size_category", location_id_string = None, run_config = None, estimate_config=None, debuglevel=0): units = model_configuration['units'] developable_maximum_unit_variable_full_name = model_configuration['developable_maximum_unit_variable_full_name'] developable_minimum_unit_variable_full_name = model_configuration['developable_minimum_unit_variable_full_name'] default_capacity_attribute = "urbansim.gridcell.is_developable_for_%s" % units default_filter = "urbansim.gridcell.developable_%s" % units if filter == "": filter = default_filter run_config = merge_resources_if_not_None(run_config, [ ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("compute_capacity_flag", compute_capacity_flag)]) run_config = merge_resources_with_defaults(run_config, [("capacity_string", default_capacity_attribute)]) estimate_config = merge_resources_if_not_None(estimate_config, [ ("estimation", estimation), ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("estimation_size_agents", estimation_size_agents)]) estimate_config = merge_resources_with_defaults(estimate_config, [("weights_for_estimation_string", self.estimation_weight_string_default)]) DevelopmentProjectLocationChoiceModel.__init__(self, location_set, project_type=project_type, units=units, developable_maximum_unit_variable_full_name=developable_maximum_unit_variable_full_name, developable_minimum_unit_variable_full_name=developable_minimum_unit_variable_full_name, model_name="Regional Development Project %s Location Choice Model" % project_type, sampler=sampler, utilities=utilities, probabilities=probabilities, choices=choices, filter=filter, submodel_string=submodel_string, location_id_string = location_id_string, run_config=run_config, estimate_config=estimate_config, debuglevel=debuglevel)
def get_model( self, location_set, sampler="opus_core.samplers.weighted_sampler", utilities="opus_core.linear_utilities", choices="opus_core.random_choices", probabilities="opus_core.mnl_probabilities", estimation="opus_core.bhhh_mnl_estimation", sample_proportion_locations=None, sample_size_locations=30, estimation_size_agents=1.0, compute_capacity_flag=True, filter=None, submodel_string=None, location_id_string=None, demand_string=None, # if not None, the aggregate demand for locations will be stored in this attribute run_config=None, estimate_config=None, debuglevel=0, dataset_pool=None): run_config = merge_resources_if_not_None( run_config, [("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("compute_capacity_flag", compute_capacity_flag)]) run_config = merge_resources_with_defaults( run_config, [("capacity_string", self.capacity_string_default), ("number_of_agents_string", self.number_of_agents_string_default), ("number_of_units_string", self.number_of_units_string_default)]) if demand_string: run_config["demand_string"] = demand_string estimate_config = merge_resources_if_not_None( estimate_config, [("estimation", estimation), ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("estimation_size_agents", estimation_size_agents)]) estimate_config = merge_resources_with_defaults( estimate_config, [("weights_for_estimation_string", self.estimation_weight_string_default)]) return AgentLocationChoiceModel( location_set, model_name="Household Location Choice Model", short_name="HLCM", sampler=sampler, utilities=utilities, probabilities=probabilities, choices=choices, filter=filter, submodel_string=submodel_string, location_id_string=location_id_string, run_config=run_config, estimate_config=estimate_config, debuglevel=debuglevel, dataset_pool=dataset_pool)
def get_model(self, location_set, sampler = "opus_core.samplers.weighted_sampler", utilities = "opus_core.linear_utilities", choices = "urbansim.first_agent_first_choices", probabilities = "opus_core.mnl_probabilities", estimation = "opus_core.bhhh_mnl_estimation", sample_proportion_locations = None, sample_size_locations = 30, estimation_size_agents = 1.0, compute_capacity_flag = True, filter = "randstad.gridcell.is_developable", submodel_string = "development_type_id", run_config = None, estimate_config=None, debuglevel=0): default_capacity_string = "randstad.gridcell.is_developable" run_config = merge_resources_if_not_None(run_config, [ ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("compute_capacity_flag", compute_capacity_flag) ("filter", filter)]) run_config = merge_resources_with_defaults(run_config, [("capacity_string", default_capacity_string), ("simulation_sampling_include_current_choice", False)]) estimate_config = merge_resources_if_not_None(estimate_config, [ ("estimation", estimation), ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("estimation_size_agents", estimation_size_agents)]) estimate_config = merge_resources_with_defaults(estimate_config, [("weights_for_estimation_string", self.estimation_weight_string_default), ("simulation_sampling_include_current_choice", True)]) return LandUseDevelopmentLocationChoiceModel(location_set, opus_package='randstad', model_name="Landuse Development Location Choice Model", sampler=sampler, utilities=utilities, probabilities=probabilities, choices=choices, filter=filter, submodel_string=submodel_string, run_config=run_config, estimate_config=estimate_config, debuglevel=debuglevel)
def get_model(self, location_set, sampler = "opus_core.samplers.weighted_sampler", utilities = "opus_core.linear_utilities", choices = "opus_core.random_choices", probabilities = "opus_core.mnl_probabilities", estimation = "opus_core.bhhh_mnl_estimation", sample_proportion_locations = None, sample_size_locations = 30, estimation_size_agents = 1.0, compute_capacity_flag = True, filter=None, submodel_string = None, location_id_string = None, demand_string = None, # if not None, the aggregate demand for locations will be stored in this attribute run_config = None, estimate_config=None, debuglevel=0, dataset_pool=None): run_config = merge_resources_if_not_None(run_config, [ ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("compute_capacity_flag", compute_capacity_flag)]) run_config = merge_resources_with_defaults(run_config, [("capacity_string", self.capacity_string_default), ("number_of_agents_string", self.number_of_agents_string_default), ("number_of_units_string", self.number_of_units_string_default) ]) if demand_string: run_config["demand_string"] = demand_string estimate_config = merge_resources_if_not_None(estimate_config, [ ("estimation", estimation), ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("estimation_size_agents", estimation_size_agents)]) estimate_config = merge_resources_with_defaults(estimate_config, [("weights_for_estimation_string", self.estimation_weight_string_default)]) return AgentLocationChoiceModel(location_set, model_name="Household Location Choice Model", short_name="HLCM", sampler=sampler, utilities=utilities, probabilities=probabilities, choices=choices, filter=filter, submodel_string=submodel_string, location_id_string=location_id_string, run_config=run_config, estimate_config=estimate_config, debuglevel=debuglevel, dataset_pool=dataset_pool)
def get_model(self, location_set, sampler="opus_core.samplers.weighted_sampler", utilities="opus_core.linear_utilities", choices="opus_core.random_choices", probabilities="opus_core.mnl_probabilities", estimation="opus_core.bhhh_mnl_estimation", sample_proportion_locations=None, sample_size_locations=20, estimation_size_agents=1.0, compute_capacity_flag=False, filter=None, submodel_string="sector_id", run_config=None, estimate_config=None, debuglevel=0): run_config = merge_resources_if_not_None( run_config, [("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("compute_capacity_flag", compute_capacity_flag)]) run_config = merge_resources_with_defaults( run_config, [("capacity_string", self.capacity_string_default)]) estimate_config = merge_resources_if_not_None( estimate_config, [("estimation", estimation), ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("estimation_size_agents", estimation_size_agents)]) estimate_config = merge_resources_with_defaults( estimate_config, [("weights_for_estimation_string", self.estimation_weight_string_default)]) return AgentLocationChoiceModel(location_set, agent_name="job", model_name="Employment Location Choice Model", \ short_name="ELCM", sampler=sampler, utilities=utilities, probabilities=probabilities, choices=choices, filter=filter, submodel_string=submodel_string, run_config=run_config, estimate_config=estimate_config, debuglevel=debuglevel)
def __init__( self, group_member, location_set, agents_grouping_attribute='building.building_type_id', sampler="opus_core.samplers.weighted_sampler", utilities="opus_core.linear_utilities", choices="urbansim.first_agent_first_choices", probabilities="opus_core.mnl_probabilities", estimation="opus_core.bhhh_mnl_estimation", capacity_string="is_developable_for_buildings_UNITS", estimation_weight_string=None, developable_maximum_unit_variable="developable_maximum_buildings_UNITS", developable_minimum_unit_variable="developable_minimum_UNITS", # None means don't consider any minimum. For default, set it to empty string number_of_agents_string="buildings_SSS_space", number_of_units_string="total_maximum_development_SSS", sample_proportion_locations=None, sample_size_locations=30, estimation_size_agents=1.0, compute_capacity_flag=True, filter="developable_maximum_buildings_UNITS", # None doesn't use any filter submodel_string="size_category_SSS", # Put here None, if no submodels should be used. nrecords_per_chunk_for_estimation_sampling=1000, # put here None, if everything in 1 chunk location_id_string=None, run_config=None, estimate_config=None, debuglevel=0, dataset_pool=None, variable_package="urbansim"): """ 'group_member' is of type ModelGroupMember. """ group_member_name = group_member.get_member_name() units = group_member.get_attribute_value("units")[0] if capacity_string: capacity_string = re.sub("UNITS", units, capacity_string) capacity_string = re.sub("SSS", group_member_name, capacity_string) if filter: filter = re.sub("UNITS", units, filter) filter = re.sub("SSS", group_member_name, filter) if developable_maximum_unit_variable: developable_maximum_unit_variable = re.sub( "UNITS", units, developable_maximum_unit_variable) developable_maximum_unit_variable = re.sub( "SSS", group_member_name, developable_maximum_unit_variable) if developable_minimum_unit_variable == "": developable_minimum_unit_variable = "developable_minimum_%s" % units elif developable_minimum_unit_variable: developable_minimum_unit_variable = re.sub( "UNITS", units, developable_minimum_unit_variable) developable_minimum_unit_variable = re.sub( "SSS", group_member_name, developable_minimum_unit_variable) if submodel_string: submodel_string = re.sub("UNITS", units, submodel_string) submodel_string = re.sub("SSS", group_member_name, submodel_string) if number_of_agents_string: number_of_agents_string = re.sub('UNITS', units, number_of_agents_string) number_of_agents_string = re.sub('SSS', group_member_name, number_of_agents_string) if number_of_units_string: number_of_units_string = re.sub('UNITS', units, number_of_units_string) number_of_units_string = re.sub('SSS', group_member_name, number_of_units_string) # create full names from (possibly) short names tmpdict = Resources({ "filter": filter, "max": developable_maximum_unit_variable, "min": developable_minimum_unit_variable }) self.add_prefix_to_variable_names(["filter", "max", "min"], location_set, variable_package, resources=tmpdict) filter = tmpdict["filter"] if tmpdict["max"]: self.developable_maximum_unit_variable = VariableName( tmpdict["max"]) else: self.developable_maximum_unit_variable = None if tmpdict["min"]: self.developable_minimum_unit_variable = VariableName( tmpdict["min"]) else: self.developable_minimum_unit_variable = None self.project_type = group_member_name self.units = units run_config = merge_resources_with_defaults(run_config, [ ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("compute_capacity_flag", compute_capacity_flag), ("capacity_string", capacity_string), ("agent_units_string", "urbansim.building.building_size"), ("number_of_agents_string", number_of_agents_string), ("number_of_units_string", number_of_units_string), ]) estimate_config = merge_resources_with_defaults( estimate_config, [("estimation", estimation), ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("estimation_size_agents", estimation_size_agents), ("weights_for_estimation_string", estimation_weight_string), ("capacity_string", capacity_string), ("compute_capacity_flag", compute_capacity_flag)]) if nrecords_per_chunk_for_estimation_sampling: estimate_config[ "chunk_specification_for_estimation"] = ChunkSpecification({ "records_per_chunk": nrecords_per_chunk_for_estimation_sampling }) AgentLocationChoiceModelMember.__init__( self, group_member, location_set, agents_grouping_attribute, model_name="Building Location Choice Model", short_name="BLCM", sampler=sampler, utilities=utilities, probabilities=probabilities, choices=choices, filter=filter, submodel_string=submodel_string, location_id_string=location_id_string, run_config=run_config, estimate_config=estimate_config, debuglevel=debuglevel, dataset_pool=dataset_pool, variable_package=variable_package)
def get_model(self, project_type, location_set, sampler = "opus_core.samplers.weighted_sampler", utilities = "opus_core.linear_utilities", choices = "urbansim.first_agent_first_choices", probabilities = "opus_core.mnl_probabilities", estimation = "opus_core.bhhh_mnl_estimation", sample_proportion_locations = None, sample_size_locations = 30, estimation_size_agents = 1.0, compute_capacity_flag = True, filter = "", submodel_string = "size_category", model_configuration = None, location_id_string = None, run_config = None, estimate_config = None, debuglevel = 0, units = '', developable_maximum_unit_variable_full_name = '', developable_minimum_unit_variable_full_name = '', residential = False): if model_configuration is not None: units = model_configuration['units'] developable_maximum_unit_variable_full_name = model_configuration['developable_maximum_unit_variable_full_name'] developable_minimum_unit_variable_full_name = model_configuration['developable_minimum_unit_variable_full_name'] default_capacity_attribute = "urbansim.gridcell.is_developable_for_%s" % units default_filter = "urbansim.gridcell.developable_%s" % units if filter == "": filter = default_filter run_config = merge_resources_if_not_None(run_config, [ ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("compute_capacity_flag", compute_capacity_flag)]) run_config = merge_resources_with_defaults(run_config, [("capacity_string", default_capacity_attribute)]) estimate_config = merge_resources_if_not_None(estimate_config, [ ("estimation", estimation), ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("estimation_size_agents", estimation_size_agents)]) estimate_config = merge_resources_with_defaults(estimate_config, [("weights_for_estimation_string", self.estimation_weight_string_default)]) return DevelopmentProjectLocationChoiceModel(location_set, project_type=project_type, units=units, developable_maximum_unit_variable_full_name=developable_maximum_unit_variable_full_name, developable_minimum_unit_variable_full_name=developable_minimum_unit_variable_full_name, model_name="Development Project %s Location Choice Model" % project_type, # residential = residential, sampler=sampler, utilities=utilities, probabilities=probabilities, choices=choices, filter=filter, submodel_string=submodel_string, location_id_string = location_id_string, run_config=run_config, estimate_config=estimate_config, debuglevel=debuglevel)
def __init__(self, group_member, location_set, agents_grouping_attribute = 'building.building_type_id', sampler = "opus_core.samplers.weighted_sampler", utilities = "opus_core.linear_utilities", choices = "urbansim.first_agent_first_choices", probabilities = "opus_core.mnl_probabilities", estimation = "opus_core.bhhh_mnl_estimation", capacity_string = "is_developable_for_buildings_UNITS", estimation_weight_string = None, developable_maximum_unit_variable = "developable_maximum_buildings_UNITS", developable_minimum_unit_variable = "developable_minimum_UNITS", # None means don't consider any minimum. For default, set it to empty string number_of_agents_string = "buildings_SSS_space", number_of_units_string = "total_maximum_development_SSS", sample_proportion_locations = None, sample_size_locations = 30, estimation_size_agents = 1.0, compute_capacity_flag = True, filter = "developable_maximum_buildings_UNITS", # None doesn't use any filter submodel_string = "size_category_SSS", # Put here None, if no submodels should be used. nrecords_per_chunk_for_estimation_sampling = 1000, # put here None, if everything in 1 chunk location_id_string = None, run_config = None, estimate_config=None, debuglevel=0, dataset_pool=None, variable_package = "urbansim"): """ 'group_member' is of type ModelGroupMember. """ group_member_name = group_member.get_member_name() units = group_member.get_attribute_value("units")[0] if capacity_string: capacity_string = re.sub("UNITS", units, capacity_string) capacity_string = re.sub("SSS", group_member_name, capacity_string) if filter: filter = re.sub("UNITS", units, filter) filter = re.sub("SSS", group_member_name, filter) if developable_maximum_unit_variable: developable_maximum_unit_variable = re.sub("UNITS", units, developable_maximum_unit_variable) developable_maximum_unit_variable = re.sub("SSS", group_member_name, developable_maximum_unit_variable) if developable_minimum_unit_variable == "": developable_minimum_unit_variable = "developable_minimum_%s" % units elif developable_minimum_unit_variable: developable_minimum_unit_variable = re.sub("UNITS", units, developable_minimum_unit_variable) developable_minimum_unit_variable = re.sub("SSS", group_member_name, developable_minimum_unit_variable) if submodel_string: submodel_string = re.sub("UNITS", units, submodel_string) submodel_string = re.sub("SSS", group_member_name, submodel_string) if number_of_agents_string: number_of_agents_string = re.sub('UNITS', units, number_of_agents_string) number_of_agents_string = re.sub('SSS', group_member_name, number_of_agents_string) if number_of_units_string: number_of_units_string = re.sub('UNITS', units, number_of_units_string) number_of_units_string = re.sub('SSS', group_member_name, number_of_units_string) # create full names from (possibly) short names tmpdict = Resources({"filter": filter, "max": developable_maximum_unit_variable, "min": developable_minimum_unit_variable}) self.add_prefix_to_variable_names(["filter", "max", "min"], location_set, variable_package, resources=tmpdict) filter = tmpdict["filter"] if tmpdict["max"]: self.developable_maximum_unit_variable = VariableName(tmpdict["max"]) else: self.developable_maximum_unit_variable = None if tmpdict["min"]: self.developable_minimum_unit_variable = VariableName(tmpdict["min"]) else: self.developable_minimum_unit_variable = None self.project_type = group_member_name self.units = units run_config = merge_resources_with_defaults(run_config, [ ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("compute_capacity_flag", compute_capacity_flag), ("capacity_string", capacity_string), ("agent_units_string", "urbansim.building.building_size"), ("number_of_agents_string", number_of_agents_string), ("number_of_units_string", number_of_units_string), ]) estimate_config = merge_resources_with_defaults(estimate_config, [ ("estimation", estimation), ("sample_proportion_locations", sample_proportion_locations), ("sample_size_locations", sample_size_locations), ("estimation_size_agents", estimation_size_agents), ("weights_for_estimation_string", estimation_weight_string), ("capacity_string", capacity_string), ("compute_capacity_flag", compute_capacity_flag)]) if nrecords_per_chunk_for_estimation_sampling: estimate_config["chunk_specification_for_estimation"] = ChunkSpecification({ "records_per_chunk": nrecords_per_chunk_for_estimation_sampling}) AgentLocationChoiceModelMember.__init__(self, group_member, location_set, agents_grouping_attribute, model_name = "Building Location Choice Model", short_name = "BLCM", sampler=sampler, utilities=utilities, probabilities=probabilities, choices=choices, filter=filter, submodel_string=submodel_string, location_id_string=location_id_string, run_config=run_config, estimate_config=estimate_config, debuglevel=debuglevel, dataset_pool=dataset_pool, variable_package=variable_package)