Show
Ignore:
Timestamp:
05/08/08 15:12:55 (3 months ago)
Author:
lmwang
Message:

(lmwang)update run_year_name_space for predict() to work in interactive mode

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/urbansim/estimation/estimator.py

    r3267 r3310  
    9999            for sm in submodels_to_be_deleted: 
    100100                del specification_dict[sm] 
    101         specification = EquationSpecification(specification_dict=specification_dict) 
     101        self.specification = EquationSpecification(specification_dict=specification_dict) 
    102102        new_namespace = self.model_system.run_year_namespace 
    103         new_namespace["specification"] = specification 
    104         self.model_system.do_process(new_namespace) 
    105         self.extract_coefficients_and_specification() 
     103        keys_coeff_spec = self.get_keys_for_coefficients_and_specification() 
     104        new_namespace[keys_coeff_spec["specification"]] = self.specification 
     105        self.coefficients, coeff_dict_dummy = self.model_system.do_process(new_namespace) 
     106        ## update run_year_namespce since it's not been updated by do_process 
     107        self.model_system.run_year_namespace = new_namespace 
     108        self.model_system.run_year_namespace[keys_coeff_spec["coefficients"]] = self.coefficients 
     109         
     110        ## this gets coeff and spec from run_year_namespce and is only updated in _run_year method 
     111        #self.extract_coefficients_and_specification()   
    106112        if self.save_estimation_results: 
    107113            self.save_results(out_storage=out_storage) 
     
    131137        except: 
    132138            logger.log_error("The estimate() method must be run first") 
    133             return 
     139            return False 
    134140         
    135141        try: 
     
    286292            if isinstance(self.model_system.run_year_namespace[key], EquationSpecification): 
    287293                self.specification = self.model_system.run_year_namespace[key] 
     294 
     295    def get_keys_for_coefficients_and_specification(self): 
     296        result = {} 
     297        for key in self.model_system.run_year_namespace.keys(): 
     298            if isinstance(self.model_system.run_year_namespace[key], Coefficients): 
     299                result['coefficients'] = key 
     300            if isinstance(self.model_system.run_year_namespace[key], EquationSpecification): 
     301                result['specification'] = key 
     302        if not result.has_key('coefficients'): 
     303            logger.log_warning("No Coefficients object is found in the name space of model_system ") 
     304        if not result.has_key('specification'): 
     305            logger.log_warning("No EquationSpecification object is found in the name space of model_system ") 
     306         
     307        return result 
     308             
    288309       #for key in self.model_system.vardict.keys(): 
    289310#            if key.rfind("coefficients") >=0: