java计算信息熵_熵的计算
1.什么是熵,這里只談計算機領域的信息熵
2.舉例,以做選擇題為例
3.代碼,用Java代碼來計算熵,還是計算上圖的例子
package net.highersoft.ml;
public class Shang {
public static void main(String[] args) {
// 一道選擇題,4個選項,選項都可能是答案。
//熵=A+B+C+D=A*4
double total=(1.0/4)*(Math.log(4)/Math.log(2))*4 ;
System.out.println(total);
//C選項有50%可能性是答案
//熵=C+(A+B+D)=C+3*A
double ratA=1.0/3*(1.0/2);
double s2=total-1.0/2*(Math.log(2)/Math.log(2))+ratA*(Math.log(1/ratA)/Math.log(2))*3;
System.out.println(s2);
//D選項是錯的
//熵=A*3
double s3=1.0/3*(Math.log(3)/Math.log(2))*3;
System.out.println(s3+"即提供的信息為:"+(total-s3));
//D選項是錯的,且A選項是錯的
//熵=B*2
double s4=1.0/2*(Math.log(2)/Math.log(2))*2;
System.out.println(s4+"即提供的信息為:"+(s3-s4));
//D選項是錯的,且A選項是錯的,且B選項是錯的
//熵=C
double s5=1.0/1*(Math.log(1)/Math.log(2));
System.out.println(s5+"即提供的信息為:"+(s4-s5));
}
}
評論:
提交
總結
以上是生活随笔為你收集整理的java计算信息熵_熵的计算的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 【八】自定义Git
- 下一篇: python安装详细步骤mac_Mac
