命令biogeme = biogeme.BIOGEME(数据库,logprob)后出错

问题描述 投票:0回答:1

我正在尝试使用 Biogeme 2.3.12 来估计高铁、传统火车、公共汽车和汽车之间的选择模型。当我运行命令 biogeme = biogeme.BIOGEME (database, log prob) 时,我收到如下错误:

KeyError                                  Traceback (most recent call last)
Cell In[33], line 2
      1 import biogeme.biogeme
----> 2 biogeme = bio.BIOGEME(database,logprob)

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:123, in LogLogit.audit(self, database)
    121     choices = np.array([self.choice.getValue_c()])
    122 else:
--> 123     choices = database.valuesFromDatabase(self.choice)
    124 correctChoices = np.isin(choices, listOfAlternatives)
    125 indexOfIncorrectChoices = np.argwhere(~correctChoices)

File F:\Anaconda\Lib\site-packages\biogeme\database.py:395, in Database.valuesFromDatabase(self, expression)
    392     error_msg = 'Database has no entry'
    393     raise excep.BiogemeError(error_msg)
--> 395 return expression.getValue_c(database=self, prepareIds=True)

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:974, in Expression.getValueAndDerivatives(self, betas, database, numberOfDraws, gradient, hessian, bhhh, aggregation, prepareIds)
    970 # Now, if we had to set the IDS, we reset them as they cannot
    971 # be used in another context.
    972 if prepareIds:
    973     # We restore the previous Id manager
--> 974     self.setIdManager(self.keep_id_manager)
    975 return results

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: 'CHOICE'

我没有任何线索,我已经尝试了一切,但没有任何效果。如果您能帮助我,我将非常感激

jupyter-notebook anaconda
1个回答
0
投票

这个问题有解决办法吗?我在spyder上运行biogeme时遇到同样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.