Faster Empirical Cumulative Distribution Function (ECDF)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 9 de Feb. de 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
el 9 de Feb. de 2025
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Piecewise Linear Distribution en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!