Error Message at MNL Model

15 views
Skip to first unread message

Ariobimo Seno

unread,
Jun 24, 2024, 2:41:09 AMJun 24
to Biogeme
Dear Prof Bierlaire,

My name is Ario and currently I'm using Biogeme for modelling MNL model for discrete choice between HSR, local train, shuttle bus and private car. I have been following your tutorial for MNL model, but i keep getting error message like this and I'm not sure how to fix it.

--------------------------------------------------------------------------- KeyError Traceback (most recent call last) Cell In[80], line 1 ----> 1 the_biogeme = bio.BIOGEME(database, logprob) 2 the_biogeme.modelName = 'AnalisisData' File F:\Anaconda\Lib\site-packages\biogeme\biogeme.py:240, in BIOGEME.__init__(self, database, formulas, userNotes, parameter_file, skip_audit, **kwargs) 237 self._prepareDatabaseForFormula() 239 if not self.skip_audit: --> 240 self._audit() 242 self.reset_id_manager() 244 self.theC = cb.pyBiogeme(self.id_manager.number_of_free_betas) File F:\Anaconda\Lib\site-packages\biogeme\biogeme.py:815, in BIOGEME._audit(self) 810 err_msg = ( 811 f"The following random variables are defined " 812 f"outside the Integrate operator: {check_rv}" 813 ) 814 list_of_errors.append(err_msg) --> 815 err, war = v.audit(self.database) 816 list_of_errors += err 817 list_of_warnings += war File F:\Anaconda\Lib\site-packages\biogeme\expressions\logit_expressions.py:151, in LogLogit.audit(self, database) 149 list_of_warnings.append(the_error) 150 else: --> 151 choiceAvailability = database.checkAvailabilityOfChosenAlt( 152 self.av, self.choice 153 ) 154 indexOfUnavailableChoices = np.where(~choiceAvailability)[0] 155 if indexOfUnavailableChoices.size > 0: File F:\Anaconda\Lib\site-packages\biogeme\database.py:428, in Database.checkAvailabilityOfChosenAlt(self, avail, choice) 426 calculated_avail = {} 427 for key, expression in avail.items(): --> 428 calculated_avail[key] = expression.getValue_c( 429 database=self, aggregation=False, prepareIds=True 430 ) 431 try: 432 avail_chosen = np.array( 433 [calculated_avail[c][i] for i, c in enumerate(choice_array)] 434 ) File F:\Anaconda\Lib\site-packages\biogeme\expressions\base_expressions.py:829, in Expression.getValue_c(self, database, betas, numberOfDraws, aggregation, prepareIds) 823 error_msg = ( 824 "An expression involving MonteCarlo integration " 825 "must be associated with a database." 826 ) 827 raise excep.BiogemeError(error_msg) --> 829 f, _, _, _ = self.getValueAndDerivatives( 830 betas=betas, 831 database=database, 832 numberOfDraws=numberOfDraws, 833 gradient=False, 834 hessian=False, 835 bhhh=False, 836 aggregation=aggregation, 837 prepareIds=prepareIds, 838 ) 839 if database is None: 840 if len(f) != 1: File F:\Anaconda\Lib\site-packages\biogeme\expressions\base_expressions.py:916, in Expression.getValueAndDerivatives(self, betas, database, numberOfDraws, gradient, hessian, bhhh, aggregation, prepareIds) 914 if prepareIds: 915 self.keep_id_manager = self.id_manager --> 916 self.prepare(database, numberOfDraws) 917 elif self.id_manager is None: 918 error_msg = "Expression evaluated out of context. Set prepareIds to True." File F:\Anaconda\Lib\site-packages\biogeme\expressions\base_expressions.py:123, in Expression.prepare(self, database, numberOfDraws) 121 # Second, we calculate a new set of IDs. 122 id_manager = IdManager([self], database, numberOfDraws) --> 123 self.setIdManager(id_manager) File F:\Anaconda\Lib\site-packages\biogeme\expressions\elementary_expressions.py:267, in Variable.setIdManager(self, id_manager) 265 self.variableId = None 266 return --> 267 self.elementaryIndex = self.id_manager.elementary_expressions.indices[self.name] 268 self.variableId = self.id_manager.variables.indices[self.name] KeyError: 'HSR_AV'
Analisis_Data.py
Analisis Data.ipynb

Michel Bierlaire

unread,
Jun 24, 2024, 2:51:22 AMJun 24
to arioobi...@gmail.com, Michel Bierlaire, Biogeme
There are several issues.
In the definition of GOPAR_AV_SP, TRAVEL_AV_SP and CAR_AV_SP, you forgot the comma.
Then, in the availability dict, you use HSR_AV_SP, which is not defined anywhere.
> --
> You received this message because you are subscribed to the Google Groups "Biogeme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to biogeme+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/biogeme/40e84e76-e48a-4a3f-873d-5f7d7bed7181n%40googlegroups.com.
> <Analisis_Data.py><Analisis Data.ipynb>

Michel Bierlaire
Transport and Mobility Laboratory
School of Architecture, Civil and Environmental Engineering
EPFL - Ecole Polytechnique Fédérale de Lausanne
http://transp-or.epfl.ch
http://people.epfl.ch/michel.bierlaire

Reply all
Reply to author
Forward
0 new messages