Repository navigation
Penalized mle scad rebased2 - #4576
Conversation
|
This pull request introduces 2 alerts when merging 6c9f896 into 40e4f56 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
looks better than I thought
|
| if pen_weight is None: | ||
| pen_weight = self.pen_weight | ||
|
|
||
| sc = super(PenalizedMixin, self).scoreobs(params) |
There was a problem hiding this comment.
Why does this not fail?
scoreobs should be score_obs
I think this is only used in the sandwich cov, so the robust sandwich cov_ types will use the unpenalized score_obs?
|
This pull request introduces 2 alerts when merging c2c4c60 into 40e4f56 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
tests fail with scipy <= 0.17 with I guess convergence problems with bfgs. next I'm renaming scoreobs. I verfied that renaming it, runs it (and would raise exception in super().scoreobs) possible source of bug: |
|
This pull request introduces 2 alerts when merging 656a301 into 40e4f56 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
currently there are only test classes for Logit and Poisson, not for GLM |
|
This pull request introduces 2 alerts when merging bce88bd into 40e4f56 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
bce88bd to
7d778f9
Compare
|
This pull request introduces 2 alerts when merging 7d778f9 into 465d1b3 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
7d778f9 to
297805b
Compare
|
This pull request introduces 2 alerts when merging 297805b into 465d1b3 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
last change added GLMPenalize test If I add interesting observation (I don't have any intuition) |
|
maybe a new compat issue with numpy in VAR irf errband mc (likely float index) on a travis 2.7 investigate tomorrow it it persists |
297805b to
a0b4283
Compare
Codecov Report
@@ Coverage Diff @@
## master #4576 +/- ##
==========================================
+ Coverage 80.32% 80.48% +0.16%
==========================================
Files 564 567 +3
Lines 85747 86707 +960
Branches 9685 9772 +87
==========================================
+ Hits 68872 69787 +915
- Misses 14653 14674 +21
- Partials 2222 2246 +24
Continue to review full report at Codecov.
|
|
This pull request introduces 2 alerts when merging a0b4283 into 3d87728 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
a0b4283 to
c3675fc
Compare
|
This pull request introduces 2 alerts when merging c3675fc into 3d87728 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
| cls.res2 = modp.fit(method='bfgs', maxiter=100, disp=0) | ||
|
|
||
| mod = PoissonPenalized(y, x, penal=cls.penalty) | ||
| #mod.pen_weight *= 1.5 |
There was a problem hiding this comment.
pls delete commented-out
There was a problem hiding this comment.
I leave it as reminder that we use a different pen_weight now
| def _initialize(cls): | ||
| y, x = cls.y, cls.x | ||
| modp = PoissonPenalized(y, x[:, :cls.k_nonzero], penal=cls.penalty) | ||
| modp.pen_weight *= 10 # meed to penalize more to get oracle selection |
|
|
||
| mod = LogitPenalized(y, x, penal=cls.penalty) | ||
| #mod.pen_weight *= 1.5 | ||
| #mod.penal.tau = 0.05 |
There was a problem hiding this comment.
pls delete commented-out
| assert_equal(self.res1.bse[self.k_nonzero:], 0) | ||
|
|
||
|
|
||
| # the following classes are copies of Poisson with model adjustments |
There was a problem hiding this comment.
this same comment occurs on L384. is it accurate/needed in both places?
There was a problem hiding this comment.
reminder that we might be able to parameterize this better with less code duplication
(but I don't change the structure in this PR.)
| def _initialize(cls): | ||
| y, x = cls.y, cls.x | ||
| x = x[:, :4] | ||
| offset = -0.25 * np.ones(len(y)) # also check offset |
There was a problem hiding this comment.
Not clear what this comment means. Is it saying that this test class exists to make sure tests are run with non-None offset?
There was a problem hiding this comment.
The test is for binomial count, but as extra we also check the offset
| pen = smpen.L2ContraintsPenalty(restriction=restriction) | ||
| mod = GLMPenalized(y, x, family=family.Gaussian(), | ||
| penal=pen) | ||
| # make pen_weight large to force redundant to close to zero |
There was a problem hiding this comment.
Does multiplying by 1 (next line) accomplish the goal described in this comment?
| mod = GLMPenalized(y, x, family=family.Gaussian(), | ||
| penal=pen) | ||
| # make pen_weight large to force redundant to close to zero | ||
| mod.pen_weight *= 1 |
There was a problem hiding this comment.
Is changing model.pen_weight in-place going to be an encouraged user behavior? If so, the pen_weight in place as of model.fit should be attached to the Result object.
| def setup_class(cls): | ||
| x0 = np.linspace(-0.2, 0.2, 11) | ||
| cls.params = np.column_stack((x0, x0)) | ||
| cls.pen = smpen.L2() No newline at end of file |
There was a problem hiding this comment.
missing newline at end of file
| # If self.exposure exists, it will already be in logs. | ||
| exposure = getattr(self, 'exposure', 0) | ||
| # the following is copied from GLM predict (without family/link check) | ||
| # Use fit offset if appropriate |
There was a problem hiding this comment.
(Not necessarily for this PR) if this is used multiple times, it may merit a helper method. Especially since IIRC there are some TODO notes regarding how to keep track of what has and has not been logged.
|
Generally looks good. The only non-formatting issue I have is a mutability/re- |
|
@jbrockmendel Thanks for reviewing. |
eed924b to
4ece026
Compare
|
This pull request introduces 2 alerts when merging 4ece026 into ec3b6d0 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
I missed two or three CLN, but maybe I don't bother anymore. |
|
all green, merging |
another rebase, rebased #3677, which is a rebase of #2374
new PR because an error when running the test might be a incorrect merge conflict resolution.
I haven't looked at any details yet, I just want to see how "bad" it is.
some of the generic results creation code in this branch might be outdated by now, or not my preferred design anymore
i.e. #2393 still has no clean solution, AFAIK
Design issues
transformed params might need a more closer look (e.g. NegativeBinomial)
I fixed it in the unit test, which is mostly checking internal structure, i.e. which start_params was used.
But I don't know if any code outside on unit tests will need to handle parameters that are transformed during the optimization.
possible source of bug:
if score is computed as sum(score_obs) in the super model class, then we might be adding the penality twice, once in score_obs (called on the final class) and once score (when final class calls super().score)
GLM uses sum(score_obs) after refactoring in 0.9
This looks like a serious problem now, and I don't see a clean way of working around it.
We would need a flag or keyword to tell whether we should add the penalty in score_obs or not.
However, a keyword in score_obs with a default like penal=None does not work, because we want no penal if score_obs is called from score, and we need penalization if score_obs is called to create cov_params with robust cov_type.
The same might happen if loglike/loglike_obs is used.
Short term workaround: score is NOT allowed to use score_obs, e.g. use extra helper method
_score_obsin GLM that is called by bothscoreandscore_obsDONE this in GLM
inheritance and tsa
The new methods,
_fit_zerosand_fit_collinearare inbase.LikelihoodModeland so they will also be inherited by tsa models which might not make much sense, and most likely will not work anyway.-> maybe use a pure Mixin class without method overlap for those extra methods and add to top level subclasses like DiscreteModel and GLM, and RLM, and GenericLikelihoodModel... Or, create a new intermediate class for non-tsa likelihood models.
df_effective, aic, bic
In order to be able to use information criteria like aic, we need effective degrees of freedom, or effective variable count. I don't know how we should define this for general MLE.
I don't remember the details: For Gauss-Newton Regression we can get the linear model analog which might have just the hessian, e.g. something like
(score_obs * (hessian dot score_obs.T).T).sum(1)in analogy to the hat matrix and its trace.standardization versus weights
Often exog are standardized or rescaled to make the relative weights less scale dependent. This is up to the user, but rescaled exog will not have nice interpretable params. For that case we could also to the rescaling internally and backtransform the result, as in
fit_transformedidea. Alternatively, we can choose weights proportional to exog.std(0) in the univariate case, but full prior covariance matrix (arbitrary linear restrictions) needs to be defined by the user or by statsmodels for built-in shrinkage targets, e.g. spline penalization or penalization of categorical exog.