Skip to content
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

all output are nan?! #1

Closed
Hualin opened this issue May 18, 2015 · 5 comments
Closed

all output are nan?! #1

Hualin opened this issue May 18, 2015 · 5 comments

Comments

@Hualin
Copy link

Hualin commented May 18, 2015

hey, thanks for you code. but I run the sammontest.py, both raw and distance output are nan, because E-E_new array is all nan.

at first glance i am not sure where to fix it, since there Dinv but you catch the inf error and replace it with 0.

@tompollard
Copy link
Owner

Hi Hualin, thanks for your message. I haven't looked at the code in a while, but I'll check this out when I get a chance. The code could do definitely do with some cleaning up.

The functionality was based on a Matlab function, which I remember would return NaNs in the following circumstances:

  • when there are two identical data points in the input array.
  • where there was a NaN in the input array

Do either of these issues apply here? i.e. please could you try removing (1) all NaNs from your input array and (2) any duplicate data points from your input array and let me know if this helps?

@Hualin
Copy link
Author

Hualin commented May 18, 2015

Cool, thanks for your fast reply. I guess sum of E_new or E is NaN because there was a value NaN in the array of E. Perhaps, delta = D-d.

I believe I should do some cleanup routine on distance matrix for D and d, it should fix something. I will be back here.

@Hualin
Copy link
Author

Hualin commented May 20, 2015

Hi there. I believe I got it fixed. Though I drop something:

  1. dropinputdist = "distance", always give vector space. (it can be hacked if one need to give distance matrix directly)
  2. drop euclid function, use scipy.spetial.distance.cdist instead.
  3. change some naming conversions: x => X, y=>Y, D=>xD, d=>yD, Dinv=>xDinv, dinv=>yDinv (the code below use these names)
  4. make some change about xDInv build:
    yD = distance.cdist(Y,Y)
np.fill_diagonal(xD, 1)
np.fill_diagonal(yD, 1)

xDinv = 1.0/xD
yDinv = 1.0/yD
np.fill_diagonal(xDinv, 0)
np.fill_diagonal(yDinv, 0)
xDinv[np.isnan(xDinv)] = 0
yDinv[np.isnan(yDinv)] = 0
xDinv[np.isinf(xDinv)] = 0
yDinv[np.isinf(yDinv)] = 0

and somehow. those changes make error gone! I didn't touch the optimisation process.

cheers,

@tompollard
Copy link
Owner

Thanks Hualin - please could you put the suggested changes into a pull request?

This was referenced Jun 9, 2015
tompollard pushed a commit that referenced this issue May 5, 2017
@tompollard
Copy link
Owner

This should have been addressed in the merged pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants