def get_updated_configuration_from_module(self, run_configuration, specification_module=None):
     run_configuration = update_controller_by_specification_from_module(
         run_configuration, self.model_name, specification_module
     )
     run_configuration["models_configuration"][self.model_name]["controller"]["prepare_for_estimate"]["arguments"][
         "specification_dict"
     ] = ("spec['%s']" % self.type)
     return run_configuration
 def get_updated_configuration_from_module(self,
                                           run_configuration,
                                           specification_module=None):
     run_configuration = update_controller_by_specification_from_module(
         run_configuration, self.model_name, specification_module)
     run_configuration["models_configuration"][
         self.model_name]["controller"]["prepare_for_estimate"][
             "arguments"]["specification_dict"] = "spec['%s']" % self.type
     return run_configuration
    def get_configuration(self, specification_module="psrc.estimation.estimation_RWZCM_variables"):
        config = copy.deepcopy(run_configuration)
        config["models"] = [
            #"land_price_model",
            {"workplace_choice_model_for_resident": ["estimate"]}
         ]
        
        config["datasets_to_preload"] = {
            'gridcell':{},
            'person':{'package_name':'psrc'},
            'zone':{}                
        } 

        config = update_controller_by_specification_from_module(config, self.model_name, specification_module)

        return config
Esempio n. 4
0
    def get_configuration(
            self,
            specification_module="psrc.estimation.estimation_RWZCM_variables"):
        config = copy.deepcopy(run_configuration)
        config["models"] = [
            #"land_price_model",
            {
                "workplace_choice_model_for_resident": ["estimate"]
            }
        ]

        config["datasets_to_preload"] = {
            'gridcell': {},
            'person': {
                'package_name': 'psrc'
            },
            'zone': {}
        }

        config = update_controller_by_specification_from_module(
            config, self.model_name, specification_module)

        return config
        self["models_configuration"]["household_location_choice_model"]["controller"]["prepare_for_estimate"]["arguments"]["index_to_unplace"] = 'None'
        self["models_configuration"]["household_location_choice_model"]["controller"]["prepare_for_estimate"]["arguments"]["filter"] = "'household.move == 1'"#None #"'psrc.household.customized_filter'"
        self["models_configuration"]["household_location_choice_model"]["controller"]["init"]["arguments"]['filter'] = "'urbansim_parcel.building.is_residential'"
#        self["datasets_to_preload"].merge({"tour":{}, "person":{}})
#        self["datasets_to_cache_after_each_model"] += ["person"]
        self["models"] = [
#            {"household_relocation_model": ["run"]},
#            {"tour_schedule_model": ["run"]},
            {"household_location_choice_model": ["estimate"]}
        ]

if __name__ == '__main__':
    from my_estimation_config import my_configuration
    from urbansim.estimation.estimator import Estimator
    from urbansim.estimation.estimator import update_controller_by_specification_from_module
    from opus_core.simulation_state import SimulationState
    from opus_core.store.attribute_cache import AttributeCache

    run_configuration = HlcmParcelEstimation()
    run_configuration.update_config()
    run_configuration = update_controller_by_specification_from_module(
                            run_configuration, "household_location_choice_model",
                            "inprocess.bhylee.hlcm_parcel_specification")
    er = Estimator(run_configuration, save_estimation_results=False)
    
    er.estimate()
#    er.create_prediction_success_table()
#    er.create_prediction_success_table(choice_geography_id="area_type_id=building.disaggregate(zone.area_type_id, intermediates=[parcel])" )
#    er.create_prediction_success_table(choice_geography_id="building_type_id=building.building_type_id" )
#    er.create_prediction_success_table(choice_geography_id="large_area_id=building.disaggregate(faz.large_area_id, intermediates=[zone, parcel])" )
#    er.reestimate("hlcm_parcel_specification")
Esempio n. 6
0
        'sampler'] = None  #"'opus_core.samplers.weighted_sampler'"
#run_configuration["models_configuration"]["household_location_choice_model"]["init"]["arguments"]["estimate_config"] = {"weights_for_estimation_string":"urbansim.zone.vacant_residential_units"}
run_configuration["models_configuration"]["household_location_choice_model"][
    "controller"]["prepare_for_estimate"]["arguments"][
        "join_datasets"] = 'True'
run_configuration["models_configuration"]["household_location_choice_model"][
    "controller"]["prepare_for_estimate"]["arguments"][
        "index_to_unplace"] = 'None'

run_configuration["models_configuration"]["household_location_choice_model"][
    "controller"]["init"]["arguments"]["location_set"] = "zone"
run_configuration["models_configuration"]["household_location_choice_model"][
    "controller"]["init"]["arguments"][
        "location_id_string"] = "'urbansim.household.zone_id'"
run_configuration["datasets_to_preload"].merge({'zone': {}})
run_configuration['models'] = [{
    'household_location_choice_model': ['estimate']
}]

if __name__ == '__main__':
    from washtenaw.estimation.my_estimation_config import my_configuration
    from urbansim.estimation.estimator import Estimator
    from urbansim.estimation.estimator import update_controller_by_specification_from_module

    run_configuration = update_controller_by_specification_from_module(
        run_configuration, "household_location_choice_model",
        "washtenaw.aocm.hlcm_zone_specification")
    run_configuration.merge(my_configuration)
    estimator = Estimator(run_configuration, save_estimation_results=False)
    estimator.estimate()
#        'gridcells',
#        'households',
#        'jobs',
#        'travel_data',
        'persons', #need to cache
#        'zones',
        'households_for_estimation'
        ]

run_configuration["datasets_to_preload"].merge({'zone':{}, 
                                                'household':{},
                                                'person':{"package_name":"psrc"},
                                                'parcel':{"package_name":"psrc"}
                                                })
run_configuration["models"] = [
#    {"household_relocation_model": ["run"]},
    {"household_location_choice_model": ["estimate"]}
]

if __name__ == '__main__':
    from my_estimation_config import my_configuration
    from urbansim.estimation.estimator import Estimator
    from urbansim.estimation.estimator import update_controller_by_specification_from_module

    run_configuration = update_controller_by_specification_from_module(
                            run_configuration, "household_location_choice_model",
                            "inprocess.psrc_parcel.hlcm_parcel_specification")
    run_configuration.merge(my_configuration)
    estimator = Estimator(run_configuration, save_estimation_results=False)
    estimator.estimate()
#    estimator.reestimate("hlcm_parcel_specification")
# Opus/UrbanSim urban simulation software.
# Copyright (C) 2005-2009 University of Washington
# See opus_core/LICENSE

from urbansim.estimation.hlcm_parcel_estimation_config import run_configuration
from urbansim.estimation.estimator import update_controller_by_specification_from_module

run_configuration = update_controller_by_specification_from_module(
    run_configuration,"household_location_choice_model", "estimation_HLCM_parcel_specification")
# Copyright (C) 2005-2009 University of Washington
# See opus_core/LICENSE 

from urbansim.configs.hlcm_estimation_config import run_configuration as config

run_configuration = config.copy()

run_configuration["models_configuration"]["household_location_choice_model"]["controller"]["init"]["arguments"]['sample_size_locations']=None
run_configuration["models_configuration"]["household_location_choice_model"]["controller"]["init"]["arguments"]['sampler']=None#"'opus_core.samplers.weighted_sampler'"
#run_configuration["models_configuration"]["household_location_choice_model"]["init"]["arguments"]["estimate_config"] = {"weights_for_estimation_string":"urbansim.zone.vacant_residential_units"}
run_configuration["models_configuration"]["household_location_choice_model"]["controller"]["prepare_for_estimate"]["arguments"]["join_datasets"] = 'True'
run_configuration["models_configuration"]["household_location_choice_model"]["controller"]["prepare_for_estimate"]["arguments"]["index_to_unplace"] = 'None'

run_configuration["models_configuration"]["household_location_choice_model"]["controller"]["init"]["arguments"]["location_set"] = "zone"
run_configuration["models_configuration"]["household_location_choice_model"]["controller"]["init"]["arguments"]["location_id_string"] = "'urbansim.household.zone_id'"
run_configuration["datasets_to_preload"].merge({'zone':{}})
run_configuration['models'] = [
    {'household_location_choice_model':['estimate']} ]

if __name__ == '__main__':
    from washtenaw.estimation.my_estimation_config import my_configuration
    from urbansim.estimation.estimator import Estimator
    from urbansim.estimation.estimator import update_controller_by_specification_from_module

    run_configuration = update_controller_by_specification_from_module(
                            run_configuration, "household_location_choice_model",
                            "washtenaw.aocm.hlcm_zone_specification")
    run_configuration.merge(my_configuration)
    estimator = Estimator(run_configuration, save_estimation_results=False)
    estimator.estimate()
Esempio n. 10
0
    def __init__(self,
                 model,
                 specification_module=None,
                 xml_configuration=None,
                 model_group=None,
                 configuration={},
                 save_estimation_results=False):
        """
        If 'specification_module' is given, it contains the specification defined as a dictionary in a module.
        Alternatively, the specification can be passed in an xml format in the 'xml_configuration' argument
        (which should be an instance of XMLConfiguration).
        If both of those arguments are None, the specification is taken from the cache.
        'configuration' is an Opus configuration.
        It can contain an entry 'config_changes_for_estimation' which is a dictionary
        where keys are model names and values are controller changes for that model.
        If 'configuration' is None, it is taken from 'xml_configuration'.
        If xml_configuration is used, and if it has a non-empty expression library, the dictionary representing
        the expression library is added to the configuration under the key 'expression_library'.
        If save_estimation_results is True, the estimation results are saved in the output configuration
        (if given in 'configuration') and in the cache.
        """
        self.specification_module = specification_module
        self.xml_configuration = xml_configuration
        self.model_group = model_group
        self.estimated_model = model

        if configuration is None:
            if self.xml_configuration is None:
                raise StandardError, "Either dictionary based or XML based configuration must be given."
            config = self.xml_configuration.get_estimation_configuration(
                model, model_group)
        else:
            config = Configuration(configuration)
        config_changes = config.get('config_changes_for_estimation', {})

        specification_dict = None
        if self.xml_configuration is not None:
            specification_dict = self.xml_configuration.get_estimation_specification(
                model, model_group)

        if model_group is None:
            if model in config_changes.keys():
                config.merge(config_changes[model])
            else:
                config['models'] = [{model: ["estimate"]}]
            if specification_module is not None:
                config = update_controller_by_specification_from_module(
                    config, model, specification_module)
            elif specification_dict is not None:
                config = update_controller_by_specification_from_dict(
                    config, model, specification_dict)
        else:
            if model in config_changes.keys():
                if model_group in config_changes[model]:
                    config.merge(config_changes[model][model_group])
                else:
                    config.merge(config_changes[model])
            else:
                config['models'] = [{
                    model: {
                        "group_members": [{
                            model_group: ["estimate"]
                        }]
                    }
                }]
            if (specification_module is not None) or (specification_dict
                                                      is not None):
                if '%s_%s' % (model_group,
                              model) in config["models_configuration"].keys():
                    model_name_in_configuration = '%s_%s' % (model_group,
                                                             model)
                else:
                    model_name_in_configuration = model
                if specification_module is not None:
                    config = update_controller_by_specification_from_module(
                        config, model_name_in_configuration,
                        specification_module)
                    config["models_configuration"][model_name_in_configuration][
                        "controller"]["prepare_for_estimate"]["arguments"][
                            "specification_dict"] = "spec['%s']" % model_group
                else:
                    config = update_controller_by_specification_from_dict(
                        config, model, specification_dict[model_group])

            if model.startswith('%s_' % model_group):
                config['model_name_for_coefficients'] = model
            else:
                config['model_name_for_coefficients'] = '%s_%s' % (model_group,
                                                                   model)

        Estimator.__init__(self,
                           config,
                           save_estimation_results=save_estimation_results)
Esempio n. 11
0
from urbansim.estimation.estimator import Estimator
from urbansim.estimation.estimator import update_controller_by_specification_from_module


#model = ("HLCM", "household_location_choice_model") 
#model = ("ELCM", "employment_location_choice_model", "industrial")
#model = ("ELCM", "employment_location_choice_model", "commercial")
##model = ("ELCM", "employment_location_choice_model", "home_based") #disabled because jobs_for_estimation_home_based has no records
#model = ("LUDLCM", "landuse_development_location_choice_model")
model = ("HPM", "housing_price_model")
##model = ("RLSM", "residential_land_share_model") ##TODO

type = None
if len(model) > 2:
    type = model[2]
if type is None:
    exec("from randstad.estimation.%s_estimation_config import run_configuration" % model[0].lower())
    run_configuration = update_controller_by_specification_from_module(
                        run_configuration, model[1],
                        "%s_specification" % model[0])
else:
    exec("from randstad.estimation.%s_estimation_config import %s_configuration as config" % (model[0].lower(),
          model[0].lower()))
    conf = config(type)
    run_configuration = conf.get_configuration(specification_module="randstad.estimation.%s_specification" % model[0])
run_configuration.merge(my_configuration)
estimator = Estimator(run_configuration, save_estimation_results=False)
estimator.estimate()
#estimator.reestimate("randstad.estimation.HLCM_specification")
#estimator.reestimate("randstad.estimation.ELCM_specification", type="home_based")
    
    def __init__(self, model, specification_module=None,
                 xml_configuration=None, model_group=None, configuration={},
                 save_estimation_results=False):
        """
        If 'specification_module' is given, it contains the specification defined as a dictionary in a module.
        Alternatively, the specification can be passed in an xml format in the 'xml_configuration' argument
        (which should be an instance of XMLConfiguration).
        If both of those arguments are None, the specification is taken from the cache.
        'configuration' is an Opus configuration.
        It can contain an entry 'config_changes_for_estimation' which is a dictionary
        where keys are model names and values are controller changes for that model.
        If 'configuration' is None, it is taken from 'xml_configuration'.
        If xml_configuration is used, and if it has a non-empty expression library, the dictionary representing
        the expression library is added to the configuration under the key 'expression_library'.
        If save_estimation_results is True, the estimation results are saved in the output configuration
        (if given in 'configuration') and in the cache.
        """
        self.specification_module = specification_module
        self.xml_configuration = xml_configuration
        self.model_group = model_group
        self.estimated_model = model

        if configuration is None:
            if self.xml_configuration is None:
                raise StandardError, "Either dictionary based or XML based configuration must be given."
            config = self.xml_configuration.get_estimation_configuration(model, model_group)
        else:
            config = Configuration(configuration)
        config_changes = config.get('config_changes_for_estimation', {})

        specification_dict=None
        if self.xml_configuration is not None:
            specification_dict = self.xml_configuration.get_estimation_specification(model, model_group)

        if model_group is None:
            if model in config_changes.keys():
                config.merge(config_changes[model])
            else:
                config['models'] = [{model: ["estimate"]}]
            if specification_module is not None:
                config = update_controller_by_specification_from_module(
                                config, model, specification_module)
            elif specification_dict is not None:
                config = update_controller_by_specification_from_dict(config, model, specification_dict)
        else:
            if model in config_changes.keys():
                if model_group in config_changes[model]:
                    config.merge(config_changes[model][model_group])
                else:
                    config.merge(config_changes[model])
            else:
                config['models'] = [{model: {"group_members": [{model_group: ["estimate"]}]}}]
            if (specification_module is not None) or (specification_dict is not None):
                if '%s_%s' % (model_group, model) in config["models_configuration"].keys():
                    model_name_in_configuration = '%s_%s' % (model_group, model)
                else:
                    model_name_in_configuration = model
                if specification_module is not None:
                    config = update_controller_by_specification_from_module(config, model_name_in_configuration, specification_module)
                    config["models_configuration"][model_name_in_configuration]["controller"]["prepare_for_estimate"]["arguments"]["specification_dict"] = "spec['%s']" % model_group
                else:
                    config = update_controller_by_specification_from_dict(config, model, specification_dict[model_group])

            if model.startswith('%s_' % model_group):
                config['model_name_for_coefficients'] = model
            else:
                config['model_name_for_coefficients'] = '%s_%s' % (model_group, model)

        Estimator.__init__(self, config, save_estimation_results=save_estimation_results)
Esempio n. 13
0
#model = ("HLCM", "household_location_choice_model")
#model = ("ELCM", "employment_location_choice_model", "industrial")
#model = ("ELCM", "employment_location_choice_model", "commercial")
##model = ("ELCM", "employment_location_choice_model", "home_based") #disabled because jobs_for_estimation_home_based has no records
#model = ("LUDLCM", "landuse_development_location_choice_model")
model = ("HPM", "housing_price_model")
##model = ("RLSM", "residential_land_share_model") ##TODO

type = None
if len(model) > 2:
    type = model[2]
if type is None:
    exec(
        "from randstad.estimation.%s_estimation_config import run_configuration"
        % model[0].lower())
    run_configuration = update_controller_by_specification_from_module(
        run_configuration, model[1], "%s_specification" % model[0])
else:
    exec(
        "from randstad.estimation.%s_estimation_config import %s_configuration as config"
        % (model[0].lower(), model[0].lower()))
    conf = config(type)
    run_configuration = conf.get_configuration(
        specification_module="randstad.estimation.%s_specification" % model[0])
run_configuration.merge(my_configuration)
estimator = Estimator(run_configuration, save_estimation_results=False)
estimator.estimate()
#estimator.reestimate("randstad.estimation.HLCM_specification")
#estimator.reestimate("randstad.estimation.ELCM_specification", type="home_based")
# Opus/UrbanSim urban simulation software.
# Copyright (C) 2005-2009 University of Washington
# See opus_core/LICENSE

from urbansim.estimation.hlcm_parcel_estimation_config import run_configuration
from urbansim.estimation.estimator import update_controller_by_specification_from_module

run_configuration = update_controller_by_specification_from_module(
    run_configuration, "household_location_choice_model",
    "estimation_HLCM_parcel_specification")