error: norm of the gradient is inf

66 views
Skip to first unread message

Zeyu Sun

unread,
Sep 29, 2021, 2:14:26 AMSep 29
to Biogeme
Dear Developer,

I have problems estimating NL model. Basically, I have numerically generated a simple data file and apply biogeme to estimate parameters (more like a short testing code). However, it keeps giving me the following error message:
-----------------------------------------------------------------------------------------------------
..
..
..
biogemeError: The norm of the gradient is inf: g=[-1.79769313e+308 -1.79769313e+308 -1.79769313e+308 -1.79769313e+308 -1.79769313e+308]
-----------------------------------------------------------------------------------------------------

(PS: I have successfully run the sample code with optima.dat provided by you and it worked.)

My initial thought was that the numerical data I have generated is unfortunately bad for the estimation which causes this numerical issue. But two of my colleagues ran the same code (with same seeds) and managed to get their results.

I have also used 'conda update --all' to keep it updated. It is clearly my local problem because the same code went well on other computers but I am not sure where the problem may possible be at. I am testing the code on 'MacOS Big Sur, version 11.4', but I do not think that the system matters.

Best,
Zeyu




Bierlaire Michel

unread,
Sep 29, 2021, 2:17:47 AMSep 29
to sunze...@gmail.com, Bierlaire Michel, Biogeme
There is something wrong indeed. What are the starting values of the nesting parameters? They should be 1.0.

Start by estimating a logit model, and use the estimated coefficients as starting values for your NL model.

Now, if the same code actually runs on other computers, create a new clean environment, and try to run it there.

 

--
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/1bc0333d-a6c9-48cd-8d62-6d6c033071ccn%40googlegroups.com.

Zeyu Sun

unread,
Sep 29, 2021, 8:11:46 AMSep 29
to Biogeme
Thank you for the quick reply.

I am actually confused about the nesting parameters. Generally speaking, for a NL model, a negative dissimilarity parameter would lead to a wrong estimation. For a positive dissimilarity parameter, it is interpretable for (0,1] and not interpretable (in general cases) when it is larger than 1. Of course, when all these parameters are 1, the NL model reduces to the MNL model. I noticed that even in the example (https://www.youtube.com/watch?v=vEhvf54IKvs), the estimated nesting parameter is more than 1. I would like to clarify with you that the nesting parameter you mentioned (also coded in the biogeme package) is the reciprocal of the dissimilarity parameter that we often see in NL models, isn't it?

Best regards,
Zeyu

Bierlaire Michel

unread,
Sep 29, 2021, 10:53:37 AMSep 29
to sunze...@gmail.com, Bierlaire Michel, Biogeme
The ratio mu / mum must indeed be between 0 and 1. mu is normalized to one. Therefore, the nest parameters mum must be larger than one.
See http://biogeme.epfl.ch/examples/swissmetro/09nested.py
You can also change the normalization, but I do not recommend it.
See http://biogeme.epfl.ch/examples/swissmetro/10nestedBottom.py
> To view this discussion on the web visit https://groups.google.com/d/msgid/biogeme/f6807b41-126d-41b3-b539-f94f04d2c4d2n%40googlegroups.com.

Mirka

unread,
Oct 26, 2021, 8:38:35 AMOct 26
to Biogeme
Hello,

I have been experiencing the same problem with a Mixed Logit. The set-up is correct and if I run the model on a subsample of choice situations, it provides me with reasonable results. The problems begin when I want to apply it on a bigger dataset. I do already use the start values from a MNL model I run before.

What can be other reasons for this error: biogemeError: The norm of the gradient is inf: g=[-1.79769313e+308 ......] to appear?

Thank you!

Best regards,
Mirka

Bierlaire Michel

unread,
Oct 26, 2021, 8:41:38 AMOct 26
to miroslawa...@gmail.com, Bierlaire Michel, Biogeme

On 26 Oct 2021, at 16:37, Mirka <miroslawa...@gmail.com> wrote:

Hello,

I have been experiencing the same problem with a Mixed Logit. The set-up is correct and if I run the model on a subsample of choice situations, it provides me with reasonable results. The problems begin when I want to apply it on a bigger dataset. I do already use the start values from a MNL model I run before.

What can be other reasons for this error: biogemeError: The norm of the gradient is inf: g=[-1.79769313e+308 ......] to appear?

It means that there is a numerical issue. 

If it works for a subsample, it may be the case that your model specification is correct, but you have some issue in the data.
In order to investigate that, use the simulation feature of Biogeme to calculate the contribution to the loglikelihood of each observation. It may help to identify which piece of data is causing the problem.

Another possibility is that you do not use enough draws for the Monte Carlo integration.


Mirka

unread,
Nov 2, 2021, 6:56:58 AMNov 2
to Biogeme
Thank you. I am getting acquainted with the Simulation tool and I am looking at the probabilities. I am wondering if looking at another values would be more beneficial and if you can suggest some?

Also, the model that is problematic and produces the error contains panel information - can you suggest how to incorporate this information in the Simulation tool? For now I am just doing the following:

probs = MonteCarlo(models.logit(V, av, choice))
simulateCol = {"probability": probs}

biogemeSimMTName = bio.BIOGEME(database, simulateCol)
Simulatedresults = biogemeSimMTName.simulate(theBetaValues= MNL_RESULTS  )  

Thank you.

Sending best regards,
Mirka

Bierlaire Michel

unread,
Nov 2, 2021, 7:02:14 AMNov 2
to miroslawa...@gmail.com, Bierlaire Michel, Biogeme
Yes, the probabilities are what you need. 
What you are looking for are probabilities close to zero. Indeed, when you take the log, it generates numerical issues.

The current version of biogeme does not simulate panel models. Or, if you need to do that, you need to reorganize the data in order to have one row per individual, and rewrite the model. 

Actually, the version of the software that is in the “working” brnch on github has this feature implemented, and partially tested. You may want to try it if you need it. 


Reply all
Reply to author
Forward
0 new messages