Faster Empirical Cumulative Distribution Function (ECDF)
Ältere Kommentare anzeigen
Hello everyone!
Im trying to speed up my bivariate ecdf code. Suppose we have data points and points for ecdf calculation:
data = rand(10000,2);
u = rand(1000,2);
Then to calculate bivariate ecdf i use code:
ECDF = squeeze(sum(all(permute(bsxfun(@le, data, permute(u, [3,2,1])), [2,1,3])))) / n;
How can i speed up my code? Dramatically, if possible. I've tried this but with no luck:
[u1,pos1] = sort(u(:,1)); [~,pos1] = sort(pos1);
[u2,pos2] = sort(u(:,2)); [~,pos2] = sort(pos2);
h = histcounts2(data(:,1),data(:,2),[0;u1],[0;u2],'Normalization','cdf');
ECDF = h(Sub2Ind([1000,1000],[pos1,pos2]));
2 Kommentare
Walter Roberson
am 9 Feb. 2025
You would have to time it to be sure, but possibly
ECDF = squeeze(sum(all(permute(data <= permute(u, [3,2,1]), [2,1,3])))) / n;
might be faster.
There are some situations in which bsxfun is faster, but there are also situations in which implicit expansion is notably faster.
Alex
am 9 Feb. 2025
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Piecewise Linear Distribution finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!