亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Commons Math學(xué)習(xí)筆記——分布

系統(tǒng) 2121 0

看其他篇章到 目錄 選擇。

概率分布是概率論的一個(gè)基礎(chǔ)。

Commons Math 包中也專門有一個(gè)子包對(duì)概率分布進(jìn)行了封裝實(shí)現(xiàn)。在 distribution 包中,定義了一個(gè)基本接口 Distribution 。該接口只有兩個(gè)方法,一個(gè)是 double cumulativeProbability (double x) ,一個(gè)是 double cumulativeProbability (double x0, double x1) 。前者對(duì)于服從某種分布的隨機(jī)變量X,返回P(X<=x);后者則返回P(x0<=X<=x1)。正如其名所示,這樣也就得到了概率。

具體 distribution 包中實(shí)現(xiàn)了基本所有的概率分布,分為連續(xù)型分布和離散型分布,連續(xù)型包括了像熟悉的指數(shù)分布、柯西分布等,離散型包括了泊松分布和二項(xiàng)分布等等。具體的類圖結(jié)構(gòu)見下圖:

Commons Math學(xué)習(xí)筆記——分布

?

在連續(xù)型的 ContinuousDistribution 接口中,添加了一個(gè) double inverseCumulativeProbability (double p) 的方法,這個(gè)方法返回 P(X<x)=p 中的 x 。也就是說通過已知概率,可以求得隨機(jī)變量 X x 范圍。當(dāng)然看 api 文檔還應(yīng)注意一句,在 3.0 的版本中會(huì)加入 public double density(double x) 這個(gè)求概率密度函數(shù)的方法,敬請(qǐng)期待吧。離散型的接口 DiscreteDistribution 中則添加了 double probability (double x) 方法,用來計(jì)算 P(X=x) 的概率。

具體的代碼我們以離散型的泊松分布和連續(xù)型的正態(tài)分布來講解。泊松分布的接口繼承了 IntegerDistribution 接口,在此基礎(chǔ)上加了 getMean() 方法和 normalApproximateProbability() 方法。正態(tài)分布 NormalDistribution 繼承了 ContinuousDistribution ,又添加了 getMean() 方法和 double density(double x) 方法以及 getStandardDeviation() 方法。

?

?1 /**
?2 ? * ?
?3 ? */
?4 package ?algorithm . math;
?5
?6 import ?org . apache . commons . math . MathException;
?7 import ?org . apache . commons . math . distribution . NormalDistribution;
?8 import ?org . apache . commons . math . distribution . NormalDistributionImpl;
?9 import ?org . apache . commons . math . distribution . PoissonDistribution;
10 import ?org . apache . commons . math . distribution . PoissonDistributionImpl;
11
12 /**
13 ? * ? @author ?Jia?Yu
14 ? * ? @date ??? 2010 - 11 - 28
15 ? */
16 public?class?DistributionTest?{
17
18 ???? /**
19 ????? * ? @param ?args
20 ????? */
21 ????public?static?void?main(String[]?args)?{
22 ???????? // ?TODO?Auto - generated?method?stub
23 ????????poisson();
24 ???????? System . out . println( " ------------------------------------------ " );
25 ????????normal();
26 ????????test();
27 ????}
28
29 ???? /**
30 ????? * ?test? for ?example
31 ????? * ?《飲料裝填量不足與超量的概率》
32 ????? * ?某飲料公司裝瓶流程嚴(yán)謹(jǐn),每罐飲料裝填量符合平均600毫升,標(biāo)準(zhǔn)差3毫升的常態(tài)分配法則。隨機(jī)選取一罐,容量超過605毫升的概率?容量小于590毫升的概率
33 ????? * ?容量超過605毫升的概率? = ?p?(?X? > ? 605 ) = ?p?(?((X - μ)? / σ)? > ?(?( 605 ?–? 600 )? / ? 3 )?) = ?p?(?Z? > ? 5 / 3 )? = ?p(?Z? > ? 1.67 )? = ? 0.0475
34 ????? * ?容量小于590毫升的概率? = ?p?(X? < ? 590 )? = ?p?(?((X - μ)? / σ)? < ?(?( 590 ?–? 600 )? / ? 3 )?) = ?p?(?Z? < ? - 10 / 3 )? = ?p(?Z? < ? - 3.33 )? = ? 0.0004
35 ????? */
36 ????private?static?void?test()?{
37 ???????? // ?TODO?Auto - generated?method?stub
38 ????????NormalDistribution?normal? = ?new?NormalDistributionImpl( 600 , 3 );
39 ????????try?{
40 ???????????? System . out . println( " P(X<590)?=? " + normal . cumulativeProbability( 590 ));
41 ???????????? System . out . println( " P(X>605)?=? " + ( 1 - normal . cumulativeProbability( 605 )));
42 ????????}?catch?(MathException?e)?{
43 ???????????? // ?TODO?Auto - generated?catch?block
44 ????????????e . printStackTrace();
45 ????????}
46 ????}
47
48 ????private?static?void?poisson()?{
49 ???????? // ?TODO?Auto - generated?method?stub
50 ????????PoissonDistribution?dist? = ?new?PoissonDistributionImpl( 4.0 );
51 ????????try?{
52 ???????????? System . out . println( " P(X<=2.0)?=? " + dist . cumulativeProbability( 2.0 ));
53 ???????????? System . out . println( " mean?value?is? " + dist . getMean());
54 ???????????? System . out . println( " P(X=1.0)?=? " + dist . probability( 1.0 ));
55 ???????????? System . out . println( " P(X=x)=0.8?where?x?=? " + dist . inverseCumulativeProbability( 0.8 ));
56 ????????}?catch?(MathException?e)?{
57 ???????????? // ?TODO?Auto - generated?catch?block
58 ????????????e . printStackTrace();
59 ????????}
60 ????}
61
62 ????private?static?void?normal()?{
63 ???????? // ?TODO?Auto - generated?method?stub
64 ????????NormalDistribution?normal? = ?new?NormalDistributionImpl( 0 , 1 );
65 ????????try?{
66 ???????????? System . out . println( " P(X<2.0)?=? " + normal . cumulativeProbability( 2.0 ));
67 ???????????? System . out . println( " mean?value?is? " + normal . getMean());
68 ???????????? System . out . println( " standard?deviation?is? " + normal . getStandardDeviation());
69 ???????????? System . out . println( " P(X=1)?=? " + normal . density( 1.0 ));
70 ???????????? System . out . println( " P(X<x)=0.8?where?x?=? " + normal . inverseCumulativeProbability( 0.8 ));
71 ????????}?catch?(MathException?e)?{
72 ???????????? // ?TODO?Auto - generated?catch?block
73 ????????????e . printStackTrace();
74 ????????}
75 ????}
76
77 }
78

?

?

輸出:
P(X<=2.0) = 0.23810330555354414
mean value is 4.0
P(X=1.0) = 0.07326255555493674
P(X=x)=0.8 where x = 5
------------------------------------------
P(X<2.0) = 0.9772498680518208
mean value is 0.0
standard deviation is 1.0
P(X=1) = 0.24197072451914337
P(X<x)=0.8 where x = 0.8416212335731417
P(X<590) = 4.290603331968401E-4
P(X>605) = 0.047790352272814696


泊松分布只需要給定參數(shù)
λ 即可,而其期望就是 λ。所以構(gòu)造方法一般就是 new PoissonDistributionImpl(double mean)這樣的形式了。

正態(tài)分布需要知道均值和方差,因此要在構(gòu)造函數(shù)時(shí)傳入,另外程序中以一個(gè)維基百科上的示例來驗(yàn)證正態(tài)分布的正確性。

相關(guān)資料:

概率分布: http://zh.wikipedia.org/zh-cn/%E6%A6%82%E7%8E%87%E5%88%86%E5%B8%83

泊松分布: http://zh.wikipedia.org/zh-cn/%E6%B3%8A%E6%9D%BE%E5%88%86%E5%B8%83

正態(tài)分布: http://zh.wikipedia.org/zh-cn/%E6%AD%A3%E6%80%81%E5%88%86%E5%B8%83

Commons math 包: http://commons.apache.org/math/index.html

Commons Math學(xué)習(xí)筆記——分布


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 日日夜夜嗷嗷叫 | 中文字幕视频免费在线观看 | 久久久久久综合对白国产 | 99热这里有精品 | 国产亚洲欧美精品久久久 | 亚洲综合欧美日韩 | 久久www免费人成_看片高清 | 51国产午夜精品免费视频 | 一区二区三区在线 | 欧 | 狠狠色狠狠色综合久久第一次 | 国产精品免费在线播放 | 精品久久一区二区三区 | 国产精品久久久久久搜索 | 亚洲国产资源 | 91在线免费看 | 99热成人精品免费久久 | 国产大片在线观看 | 91色在线视频 | 免看一级a毛片一片成人不卡 | 天天曰夜夜曰 | 草久在线观看视频 | 激情综合五月 | 四虎永久影院 | 免费国产免费福利视频 | 久久这里只有精品免费的 | 成人午夜视频在线播放 | 中文字幕在线精品不卡 | 日韩字幕在线 | xx性欧美高清 | 日韩中文字幕免费在线观看 | 国产精品国内免费一区二区三区 | 久久夜色视频 | 99精品国产福利在线观看 | 天海翼精品久久中文字幕 | 国产你懂的在线 | 精品精品国产理论在线观看 | 欧美一级亚洲一级 | 国产成人99久久亚洲综合精品 | 在线久久 | 欧美精品成人a多人在线观看 | 一级毛片免费视频网站 |