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

metricize uses various names for the same matrix #6

Closed
siudej opened this issue Mar 17, 2016 · 3 comments
Closed

metricize uses various names for the same matrix #6

siudej opened this issue Mar 17, 2016 · 3 comments

Comments

@siudej
Copy link
Contributor

siudej commented Mar 17, 2016

In metricize we have olddist=dist and the same with d_ij. These do not create copies of the original matrix, just fresh reference (pointer) to the same numpy array.

So the algorithm is changing entries of the matrix and uses the changed entries to compute other entries, in one while run. Also, olddist==dist is automatically true, so while never runs more than once.

Adding np.copy(dist) should fix this, but will also slow down the algorithm significantly. And it is already very slow.

@siudej
Copy link
Contributor Author

siudej commented Mar 17, 2016

This paper provides an algorithm to metricize and keep the correction minimal in L2 sense:
http://papers.nips.cc/paper/2598-triangle-fixing-algorithms-for-the-metric-nearness-problem.pdf
However, it requires a lot of memory to store all the correction terms.

@micah541
Copy link
Owner

I'm really confused as to when and why this happens. For example, I've
been using idist = dist before starting the Ricci flow, and then, after
doing the Ricci flow, printing idist. idist does not change, but dist
does change and I can see them right next to each other. This seems
to be my usual experience, so I'm not sure why it would be any different
here.

On 3/17/2016 9:12 AM, Bartek Siudeja wrote:

In |metricize| we have |olddist=dist| and the same with |d_ij|. These
do not create copies of the original matrix, just fresh reference
(pointer) to the same numpy array.

So the algorithm is changing entries of the matrix and uses the
changed entries to compute other entries, in one while run. Also,
|olddist==dist| is automatically true, so while never runs more than once.

Adding |np.copy(dist)| should fix this, but will also slow down the
algorithm significantly. And it is already very slow.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#6

@siudej
Copy link
Contributor Author

siudej commented Mar 18, 2016

You do
idist = sqdist
then before you initial_L1 you change sqdist.
Check if idist is also different. It should.

Later in the loop you have
sqdist = ne.evaluate(…)
This creates a completely new sqdist.

So in general
array = ..
first forgets whatever was in array, them creates something new.

In contrast:
array +=
array[:] =
ne.evaluate(…, out=array)
np.exp(…, out=array)
all replace values in the array.

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