Repository navigation
Conversation
|
Needs a test that exits here. |
Codecov Report
@@ Coverage Diff @@
## master #5585 +/- ##
=======================================
Coverage 82.03% 82.03%
=======================================
Files 588 588
Lines 93103 93103
Branches 10323 10323
=======================================
Hits 76379 76379
Misses 14359 14359
Partials 2365 2365
Continue to review full report at Codecov.
|
Thanks, let me add one and get back to you. I see the tests in the robust/tests directory; I need to figure out their data format and then add a test for x ~ x. |
|
You can simulate the data as part of the test, something like rs = np.random.RandomState(0)
x = rs.standard_normal(100)
y = x + 1e-16*rs.standard_normal(100) # or just y = xIt is best to use a dedicated RandomState so that the test is the same on every run. |
|
I don't think this can ever stop at this point since the initial criterial is always I think you always have to run a couple of iterations to know a model has converged. In particular on the first iteration,
is
which is always a nonstop. AFAICT The only way it could stop here would be is |
|
I think to beleive it has converged you need to estimate the model at least twice, so that is OK. An looking again, if maxiter == 0, then it will ignore this and always run one, so this check seems to be OK here. @jpfeiffg The only thing the test needs to do is to fit(maxiter=0) and verify that it exits immediately with iteration=1 |
|
Hey, thank you for the response. I'm sorry for the delay, I have been working on other stuff and found it hard to write the test :(. Are you sure the change is always a no-op? I added some prints to my test case (which is, fitting "a ~ b - 1" when a and b are both == range(10)). The _check_convergence call in this case is: It evaluates to True: So, I think if we believe that exiting after 1 iteration is a sensible thing to do here, then the code change in this pull request, is sensible. As to whether we should exit after 1 iteration, I don't know the module well enough. I see that we're attempting to re-weight the LS in the iteration which seems fine. The problem is, in my example where we are fitting X to itself, we divide by 0 in the wls_results.resid/self.scale line, because self.scale can be 0. Question for those who know the module well - does self.scale == 0 imply that we have in fact converged? |
|
I hadn't considered the Nan case, althiugh I would describe that as a
different bug, in particular this case should be explicitly exited rather
than relying a not (Nan comparison to an number)
…On Fri, May 10, 2019, 23:18 jpfeiffg ***@***.***> wrote:
Hey, thank you for the response. I'm sorry for the delay, I have been
working on other stuff and found it hard to write the test :(.
Are you sure the change is always a no-op? I added some prints to my test
case (which is, fitting "a ~ b - 1" when a and b are both == range(10)).
The _check_convergence call in this case is:
_check_convergence([inf, nan], 1, 1e-08, 50).
It evaluates to True:
_check_convergence([inf, nan], 1, 1e-08, 50) = not
(np.any(np.fabs(criterion[1] - criterion[0]) > 1e-08) and 1 < 50)
= not (np.any(np.fabs(nan - inf) > 1e-08) and 1 < 50)
not (np.any(np.fabs(np.nan - np.inf) > 1e-08) and 1 < 50)
True
np.nan > 1e-08
False
So, I think if we believe that exiting after 1 iteration is a sensible
thing to do here, then the code change in this pull request, is sensible.
As to whether we should exit after 1 iteration, I don't know the module
well enough. I see that we're attempting to re-weight the LS in the
iteration which seems fine. The problem is, in my example where we are
fitting X to itself, we divide by 0 in the wls_results.resid/self.scale
line, because self.scale can be 0.
Question for those who know the module well - does self.scale == 0 imply
that we have in fact converged?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5585 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABKTSROB7NEJXNH3D6KTNNTPUXYEDANCNFSM4HJOWNIQ>
.
|
|
Yes, scale=0 would always be converged since all errors are 0
…On Fri, May 10, 2019, 23:18 jpfeiffg ***@***.***> wrote:
Hey, thank you for the response. I'm sorry for the delay, I have been
working on other stuff and found it hard to write the test :(.
Are you sure the change is always a no-op? I added some prints to my test
case (which is, fitting "a ~ b - 1" when a and b are both == range(10)).
The _check_convergence call in this case is:
_check_convergence([inf, nan], 1, 1e-08, 50).
It evaluates to True:
_check_convergence([inf, nan], 1, 1e-08, 50) = not
(np.any(np.fabs(criterion[1] - criterion[0]) > 1e-08) and 1 < 50)
= not (np.any(np.fabs(nan - inf) > 1e-08) and 1 < 50)
not (np.any(np.fabs(np.nan - np.inf) > 1e-08) and 1 < 50)
True
np.nan > 1e-08
False
So, I think if we believe that exiting after 1 iteration is a sensible
thing to do here, then the code change in this pull request, is sensible.
As to whether we should exit after 1 iteration, I don't know the module
well enough. I see that we're attempting to re-weight the LS in the
iteration which seems fine. The problem is, in my example where we are
fitting X to itself, we divide by 0 in the wls_results.resid/self.scale
line, because self.scale can be 0.
Question for those who know the module well - does self.scale == 0 imply
that we have in fact converged?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5585 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABKTSROB7NEJXNH3D6KTNNTPUXYEDANCNFSM4HJOWNIQ>
.
|
|
OK. We could explicitly check for scale==0. I think what's happening in this case is that deviance is very large, NaN in my example when compiled with -copt=-mavx, or just large numbers when compiled normally. I think it makes sense to treat scale == 0 or scale ~ 0 identically? |
|
No, if the initial estimate of scale=0, then we don't necessarily have converged. based on what I remember Is perfect fit to 50% of the data a feature or a bug? |
|
@josef-pkt , thanks for the links to older bugs, the history / context is useful. I would agree that users usually don't want to get NaN back if they passed in reasonable data such as a perfect fit or 50%+ perfect fit. Can we reach agreement on what to do in this case, at an API level? If we agree on that I think it will be straightforward to make the code changes involved. I propose a good thing for RLM.fit(partial_perfect_fit) to do, is to proceed until we hit a scale of 0 since it's not meaningful. I would be love to hear other approaches since I'm not familiar with robust regression. I claim in general that we shouldn't return NaN here but would also be open to understanding why this is reasonable. Is there anyone else who should be brought in to comment? Besides @bashtage and @josef-pkt I see that @jseabold has done a lot of work in robust/ over time. |
|
When I cannot make up my mind, which happened in this case with 50% perfect fit, then I like to push it off to the user. So, I think we could add a keyword option to stop the iteration if estimated scale = 0. That would depend on the breakdown point of the chosen scale estimator or (maybe) initial scale estimator, around 50% for MAD and something higher for iqr. If scale=0, then we still have params, but I think all standard errors will be nan or zero. (I don't remember if I looked at that part, or if the references that I had used say anything about inference in the perfect fit case.) Correction after reading the docstring of RLM.fit again. If user specified MAD scale_est, then I also think it will have converged at perfect fit if the scale=0. IIRC, I didn't look much at that case because MAD has low efficiency as scale estimator, and I was more interested in cases where we don't have a very high breakdown point. (Default RLM is not really designed for high breakdown point, i.e. something close to 50%) so
|
|
Another option would be to mimic what R or Stata does in this case,
especially if they do the same thing.
…On Tue, May 21, 2019, 01:52 Josef Perktold ***@***.***> wrote:
When I cannot make up my mind, which happened in this case with 50%
perfect fit, then I like to push it off to the user.
So, I think we could add a keyword option to stop the iteration if
estimated scale = 0. That would depend on the breakdown point of the chosen
scale estimator or (maybe) initial scale estimator, around 50% for MAD and
something higher for iqr.
Huber scale is always nonzero, IIRC, but might have strange behavior if a
large fraction of observations has zero residuals and the others have
residuals with large magnitude, i.e. the distribution of the data is far
away from a normal distribution.
If scale=0, then we still have params, but I think all standard errors
will be nan or zero. (I don't remember if I looked at that part, or if the
references that I had used say anything about inference in the perfect fit
case.)
*Correction* after reading the docstring of RLM.fit again.
The default scale is MAD (and not HuberScale as I remembered). In the past
I was looking mainly at the case when initial scale estimate is MAD and
iteration scale estimate is HuberScale. IIRC
If user specified MAD scale_est, then I also think it will have converged
at perfect fit if the scale=0.
IIRC, I didn't look much at that case because MAD has low efficiency as
scale estimator, and I was more interested in cases where we don't have a
very high breakdown point. (Default RLM is not really designed for high
breakdown point, i.e. something close to 50%)
so
- if scale_est == 'mad' and scale==0, then stop as converged with
perfect fit.
- if scale_est == HuberScale and scale==0, then make continuation
depend on user option
default is to continue to convergence and handle initial estimated
scale=0 with something nonzero
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5585?email_source=notifications&email_token=ABKTSROOOG7HO6RTU3ILJGLPWNBVZA5CNFSM4HJOWNI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODV2OFGQ#issuecomment-494199450>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABKTSRLZDHN5LHHF6LJREZDPWNBVZANCNFSM4HJOWNIQ>
.
|
|
terminology: "exact fit property" I was rereading the sections in the book. It is defined as having at least the number of observations corresponding to the breakdown point in a linear subspace. AFAIR, M-estimator with Huber loss function does not have a breakdown point < 1. there is a new, Jan 2019, edition of the book using R instead of S with R package https://cran.r-project.org/web/packages/RobStatTM/index.html |
|
I saw this was referenced as a release blocker - I can work on this at some point but I don't have time to do anything in the near term. Happy to hand it off if that helps; if not, I may come back to it later. |
|
Would be nice to have the right fix, but not a blocker. |
|
What does R do in this data? Could just follow their lead. |
Ensure RLM doesn't crash if perfect fit Clean norms so that they don't crash either Avoid calculations the load to nan Improve testing of RLM Replace fabs with abs closes statsmodels#5585 closes statsmodels#1341 closes statsmodels#5878 closes statsmodels#5356 closes statsmodels#3319 xref statsmodels#55
Ensure RLM doesn't crash if perfect fit Clean norms so that they don't crash either Avoid calculations the load to nan Improve testing of RLM Replace fabs with abs closes statsmodels#5585 closes statsmodels#1341 closes statsmodels#5878 closes statsmodels#5356 closes statsmodels#3319 xref statsmodels#55
Ensure RLM doesn't crash if perfect fit Clean norms so that they don't crash either Avoid calculations the load to nan Improve testing of RLM Replace fabs with abs closes statsmodels#5585 closes statsmodels#1341 closes statsmodels#5878 closes statsmodels#5356 closes statsmodels#3319 xref statsmodels#55
Currently in robust_linear_model, we do one iteration, rescale, and then enter the iterations loop.
This can be a problem if the first iteration is a perfect fit or nearly a perfect fit. When dividing by scale, we get either NaN or an ill-conditioned problem.