Borrar filtros
Borrar filtros

How to compute entropy more efficiently?

2 visualizaciones (últimos 30 días)
Yingke
Yingke el 10 de Ag. de 2012
Dear All
I want to computer the entropy for the distribution over hundreds outcomes for many times. I did it as follows: (copied from profiler, first column for time consumed , and second column for call numbers).
Do you know any more efficient way to do this?
Since it has been vectorised, I guess 'mex' may not help too much. Is it right?
Thanks!!!
==================
6.31 993683 16 p1 = Alpha1./sum(Alpha1);
5.06 993683 17 p2 = Alpha2./sum(Alpha2);
16.56 993683 18 h1 = sum(p1.*log(p1));
13.05 993683 19 h2 = sum(p2.*log(p2));
===================

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 10 de Ag. de 2012
On my version of matlab I get a big reduction in run-time by doing:
h1 = p1*log(p1.');
or
h1 = p1.'*log(p1);
depending on which version is the inner product for vector p1.
HTH
  2 comentarios
Yingke
Yingke el 10 de Ag. de 2012
I found a package which provide better (C and ASM) implementation of log. Anyway, your suggestion is still good. It really helped a bit. Thanks!
Bjorn Gustavsson
Bjorn Gustavsson el 10 de Ag. de 2012
Ops, I was wrong. Seems most time gain in my version was that I forgot to call the log -> the log-ing is what takes time.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical 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