Filter löschen
Filter löschen

How to compute entropy more efficiently?

2 Ansichten (letzte 30 Tage)
Yingke
Yingke am 10 Aug. 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));
===================

Akzeptierte Antwort

Bjorn Gustavsson
Bjorn Gustavsson am 10 Aug. 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 Kommentare
Yingke
Yingke am 10 Aug. 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 am 10 Aug. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by