Speed up for loop in this code for calculating mutual information (maybe using GPU computing)
Show older comments
So I want to use the code given HERE where we use the Kraskov estimation procedure to estimate the mutual information between two time series (for more information see Ref: Kraskov, Alexander, Harald Stögbauer, and Peter Grassberger. "Estimating mutual information." Physical review E 69.6 (2004): 066138).
Whilst the code seems to work fine for my uses, because of the length of time series and the amount of different time series (I am calculating mutual information between pairs of many different time series) I have, the code runs too slowly. I ran the code profiler in MATLAB and seems to be the case that the following section code in the function provided in the link is causing the slowdown:
% compute distance between each sample and its k-th nearest neighbour
dz = zeros(nObs, nObs);
dx = zeros(nObs, nObs);
dy = zeros(nObs, nObs);
for i = 1:nObs
for j = 1:nObs
dx(i,j) = sqrt(sum((X(i, :) - X(j, :)).^2));
dy(i,j) = sqrt(sum((Y(i, :) - Y(j, :)).^2));
dz(i,j) = max([dx(i, j), dy(i, j)]);
end
end
Is there any way to speed this up? I was thinking maybe a GPU based total/partial solution might be feasible/offer a sufficient speed up. Any alternative suggestions would be very helpful (maybe parallelsing and using a parfor loop instead, although the speed up would be less and would make my future projects more complicated). I am currently using MATLAB 2016b.
3 Comments
Rik
on 14 Jan 2018
It looks like this should be possible to speed up a lot with the use of functions like pdist (or pdist2) and possibly with meshgrid, but I can't wrap my head around how to achieve it.
Jan
on 14 Jan 2018
How log are the X(i, :)? It matters if X is a [10 x 10'000] or [10'000 x 10] matrix.
Accepted Answer
More Answers (0)
Categories
Find more on Big Data Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!