biogemeError: RandomVariable expression must be embedded into a integrate: omega_1 RandomVariable expression must be embedded into a integrate: omega_2 RandomVariable expression must be embedded into a integrate: omega_3

73 views
Skip to first unread message

sing leo

unread,
Aug 28, 2023, 2:38:38 AM8/28/23
to Biogeme

Dear Michel,  and all,

I hope this email finds you in good health. I am currently in the process of testing the incorporation of three latent variables into a Discrete Choice Model (DCM). However, I have encountered multiple challenges along the way. I am writing to seek your guidance and expertise in addressing these issues.

Issue 1: One of the primary hurdles I am facing involves the computation of integrals for each of the random variables within the DCM. Specifically, I am unsure about the validity of the following code segment:

integral_1 = Integrate(condlike * density_1, 'omega_1')
integral_2 = Integrate(condlike * density_2, 'omega_2')
integral_3 = Integrate(condlike * density_3, 'omega_3’)
loglike = log(integral_1 + integral_2 + integral_3)


Could you please provide insight into whether this approach is appropriate for calculating the integrals and overall log likelihood?

Issue 2: After implementing this approach, I encountered two bugs:

  1. An error message originating from src/biogeme.cc: "Biogeme exception: Error for data entry 4011: src/bioExprRandomVariable.cc:36: Biogeme exception: Null pointer: random variable value."
  2. An error message indicating a "biogemeError: RandomVariable expression must be embedded into an integrate: omega_1 RandomVariable expression must be embedded into an integrate: omega_2 RandomVariable expression must be embedded into an integrate: omega_3."

I believe these errors are related to the integration of the random variables. However, I am uncertain about the exact cause and how to resolve them.

Below is a snippet of the code where I define the random variables:

omega_1 = RandomVariable('omega_1')
omega_2 = RandomVariable('omega_2')
omega_3 = RandomVariable('omega_3’)
density_1 = dist.normalpdf(omega_1)
density_2 = dist.normalpdf(omega_2)
density_3 = dist.normalpdf(omega_3)
sigma_s_1 = Beta('sigma_s_1', 1, None, None, 0)
sigma_s_2 = Beta('sigma_s_2', 1, None, None, 0)
sigma_s_3 = Beta('sigma_s_3', 1, None, None, 0)


Your expertise would be incredibly valuable in helping me navigate through these complexities. If you require more specific information about the model setup or the code, I am more than willing to provide it.

Thank you very much for your time and assistance. I am eagerly anticipating your guidance.

Best regards, Leos

Michel Bierlaire

unread,
Aug 28, 2023, 4:15:36 AM8/28/23
to leo594...@gmail.com, Michel Bierlaire, Biogeme
Hi.

If you have more than one random variable in your model, use Monte-Carlo integration. The Integrate method uses numerical integration (using quadrature), and is not appropriate more multi-dimensional integrals.
Look at the examples online for guidance.
> --
> 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/0f26e47b-cd2d-4833-adeb-f8ce42b2dfe5n%40googlegroups.com.

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

Michel Bierlaire

unread,
Aug 29, 2023, 2:35:42 AM8/29/23
to leo594...@gmail.com, Michel Bierlaire, Biogeme
Please post your questions on the users’ group.

A tutorial on Monte-Carlo integration with Biogeme is available here: https://transp-or.epfl.ch/documents/technicalReports/Bier19.pdf

And, if you look at the examples for latent variables here https://github.com/michelbierlaire/biogeme/tree/master/examples/latent
you will find the two versions for the integral. Look at file names finishing by _mc.py


> On 29 Aug 2023, at 05:57, leo594...@gmail.com wrote:
>
> Dear Professor Michel,
> I hope this email finds you well. First and foremost, I want to express my gratitude for your previous guidance and support, which has enabled me to make progress in code development. However, I've encountered some uncertainties in the code and I'm hoping to receive some advice and guidance from you.
> To be specific, I am currently adapting the "latent04" case study in my code. I've noticed that the case study code does not touch upon concepts such as "Monte-Carlo integration" and "condlike." Nevertheless, I've come to realize that these two concepts seem to be relevant to the work I am undertaking in my project.
> I find myself perplexed about the correct usage of "Monte-Carlo integration." While I understand that it is a technique for estimating complex integrals using random sampling, its practical application within the code leaves me somewhat uncertain. I'm eager to understand how to integrate this technique into my code to better tackle computational challenges associated with my project.
> Additionally, concerning "condlike," although there isn't much information about this concept in the case study code, it appears to be a factor of significance in my work. I would greatly appreciate it if you could explain the role of "condlike" in this context and guide me on its proper implementation within the code.
> Your experience and insights are invaluable to me, and I believe that with your guidance, I can gain a clearer understanding of these concepts and effectively apply them in my code.
> Thank you very much for taking the time to read my email. I look forward to your response.
> Best regards,
> Leos
Reply all
Reply to author
Forward
0 new messages