jpn-- / larch

Larch: a Python tool for choice modeling
http://larch.newman.me
GNU General Public License v3.0
41 stars 14 forks source link

Change Convergence Tolerance #1

Closed yue899889 closed 2 years ago

yue899889 commented 6 years ago

May I know what is the default setting for the convergence tolerance? Is there any way that I could make it large?

I am doing a 400+ choices simple MNL model, but the convergence tolerance reaches 0.0001 then goes back to large value for many more iterations and it seems never stop. Can I change it?

jpn-- commented 6 years ago

the default convergence tolerance on the maximize_loglike function is ctol=1e-6, which is applied to the function bhhh_tolerance. You can change it by giving a different value as a keyword argument 'ctol' to maximize_loglike.

If you experience convergence problems on an MNL model, it is often the case that the model is poorly specified (e.g., has too many alternative specific constants). This is especially true if you find the convergence criteria growing instead of shrinking. If you interrupt the model, are any of your parameters blowing up (huge positive or negative values)? If so, try changing your model specification.

deepakagrawal commented 6 years ago

I am facing a similar problem. I don't have any alternative specific constants. I don't have any parameters blowing up. However, I do see t-stat very low whenever max_loglike fails.

Here is the output

convergence tolerance 16.6
False
=================================================================================================================================
Model Parameter Estimates
---------------------------------------------------------------------------------------------------------------------------------
Parameter       InitValue       FinalValue      StdError        t-Stat          NullValue   
Ndays            0.0             0.321          -0.000535       -6.01e+02        0.0        
NR_LG            0.0            -0.288          -0.000504        5.71e+02        0.0        
CategoryLEG      0.0            -0.468          -0.00071         6.59e+02        0.0        
CategoryULCC     0.0             0.0            -0.00465        -0.0             0.0        
sin_dep1         0.0            -0.33           -0.000893        3.69e+02        0.0        
sin_dep2         0.0             0.0857          0.00109         78.6            0.0        
sin_dep3         0.0             0.106          -0.000469       -2.26e+02        0.0        
cos_dep1         0.0             0.163           0.000971        1.67e+02        0.0        
cos_dep2         0.0             0.0475          0.000103        4.61e+02        0.0        
cos_dep3         0.0             0.0649          0.000193        3.36e+02        0.0        
=================================================================================================================================
Model Estimation Statistics
---------------------------------------------------------------------------------------------------------------------------------
Log Likelihood at Convergence       -333342.98
Log Likelihood at Null Parameters   -346927.40
---------------------------------------------------------------------------------------------------------------------------------
Rho Squared w.r.t. Null Parameters  0.039
=================================================================================================================================
Latest Estimation Run Statistics
---------------------------------------------------------------------------------------------------------------------------------
Number of Iterations        4
Running Time                8.075   seconds
- setup                     0:00.98
- null_likelihood           0:00.06
- weight choice rebalance   0:00
- weight autorescale        0:00
- optimize:BFGS             0:06
- weight unrescale          0:00.02
- parameter covariance      0:01.02
- cleanup                   0:00
Notes                       automatically rescaled weights (total initial weight 88095 scaled by 0.00926273 across 816 cases)
Results                     failed
=================================================================================================================================
jpn-- commented 2 years ago

For posterity: this kind of error occurs when the model is poorly specified or otherwise fails to converge properly.