Repository navigation
REF: implement _get_start_params - #5205
jbrockmendel wants to merge 2 commits into
Conversation
| if start_params is None: | ||
| offset = getattr(self, "offset", 0) + getattr(self, "exposure", 0) | ||
| if np.size(offset) == 1 and offset == 0: | ||
| offset = None |
There was a problem hiding this comment.
Here and below these were apparently copy/pasted from discrete_model, are not actually necessary.
| return result[0] if transform else result | ||
|
|
||
| def _get_start_params(self): | ||
| def _get_start_params(self, **kwargs): |
There was a problem hiding this comment.
kwargs added to keep the signature consistent
| a = ((resid**2 / mu - 1) * mu**(-q)).sum() / df_resid | ||
| return a | ||
|
|
||
| def _get_start_params(self, **kwargs): |
There was a problem hiding this comment.
Really similar to the version above; in the future there may be room for de-duplication
e8f3829 to
0cf9af8
Compare
|
can be reviewed and used during the next discrete or GenericLikelihood review and refactoring. |
|
Hmm the failing test is |
695a97b to
31aa55a
Compare
| ValueError if start_params cannot be found. | ||
| """ | ||
| if hasattr(self, 'start_params'): | ||
| start_params = self.start_params |
There was a problem hiding this comment.
This line exists in LikelihoodModel.fit ATM. If it is never hit, we should consider removing this usage.
There was a problem hiding this comment.
Is tt never hit in the existing tests, or unhittable? I agree with @ChadFulton that sv should be user settable, ideally.
There was a problem hiding this comment.
It can be hit by setting model.start_params = foo before calling model.fit(...), but this can also be accomplished by passing start_params=foo to model.fit.
There was a problem hiding this comment.
attributes or methods like this are or were for subclassing.
e.g. a subclass of GenericLikelihoodModel can specify appropriate start_params without having to overwrite the fit method.
There was a problem hiding this comment.
This side-note can be put on the back-burner. This PR leaves the logic unchanged, so GenericLikelihoodModel subclasses can keep doing whatever they want.
|
I'm not opposed to pulling out the starting parameters defaults, but I would argue that it's better to expose it as public rather than private. In state space, we just use a |
@ChadFulton You're suggesting making the |
|
don't change this without agreement across models and maintainers afaik, we never agreed on a signature or structure for this common across models |
Codecov Report
Continue to review full report at Codecov.
|
|
@ChadFulton are you ok with the “private for now so we keep the option to make public later” approach? |
|
I guess maybe that's okay, but I don't think this is quite the right part to excise from and I think that this part could be put in Also, I think we should not have arguments for getting the starting parameters (i.e. the method should not include |
Can you expand on this? I'm not sure I understand. The difference between what you block-quoted and the base class implementation is just the check for
The issue with this is that in
Is the availability for subclasses to override materially different for method vs property?
This seems backwards to me. I agree that the hasattr check is "about the process of selecting starting parameters", but that's exactly the scope of Incidentally, I think I would be much happier if |
|
@ChadFulton gentle ping; ok with private-for-now-revisit-later? |
31aa55a to
9b3b1e8
Compare
9b3b1e8 to
ee3b605
Compare
ee3b605 to
35cab45
Compare
|
This pull request fixes 2 alerts when merging 35cab45 into 52b142c - view on LGTM.com fixed alerts:
|
count_model implements a
_get_start_paramsmethod that gets called at the top offitifstart_params is None. This extends that pattern up to the base class. This is done in such a way that subclass authors can completely ignore this if they want, nothing has to be changed for subclasses.The big benefits of this:
fitwill in the future be able to override just_get_start_paramsoffsetvariables copy/pasted into count_model)