How to compute entropy more efficiently?

1 次查看(过去 30 天)
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));
===================

采纳的回答

Bjorn Gustavsson
Bjorn Gustavsson 2012-8-10
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 个评论
Yingke
Yingke 2012-8-10
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 2012-8-10
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by