필터 지우기
필터 지우기

Euclidean Distance (huge number of vectors)

조회 수: 6 (최근 30일)
Vishnu Sreekumar
Vishnu Sreekumar 2012년 4월 30일
I have a 70,000 x 300 matrix. These are basically 70,000 vectors of 300 elements each. I need the distance matrix (distances between each pair of vectors). It is too large to just use pdist. Does anybody have general programming tips on how to handle this problem?

답변 (4개)

Richard Brown
Richard Brown 2012년 4월 30일
You could do something like this and leave it running overnight :| Obviously you'd define your histogram edges to be relevant to the vectors you were using. The disp statement is purely there as a primitive progress bar
n = 70000;
x = rand(300,n);
edges = linspace(0, 10, 100);
edges2 = edges.^2;
h = zeros(1, numel(edges));
for i = 1:n-1;
d2 = sum(bsxfun(@minus, x(:, i+1:n), x(:, i)).^2);
h = h + histc(d2, edges2);
disp(100*i/n)
end
And then to display it,
bar(edges, h, 'histc')
EDIT Adjusted to reflect Walter Roberson's comment below to eliminate the use of sqrt
  댓글 수: 3
Richard Brown
Richard Brown 2012년 4월 30일
Good point, edited accordingly
Sean de Wolski
Sean de Wolski 2012년 5월 1일
Nice!

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2012년 4월 30일
That's 70,000 * 69,999 / 2 = 2.4 billion distances. What are you going to do with all those? Can you figure out a way where you only need to calculate some specific distances for some limited number of specific circumstances/criteria rather than all of them? Do you really need all 2.4 billion of them?
  댓글 수: 2
Vishnu Sreekumar
Vishnu Sreekumar 2012년 4월 30일
I basically need a cumulative histogram of these 2.4 billion distances. So I do need access to all 2.4 billion distances but only to be able to count them. So I'm sure there is a way to do this as smaller computations (and then store them away until I need to count the distances, which I can do one matrix at a time too, it doesn't all have to be in memory at the same time).
Image Analyst
Image Analyst 2012년 4월 30일
If there is not pattern and they're more or less uniformly distributed, then you would probably get the same essential shape of the histogram after only a few thousand distances. You can do that for a few thousand of them, then a few million, and see if the shape of the histogram changes substantially. If the histogram shape equilibrates/stabilizes after a few thousand calculations, why do all 2.4 billion of them?

댓글을 달려면 로그인하십시오.


Sean de Wolski
Sean de Wolski 2012년 4월 30일
Break it into a bunch of smaller problems and solve each one (based on what you want as an end result).
Some questions to ask yourself: Do the vectors follow any pattern? Could you downsample or merge some of them? What are you doing with the results?
The more background you can give us the more we can help.

Vishnu Sreekumar
Vishnu Sreekumar 2012년 4월 30일
I need to then count up these distances (basically a histogram of distances). Hope that simplifies the question a little. I was thinking I break the matrix into smaller matrices and then go from there but I'm still not very clear on how to proceed. This is basically a question on how to deal with memory and I'm not a very experienced programmer. Hence seeking advice from the collective wisdom here.

카테고리

Help CenterFile Exchange에서 Hypothesis Tests에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by