From:  johndcook.com/blog

For a set of positive probabilities pi summing to 1, their entropy is defined as

(For this post, log will mean log base 2, not natural log.)

This post looks at a couple questions about computing entropy. First, are there any numerical problems computing entropy directly from the equation above?

Second, imagine you don’t have the pi values directly but rather counts ni that sum to N. Then pi = ni/N. To apply the equation directly, you’d first need to compute N, then go back through the data again to compute entropy. If you have a large amount of data, could you compute the entropy in one pass?

To address the second question, note that

so you can sum ni and ni log ni in the same pass.

One of the things you learn in numerical analysis is to look carefully at subtractions. Subtracting two nearly equal numbers can result in a loss of precision. Could the numbers above be nearly equal? Maybe if the ni are ridiculously large. Not just astronomically large — astronomically large numbers like the number of particles in the universe are fine — but ridiculously large, numbers whose logarithms approach the limits of machine-representable numbers. (If we’re only talking about numbers as big as the number of particles in the universe, their logs will be at most three-digit numbers).

Now to the problem of computing the sum of ni log ni. Could the order of the terms matter? This also applies to the first question of the post if we look at summing the pi log pi. In general, you’ll get better accuracy summing a lot positive numbers by sorting them and adding from smallest to largest and worse accuracy by summing largest to smallest. If adding a sorted list gives essentially the same result when summed in either direction, summing the list in any other order should too.

To test the methods discussed here, I used two sets of count data, one on the order of a million counts and the other on the order of a billion counts. Both data sets had approximately a power law distribution with counts varying over seven or eight orders of magnitude. For each data set I computed the entropy four ways: two equations times two orders. I convert the counts to probabilities and use the counts directly, and I sum smallest to largest and largest to smallest.

For the smaller data set, all four methods produced the same answer to nine significant figures. For the larger data set, all four methods produced the same answer to seven significant figures. So at least for the kind of data I’m looking at, it doesn’t matter how you calculate entropy, and you might as well use the one-pass algorithm to get the result faster.

[转载] Calculating Entropy的更多相关文章

  1. 【转载】7 Steps for Calculating the Largest Lyapunov Exponent of Continuous Systems

    原文地址:http://sprott.physics.wisc.edu/chaos/lyapexp.htm The usual test for chaos is calculation of the ...

  2. [转载] TLS协议分析 与 现代加密通信协议设计

    https://blog.helong.info/blog/2015/09/06/tls-protocol-analysis-and-crypto-protocol-design/?from=time ...

  3. 转载:scikit-learn学习之决策树算法

    版权声明:<—— 本文为作者呕心沥血打造,若要转载,请注明出处@http://blog.csdn.net/gamer_gyt <—— 目录(?)[+] ================== ...

  4. 【转载】计算机视觉(CV)前沿国际国内期刊与会议

    计算机视觉(CV)前沿国际国内期刊与会议这里的期刊大部分都可以通过上面的专家们的主页间接找到1.国际会议 2.国际期刊 3.国内期刊 4.神经网络 5.CV 6.数字图象 7.教育资源,大学 8.常见 ...

  5. 【转载】nginx 并发数问题思考:worker_connections,worker_processes与 max clients

    注:这个文章主要是作者一直在研究nginx作为http server和反向代理服务器时候所谓最大的max_clients和 worker_connections的计算公式, 其实最后的结论也没有卡上公 ...

  6. ZOJ3827 ACM-ICPC 2014 亚洲区域赛的比赛现场牡丹江I称号 Information Entropy 水的问题

    Information Entropy Time Limit: 2 Seconds      Memory Limit: 131072 KB      Special Judge Informatio ...

  7. 最大似然估计 (Maximum Likelihood Estimation), 交叉熵 (Cross Entropy) 与深度神经网络

    最近在看深度学习的"花书" (也就是Ian Goodfellow那本了),第五章机器学习基础部分的解释很精华,对比PRML少了很多复杂的推理,比较适合闲暇的时候翻开看看.今天准备写 ...

  8. 基于Spark自动扩展scikit-learn (spark-sklearn)(转载)

    转载自:https://blog.csdn.net/sunbow0/article/details/50848719 1.基于Spark自动扩展scikit-learn(spark-sklearn)1 ...

  9. softmax,softmax loss和cross entropy的区别

     版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u014380165/article/details/77284921 我们知道卷积神经网络(CNN ...

随机推荐

  1. 在cocos2d里面如何使用Texture Packer和像素格式来优化spritesheet

    免责申明(必读!):本博客提供的所有教程的翻译原稿均来自于互联网,仅供学习交流之用,切勿进行商业传播.同时,转载时不要移除本申明.如产生任何纠纷,均与本博客所有人.发表该翻译稿之人无任何关系.谢谢合作 ...

  2. phpcms开启、关闭在线编辑模板的方法

    打开 caches/configs/system.php 文件 找到 'tpl_edit'=> 0,//是否允许在线编辑模板 修改此行代码中的数字为 1或0 即可

  3. Eclipse程序员要掌握的常用快捷键

    Ctrl+K 光标放在一个变量上(注意,是变量,如果你的光标放在了字符串上,如http://keleyi.com则没有任何作用的),按下Ctrl+K光标会定位到下一个相同的变量 Shift+Ctrl+ ...

  4. iOS中数字的格式化 NSNumberFormatter

    NSNumberFormatter 和NSDateFormatter 是NsFormatter的子类. NSNumberFormatter类有个属性numberStyle,它是一个枚举型,设置不同的值 ...

  5. [ACM_水题] ZOJ 3706 [Break Standard Weight 砝码拆分,可称质量种类,暴力]

    The balance was the first mass measuring instrument invented. In its traditional form, it consists o ...

  6. [Java Web] 3、WEB开发之HTML基础程序试手

    1.初试: <html> <body> <h1>My First Heading</h1> <p>My first paragraph.&l ...

  7. 使用window2003安装邮件服务器最新实际操作记录

    关于使用windows 2003自带的服务组件来安装简单的pop3 协议邮件服务器网上教程很多,可以搜索出来,就是安装IIS选中smtp和添加window是组件的应用程序服务器,这点这里不多说. 安装 ...

  8. ASP.NET Entity Framework with MySql服务器发布环境配置

    首先,.net应该自带Entity Framework,所以服务器只要有对应版本的.net Framework就OK! 我们在开发环境中一般会直接使用edmx来管理应用程序与数据库的交互操作,所有与数 ...

  9. IMP-00038:无法转换为环境字符集句柄

    参考解决方案:http://www.cnblogs.com/wangsaiming/p/4947151.html

  10. paip.自定义java 泛型类与泛型方法的实现总结

    paip.自定义java 泛型类与泛型方法的实现总结 ============泛型方法     public static <atiType,retType> retType reduce ...