def estimate(self, specification, agent_set, agents_index=None, procedure=None, data_objects=None, estimate_config=None, debuglevel=0): """ Computes capacity if required and calls the estimate method of ChoiceModel. See ChoiceModel.estimate for details on arguments. """ if agents_index==None: agents_index=arange(agent_set.size()) if agents_index.size <= 0: logger.log_status("Nothing to be done.") return (None, None) if estimate_config == None: estimate_config = Resources() self.estimate_config = estimate_config.merge_with_defaults(self.estimate_config) if data_objects is not None: self.dataset_pool.add_datasets_if_not_included(data_objects) if self.location_id_string is not None: agent_set.compute_variables(self.location_id_string, dataset_pool=self.dataset_pool) capacity_for_estimation = None if self.estimate_config.get("compute_capacity_flag", False): capacity_string_for_estimation = self.estimate_config.get("capacity_string", None) capacity_for_estimation = self.determine_capacity(capacity_string=capacity_string_for_estimation, agent_set=agent_set, agents_index=agents_index) self.estimate_config.merge({"capacity":capacity_for_estimation}) return ChoiceModel.estimate(self,specification, agent_set, agents_index, procedure, estimate_config=self.estimate_config, debuglevel=debuglevel)
def estimate(self, specification, agent_set_year1, agent_set_year2, agents_index=None, procedure="opus_core.bhhh_mnl_estimation", calibrate_constants=False, data_objects=None, estimate_config=None, debuglevel=0): """Set calibrate_constants to True only if agent_set_year1 is the full dataset. Otherwise, the calibration can be done separately by calling the method "calibrate" with the full dataset. """ if self.choice_attribute_name.get_alias() not in agent_set_year2.get_known_attribute_names(): agent_set_year2.compute_variables([self.choice_attribute_name]) if self.submodel_string not in agent_set_year1.get_known_attribute_names(): agent_set_year1.compute_variables([self.submodel_string]) lct_y2 = agent_set_year2.get_attribute(self.choice_attribute_name) attributes_switched = False if self.submodel_string == self.choice_attribute_name.get_alias(): new_submodel_string = self.choice_attribute_name.get_alias() + "_start" original_submodel_string = self.submodel_string agent_set_year1.add_attribute(name=new_submodel_string, data=agent_set_year1.get_attribute(original_submodel_string).astype(int16)) agent_set_year1.add_attribute(name=original_submodel_string, data=lct_y2.astype(int16)) self.submodel_string = new_submodel_string attributes_switched = True self.specification = specification results = ChoiceModel.estimate(self,specification, agent_set_year1, agents_index, procedure, data_objects, estimate_config, debuglevel=debuglevel) if calibrate_constants: self.calibrate(agent_set_year1, agent_set_year2, agents_index) if attributes_switched: agent_set_year1.add_attribute(name=self.choice_attribute_name.get_alias() + "_end", data=agent_set_year1.get_attribute(self.choice_attribute_name)) agent_set_year1.add_attribute(name=original_submodel_string, data=agent_set_year1.get_attribute(new_submodel_string)) agent_set_year1.delete_one_attribute(new_submodel_string) return self.coefficients, results[1]
def estimate(self, specification, agent_set, agents_index=None, procedure=None, data_objects=None, estimate_config=None, debuglevel=0): """ Computes capacity if required and calls the estimate method of ChoiceModel. See ChoiceModel.estimate for details on arguments. """ if agents_index == None: agents_index = arange(agent_set.size()) if agents_index.size <= 0: logger.log_status("Nothing to be done.") return (None, None) if estimate_config == None: estimate_config = Resources() self.estimate_config = estimate_config.merge_with_defaults( self.estimate_config) if data_objects is not None: self.dataset_pool.add_datasets_if_not_included(data_objects) if self.location_id_string is not None: agent_set.compute_variables(self.location_id_string, dataset_pool=self.dataset_pool) capacity_for_estimation = None if self.estimate_config.get("compute_capacity_flag", False): capacity_string_for_estimation = self.estimate_config.get( "capacity_string", None) capacity_for_estimation = self.determine_capacity( capacity_string=capacity_string_for_estimation, agent_set=agent_set, agents_index=agents_index) self.estimate_config.merge({"capacity": capacity_for_estimation}) return ChoiceModel.estimate(self, specification, agent_set, agents_index, procedure, estimate_config=self.estimate_config, debuglevel=debuglevel)
from opus_core.equation_specification import EquationSpecification specification = EquationSpecification( coefficients = array([ "beta01", "beta12", "beta03", "beta13" ]), variables = array([ "constant","household.persons", "constant", "household.persons" ]), equations = array([ 1, 2, 3, 3 ]) ) households.add_primary_attribute(data=[1,2,2,2,1,3,3,1,2,1], name="choice_id") coefficients, other_results = choicemodel.estimate(specification, households, procedure="opus_core.bhhh_mnl_estimation") # # Uncomment to output mycoef.tab # #coefficients.write(out_storage=storage, out_table_name="mycoef") from numpy.random import seed seed(1) choices = choicemodel.run( specification, coefficients, households, debuglevel=1) households.modify_attribute(name="choice_id", data=choices) from opus_core.coefficients import Coefficients coefficients = Coefficients( names=array(["beta01", "beta12", "beta03", "beta13"]),
def estimate(self, specification, *args, **kwargs): self.init_membership_in_nests() # This is because there will be __logsum_ variables in the specification when configured from the GUI, # in order to define starting values. They are not supposed to be included there. self.delete_logsum_from_specification(specification) return ChoiceModel.estimate(self, specification, *args, **kwargs)
def estimate(self, specification, *args, **kwargs): self.init_membership_in_nests() # This is because there will be __logsum_ variables in the specification when configured from the GUI, # in order to define starting values. They are not supposed to be included there. self.delete_logsum_from_specification(specification) return ChoiceModel.estimate(self, specification, *args, **kwargs)
from opus_core.equation_specification import EquationSpecification specification = EquationSpecification( coefficients = array([ "beta01", "beta12", "beta03", "beta13" ]), variables = array([ "constant","household.persons", "constant", "household.persons" ]), equations = array([ 1, 2, 3, 3 ]) ) households.add_primary_attribute(data=[1,2,2,2,1,3,3,1,2,1], name="choice_id") coefficients, other_results = choicemodel.estimate(specification, households, procedure="opus_core.bhhh_mnl_estimation") # # Uncomment to output mycoef.tab # #coefficients.write(out_storage=storage, out_table_name="mycoef") from numpy.random import seed seed(1) choices = choicemodel.run( specification, coefficients, households, debuglevel=1) households.modify_attribute(name="choice_id", data=choices) from opus_core.coefficients import Coefficients coefficients = Coefficients( names=array(["beta01", "beta12", "beta03", "beta13"]),