Faster Empirical Cumulative Distribution Function (ECDF)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 9 Fév 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
le 9 Fév 2025
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Piecewise Linear Distribution dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!