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(); } }