The norm of the gradient is inf

413 views
Skip to first unread message

Zeyu Sun

unread,
Nov 25, 2021, 12:17:47 AM11/25/21
to Biogeme
Dear developer,

I think that I have encountered a bug, which I have seen several times in different operating systems.

It goes like a numerical error, which states
biogemeError: The norm of the gradient is inf:......

My initial thought was that my dataset for the estimation was not good enough which led to this numerical error. Then, I changed back to my previous setting, which successfully gave me a result before. However, once this error came out, no matter what data I was trying, the error message remained even with the dataset that previously worked.
---------------------------------------------------------------------------------------------------------------
Regarding to my previous emails, I found this error on macOS. This time, I am using Windows and find the same error.

I am wondering is there anybody else reported similar error before. I suspect that during some process, it changes the setting of some in-built functions and never has a chance to reset it so later on it keeps showing the same error even with a workable dataset.
---------------------------------------------------------------------------------------------------------------
Is there a way to fully reset biogeme package to default? I am not sure whether doing this would solve the issue.

Thank you!
Zeyu



Bierlaire Michel

unread,
Nov 25, 2021, 12:23:03 AM11/25/21
to sunze...@gmail.com, Bierlaire Michel, Biogeme
It is not a bug. It means that calculating the loglikelihood and its gradient generates numerical issues.
If it is at the first iteration, it is likely to be due to the starting value of the parameters. Investigate using simulation.

If it is during the course of the algorithm, you may want to define tighter bounds on the parameters, so that they don’t take absurdly large values. 

--
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/1967eeea-d537-4383-9231-53295a998188n%40googlegroups.com.

Zeyu Sun

unread,
Nov 25, 2021, 1:08:07 AM11/25/21
to Biogeme
Hi Michel,

Thank you for the reply but I am a bit confused. I have tested the same code before and after (the error). Before I first time saw the error, the code worked well and the estimation completed successfully. Then, I have tried to edit the code a little bit and it turned out not workable (the error came out). Then I opened the first code, which worked the at first time and ran it. It started to gave the error, too.

In between running the same code twice, I only ran a different code which gave me a norm error. I did not change any setups. I mean... if it is a numerical issue due to calculating gradient, should not the same code give me the same result (instead of a good result and an error)?

Best,
Zeyu

Bierlaire Michel

unread,
Nov 25, 2021, 1:13:17 AM11/25/21
to sunze...@gmail.com, Bierlaire Michel, Biogeme
Try to run it in a clean environment. You’ll see if it is an installation problem or a numerical issue. 

Zeyu Sun

unread,
Nov 25, 2021, 2:48:47 AM11/25/21
to Biogeme
Hi Michel,

Your answer is totally correct. I have changed some starting points and upper/lower bounds then I managed to have a result on my PC.

However, I am not sure whether the following is natural. Although the code works when I specify a good starting point and bounds, it actually works on other PC without this specification. Is it normal that the same code may provide different outcomes on different PC?

I am sorry that this question may sound silly but it is important because we want to make sure the experiment can be reproduced with the same code on any PC.

Thank you!
Zeyu

Bierlaire Michel

unread,
Nov 25, 2021, 5:46:50 AM11/25/21
to sunze...@gmail.com, Bierlaire Michel, Biogeme
On 25 Nov 2021, at 10:54, Zeyu Sun <sunze...@gmail.com> wrote:

Hi Michel,

Your answer is totally correct. I have changed some starting points and upper/lower bounds then I managed to have a result on my PC.

However, I am not sure whether the following is natural. Although the code works when I specify a good starting point and bounds, it actually works on other PC without this specification. Is it normal that the same code may provide different outcomes on different PC?

Yes. Floating point arithmetic may slightly vary from one processor to the next, and from one compiler to the next.  And if the problem has numerical difficulties, the outcome can be very different. 

Reply all
Reply to author
Forward
0 new messages