def reestimate(self, submodels=None, reload_xml_file=True):
     """Launch a re-estimation without recomputing all variables. 'submodels' is a list or single number of submodels to re-estimate.
     If it is None, all submodels are re-estimated.  If self.xml_configuration is not None and reload_xml_file is True, re-read
     the contents of the xml configuration file in case it has changed.  This will usually be what you want to do when
     using reestimate from the command line -- but not from the GUI (since with the GUI, the XMLConfiguration might have been
     edited but not yet saved back to the file).
     """
     specification_dict=None
     if self.xml_configuration is not None:
         if reload_xml_file:
             self.xml_configuration.initialize_from_xml_file()
         specification_dict = self.xml_configuration.get_estimation_specification(self.estimated_model, model_group=self.model_group)
     Estimator.reestimate(self, self.specification_module, specification_dict=specification_dict, type=self.model_group, submodels=submodels)
예제 #2
0
 def reestimate(self, submodels=None, reload_xml_file=True):
     """Launch a re-estimation without recomputing all variables. 'submodels' is a list or single number of submodels to re-estimate.
     If it is None, all submodels are re-estimated.  If self.xml_configuration is not None and reload_xml_file is True, re-read
     the contents of the xml configuration file in case it has changed.  This will usually be what you want to do when
     using reestimate from the command line -- but not from the GUI (since with the GUI, the XMLConfiguration might have been
     edited but not yet saved back to the file).
     """
     specification_dict = None
     if self.xml_configuration is not None:
         if reload_xml_file:
             self.xml_configuration.initialize_from_xml_file()
         specification_dict = self.xml_configuration.get_estimation_specification(
             self.estimated_model, model_group=self.model_group)
     Estimator.reestimate(self,
                          self.specification_module,
                          specification_dict=specification_dict,
                          type=self.model_group,
                          submodels=submodels)
        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")
    "parcels",
    #        '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")
예제 #5
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()
예제 #6
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)
    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)