You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by naftaliharris <gi...@git.apache.org> on 2014/06/12 00:48:51 UTC
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
GitHub user naftaliharris opened a pull request:
https://github.com/apache/spark/pull/1057
Check if margin > 0, not if prob > 0.5
This avoids an unnecessary computation and also possible math overflow errors.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/naftaliharris/spark patch-1
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/1057.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1057
----
commit a77bb6f4ef335d7892d292333a84e24e28bea048
Author: Naftali Harris <na...@gmail.com>
Date: 2014-06-11T22:48:32Z
Check if margin > 0, not if prob > 0.5
This avoids an unnecessary computation and also possible math overflow errors.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by naftaliharris <gi...@git.apache.org>.
Github user naftaliharris commented on the pull request:
https://github.com/apache/spark/pull/1057#issuecomment-50508305
My point actually is that you get OverflowError's if margin is too large, for example:
```python
>>> from math import exp
>>> margin = -1000
>>> prob = 1/(1 + exp(-margin))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: math range error
>>>
```
This actually happened to me, which is how I saw this issue.
There are (at least) two ways to solve this: One is to check margin instead of prob; this has the advantage of also saving a computation. Even if you allow the user to specify the probability threshold p at some later date, you can just change the margin cutoff from 0 to log(p/(1-p)).
The second solution is to replace math.exp with np.exp, which gives a warning rather than an exception:
```python
>>> import numpy as np
>>> margin = -1000
>>> prob = 1/(1 + np.exp(-margin))
__main__:1: RuntimeWarning: overflow encountered in exp
>>> prob
0.0
>>>
```
For robustness of the code, perhaps you should at least do that.
Thanks!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:
https://github.com/apache/spark/pull/1057#issuecomment-45810663
Can one of the admins verify this patch?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on the pull request:
https://github.com/apache/spark/pull/1057#issuecomment-50433121
I think we should keep it as it is now and add support for setting thresholds.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by naftaliharris <gi...@git.apache.org>.
Github user naftaliharris closed the pull request at:
https://github.com/apache/spark/pull/1057
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by mateiz <gi...@git.apache.org>.
Github user mateiz commented on the pull request:
https://github.com/apache/spark/pull/1057#issuecomment-50429657
@mengxr what do you think about this?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by mateiz <gi...@git.apache.org>.
Github user mateiz commented on the pull request:
https://github.com/apache/spark/pull/1057#issuecomment-50514187
That makes sense. I believe this was fixed just recently in here though: https://github.com/apache/spark/pull/1493. Does the fix look okay to you?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by mateiz <gi...@git.apache.org>.
Github user mateiz commented on the pull request:
https://github.com/apache/spark/pull/1057#issuecomment-53972967
Hey @naftaliharris, might closing this pull request now that this has been fixed in other PRs?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by naftaliharris <gi...@git.apache.org>.
Github user naftaliharris commented on the pull request:
https://github.com/apache/spark/pull/1057#issuecomment-50520177
Yeah, that fixes the overflow errors! The second probability calculation has some slight numerical issues, (see in-line comment), but not a huge deal.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by naftaliharris <gi...@git.apache.org>.
Github user naftaliharris commented on the pull request:
https://github.com/apache/spark/pull/1057#issuecomment-53973576
@mateiz oh yeah, no problem. Thanks again for the fixes!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: Check if margin > 0, not if prob > 0.5
Posted by mateiz <gi...@git.apache.org>.
Github user mateiz commented on the pull request:
https://github.com/apache/spark/pull/1057#issuecomment-50429778
Actually the Python version of this code seems like it needs to be brought in line with the threshold API added to Java / Scala. After that, the change won't work any more, though it is correct for threshold = 0.5.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---