Azzera filtri
Azzera filtri

How to compute entropy more efficiently?

2 visualizzazioni (ultimi 30 giorni)
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));
===================

Risposta accettata

Bjorn Gustavsson
Bjorn Gustavsson il 10 Ago 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 Commenti
Yingke
Yingke il 10 Ago 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 il 10 Ago 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by