-
Notifications
You must be signed in to change notification settings - Fork 3.3k
add a fitting interface for simultaneous log likelihood and score, for lbfgs, tested with MNLogit #1161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a fitting interface for simultaneous log likelihood and score, for lbfgs, tested with MNLogit #1161
Conversation
related to issue #1141 |
@@ -1588,6 +1588,21 @@ def score(self, params): | |||
#NOTE: might need to switch terms if params is reshaped | |||
return np.dot(firstterm.T, self.exog).flatten() | |||
|
|||
def loglike_and_score(self, params): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: maybe not such a good idea, because your _fit_mle_lbfgs covers several cases of loglike and score
Since this is mainly for optimization and doesn't affect other statistical results, I would define it in terms of the negative logliglihood nloglike_and_score
avoids the negation.
in statsmodels.base.model.GenericLikelihoodModel and subclasses, I used nloglike
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is GenericLikelihoodModel even used? I've run across swaths of statsmodels code that is either commented out or has comments like 'dead code below here' related to the generic likelihood model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenericLikelihoodModel is the rapid prototyping and development version. Most likelihood models grow up and then integrate into the LikelihoodModel hierarchy and don't subclass GenericLikelihoodModel.
GenericLikelihoodModel has more preconfigured or more general defaults than LikelihoodModel.
I think, you could try to special case it in line L378, if loglike_and_score are available, to make it used automatically. looks good so far. |
I'm not sure exactly what you mean here, but maybe you are talking about Regarding the comments about |
…y passing it a score function
Can you just point them out or open an issue for them. |
added as issue #1162 |
Is the Travis failure a known issue? ( |
I've tried closing and reopening to toggle Travis for the SVD convergence problem. On my system |
@josef-pkt Is there anything preventing merging of this PR? I think that the SVD non-convergence is some numpy bug, and I don't understand your comment about line 378. If you would like me to address that comment before merging, I might need more detail. Is it referring to this line https://github.com/argriffing/statsmodels/blob/907122b797b4bf19ad3cf5e25686bc40c4464c51/statsmodels/base/model.py#L378? |
@argriffing I didn't know this is ready for merge. I can look into it in a few hours. In the unit test you give |
@josef-pkt Thanks! The interface design could become clearer if we add interfaces to more solvers that use loglike+score but not hessian (e.g. tnc), and when more models provide the simultaneous calculations (maybe ARIMA). |
The latest build on master was without failure, so the svd failure is most likely in this PR common problem I have with svd failures is if a nan or inf sneaked into my numbers. |
extra_kwargs = dict((x, kwargs[x]) for x in names if x in kwargs) | ||
|
||
if extra_kwargs.get('approx_grad', False): | ||
score = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we removed the score if approx_grad
In my opinion the root of the So there are multiple ways to specify the gradient.
Of these options, (3) is best, followed by (1), and (2) is worst. We are currently using (2) for ARIMA, but I hope that fixing this does not fall in the scope of this PR. |
(We had a power outage all last evening and part of the night). I understand the principle, but I'm still not sure whether ARMA is or is not using the score method, and whether that default has been changed by this PR, leading to the SVD failure. Changing/Improving the score calculation for ARIMA is of course not required by this pull request. |
Yeah I think you're right. I'll change it back. |
It made TravisCI green. What I find strange is that it looks like the ARIMA estimation doesn't use "our" score, but the buildin of l_bfgs_b. Do I read this correctly? The svd failure with the different estimation settings might need investigation, but that's not part of this PR. I can merge this (after another brief look), if you want to use this for your low memory estimation, and we open a new issue for integrating this with automatic |
Yes, I believe so. In the old statsmodels code (and in its current restored version), ARIMA uses the internal gradient approximation of
You are suggesting to have the statsmodels machinery automatically detect a |
Yes, that was my first thought when I looked through this PR, automatically using Now, I think we better wait for Skippers outsourcing of the optimizer code. To make the optimizer code more generally available, we need to be able to specify the objective function and the score even if they are not lo
8000
glike and score. So, if you can do your low memory work with the changes in this PR, then I would postpone this integration until Skipper can also have a look at this, and can check how this works with his branch. |
@josef-pkt That sounds like a good plan. After this PR is merged I'll work on low memory modifications (or low memory subclasses, if a time/memory tradeoff is required) for MNLogit. By the way, I saw your mailing list question
and I'd suggest giving |
add a fitting interface for simultaneous log likelihood and score, for lbfgs, tested with MNLogit
Good, merged unit tests pass, and we will have another look later, see #1141 Thanks you |
…core add a fitting interface for simultaneous log likelihood and score, for lbfgs, tested with MNLogit
No description provided.