<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Change Dir

    先知cd——熱愛生活是一切藝術(shù)的開始

    統(tǒng)計(jì)

    留言簿(18)

    積分與排名

    “牛”們的博客

    各個(gè)公司技術(shù)

    我的鏈接

    淘寶技術(shù)

    閱讀排行榜

    評論排行榜

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

     

    看其他篇章到目錄選擇。

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

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

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



     

    在連續(xù)型的ContinuousDistribution接口中,添加了一個(gè)double inverseCumulativeProbability(double p)的方法,這個(gè)方法返回P(X<x)=p中的x。也就是說通過已知概率,可以求得隨機(jī)變量Xx范圍。當(dāng)然看api文檔還應(yīng)注意一句,在3.0的版本中會加入public double density(double x)這個(gè)求概率密度函數(shù)的方法,敬請期待吧。離散型的接口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 */
     4package algorithm.math;
     5
     6import org.apache.commons.math.MathException;
     7import org.apache.commons.math.distribution.NormalDistribution;
     8import org.apache.commons.math.distribution.NormalDistributionImpl;
     9import org.apache.commons.math.distribution.PoissonDistribution;
    10import org.apache.commons.math.distribution.PoissonDistributionImpl;
    11
    12/**
    13 * @author Jia Yu
    14 * @date   2010-11-28
    15 */
    16public 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

    posted on 2010-12-23 20:03 changedi 閱讀(5137) 評論(0)  編輯  收藏 所屬分類: 數(shù)學(xué)

    主站蜘蛛池模板: 免费看的成人yellow视频| 99久久免费中文字幕精品| 永久免费AV无码网站在线观看| 亚洲熟妇av一区| 午夜爽爽爽男女免费观看影院| 国产精品亚洲а∨无码播放| 怡红院免费全部视频在线视频| 国产亚洲午夜高清国产拍精品| xxxx日本在线播放免费不卡| 国产精品亚洲精品日韩已方| 久青草视频97国内免费影视| 亚洲午夜AV无码专区在线播放| 一区二区三区免费在线观看| 亚洲精品高清在线| 国产精品小视频免费无限app| 亚洲香蕉网久久综合影视| 鲁丝片一区二区三区免费| 亚洲精选在线观看| 天天影院成人免费观看| 久久亚洲国产最新网站| 手机看片久久国产免费| 一区二区三区AV高清免费波多| 2048亚洲精品国产| 久久久久国产免费| 亚洲综合久久一本伊伊区| 中文在线日本免费永久18近| 亚洲成A∨人片在线观看不卡| 外国成人网在线观看免费视频 | 免费看一级做a爰片久久| 久青草国产免费观看| 久久久久亚洲AV片无码| 久久99九九国产免费看小说| 亚洲日韩在线中文字幕综合| 国产jizzjizz视频全部免费| 亚洲精品无AMM毛片| 永久免费看mv网站入口| 男人的天堂亚洲一区二区三区 | 亚洲av日韩综合一区二区三区| 免费无码不卡视频在线观看| eeuss影院免费直达入口| 亚洲αv在线精品糸列|