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
Zero and inf fix #4
Conversation
Maybe add a minimal regression test using X = np.array([[1, 1, np.NaN], [1, 1, 1]])
knnimpute.knn_impute_few_observed(X, np.isnan(X), k=1) ? |
Yup, good idea. It's in there. |
knnimpute/common.py
Outdated
# points considering themselves as neighbors | ||
for i in range(X.shape[0]): | ||
D[i, i] = np.inf | ||
max_dist = 1e6 * np.maximum(1, D.max()) |
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.
In [1]: np.array([1,2,np.inf]).max()
Out[1]: inf
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.
Oh right, I should do D[np.isfinite(D)].max()
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.
Err unless that makes D empty. That's impossible, right?
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.
Well, I guess you could play it very safe and have:
finite_distances = D[np.isfinite(D)]
if len(finite_distances) > 0:
max_dist = 1e6 * max(1, finite_distances.max())
else:
max_dist = 1e6
knnimpute/common.py
Outdated
# points considering themselves as neighbors | ||
np.fill_diagonal(D, np.inf) | ||
max_dist = 1e6 * np.maximum(1, D.max()) |
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.
If infinity is in the distance matrix, won't this make max_dist
infinity?
In [1]: np.array([1,2,np.inf]).max()
Out[1]: inf
missing_mask, | ||
verbose=False, | ||
min_dist=1e-6, | ||
max_dist_multiplier=1e6): |
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.
What does max_dist_multiplier
do?
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.
Oh right, it's supposed to be in the code instead of 1e6.
FYI, this is going to break the
|
One way to fix this for |
@iskandr I think I fixed that a few commits back?
|
Didn't see that, looks good.
…On Wed, Mar 15, 2017 at 5:12 PM, Sergey Feldman ***@***.***> wrote:
@iskandr <https://github.com/iskandr> I think I fixed that a few commits
back?
effective_infinity = D[0, 0] # since diagonal was replaced by max_dist
D_valid_mask = D < effective_infinity
valid_distances_per_row = D_valid_mask.sum(axis=1)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC9OQ1go7tRFllxb9ImY030nog17Srjks5rmFQugaJpZM4Med2Z>
.
|
Test failure: |
That's weird. I fixed that:
|
Did you get the latest version? |
I took a peek at Travis but I guess it's behind on builds. Wonder why it's so slow today. |
Not sure which library this bubbles up from, but we get a warning on Python 2.7:
Possibly fixed by depending on https://pypi.python.org/pypi/backports.functools_lru_cache/1.3? I can look into it later. |
Re: #3
@iskandr Please check it out to make sure these changes don't fundamentally break something else.