フィルターのクリア

How to compute entropy more efficiently?

1 回表示 (過去 30 日間)
Yingke
Yingke 2012 年 8 月 10 日
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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by