Gamma function compute beta distribution and drawing (1), gammabeta

Source: Internet
Author: User

Gamma function compute beta distribution and drawing (1), gammabeta



Relationship between beta function and Gamma Function


For detailed derivation process, see LDA roaming guide.
Java org. apache. commons. math3.special. Gamma encapsulates the Gamma function and can be directly used.
This article first calculates the 3.9 scatter plots of B (2.9, 3.9) and B (5.3, 100), and then draws the Beta distribution image.
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();                     }    }


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.