GammaFunction Computebeta分布並畫圖(1),gammabeta

來源:互聯網
上載者:User

GammaFunction Computebeta分布並畫圖(1),gammabeta



貝塔函數與伽馬函數的關係


詳細推導過程見LDA漫遊指南
java的org.apache.commons.math3.special.Gamma封裝了Gamma函數可以直接使用
本文首先計算出B(3.9,2.9)與B(3.9,5.3)的100個散點,然後繪製出Beta分布圖像
import java.io.BufferedWriter;import java.io.FileWriter;import java.io.IOException;import org.apache.commons.math3.special.Gamma;public class betadistr {                        public static double Gammafun(double alpha){                    return Gamma.gamma(alpha);                         }         public static double Bfunction(double alpha,double beta) {            double totgamm = Gammafun(alpha+beta);            double addgamm = Gammafun(alpha)*Gammafun(beta);            return addgamm/totgamm;        }         public static void valued() throws IOException {                        BufferedWriter writer = new BufferedWriter(new FileWriter(filename));                        int K=2;            double[][] m=new double[K][100];                        double b[][]= new double[2][2];            b[0][0]= 3.9;            b[0][1]= 2.9;            b[1][0]= 3.9;            b[1][1]= 5.3;                                                                                       for (int i = 0; i < K; i++) {                                for (int x = 0; x < 100; x++) {                        double y = (double)x/100;                                    double f=Math.pow(y,b[i][0]-1)*Math.pow(1-y, b[i][1]-1);                                                double z=Bfunction(b[i][0],b[i][1]);                        m[i][x]=f/z;                        writer.write(m[i][x] + "\t");                        System.out.println(m[i][x]);                   }                writer.write("\n");               }                                                      writer.close();                                                  }                                           public static void main(String[] args) throws IOException {            valued();                     }    }


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.