Borrar filtros
Borrar filtros

Why is betapdf so slow?

1 visualización (últimos 30 días)
William Wooley
William Wooley el 9 de Dic. de 2015
Comentada: Jeff Miller el 19 de Jul. de 2020
I'm running some code where I need to evaluate several beta pdfs per iteration. When I profile my code I notice that the four calls to betapdf consume about one-third (0.012s out of 0.03s total) of the run-time.
It seems that betapdf is implemented as an .m file rather than mex. Is there a mex'ed (or just faster) version of betapdf out there?
  2 comentarios
James Heald
James Heald el 17 de Jul. de 2020
i also need a faster version of this. it is prohibitively slow for the arrays im working with. it is about 10 x slower than normpdf
Jeff Miller
Jeff Miller el 19 de Jul. de 2020
Cupid is a bit faster if the distribution parameters are fixed:
n = 1000000;
a = 3;
b = 2;
x = betarnd(a,b,n,1);
tic
xpdf = betapdf(x,a,b);
toc
% Elapsed time is 0.306104 seconds.
cupidbeta = Beta(a,b); % Using Cupid
tic
xpdfcupid = cupidbeta.PDF(x);
toc
% Elapsed time is 0.090670 seconds.

Iniciar sesión para comentar.

Respuestas (1)

John D'Errico
John D'Errico el 9 de Dic. de 2015
betapdf is as it is, because it is. Writing it as an m-file versus a mex-ed file has advantages, but also disadvantages. Yes, were MATLAB composed of entirely compiled code, those compiled pieces would usually run faster. At the same time, m-code is easier to read, easier to debug, easier to change if at some point in the future they wanted to do something.
Since I would expect that few people are that worried about the brute speed of beta pdf evaluation, they chose to leave it in an m-file form.

Categorías

Más información sobre Polynomials en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by