因此,我为Poisson分布定义了对数似然函数,我想知道是否有一种方法可以在Java中优化(最大化或最小化)该对数似然函数,目前我正在使用NetBeans,而我是新手Java。 这是我的代码:
package javaapplication1;
public class JavaApplication1 {
public static void main(String[] args) {
// x_input generated from Poisson(3)
double x_input[]={3,0,4,3,4,4,3,2,3,0};
// x_input generated from Poisson(3)
//Initializing Poisson's lamda value
double theta_input[]={3};
//Initializing Poisson's lamda value
//Just checking if the functions are well defined
System.out.println(factorial(3));
System.out.println(poisson_pdf(3,3));
System.out.println(poisson_loglik(theta_input,x_input));
//Just checking if the functions are well defined
}
// Defining function to compute the factorial
public static double factorial(double n){
double sum=0;
for (double i=1; i<=n; i++) sum=sum+Math.log(i);
return Math.exp(sum);
}
// Defining function to compute the factorial
// Defining the poisson pdf
public static double poisson_pdf(double x, double lamda){
return (1/factorial(x)) * (Math.pow(lamda,x)) * (Math.exp(-lamda) ) ;
}
// Defining the poisson pdf
// Defining the poisson loglikelihood which I want to optimize somehow
public static double poisson_loglik(double theta[], double x[]){
double lamda_pois=theta[0];
double loglik_result=0;
for(int i=0;i<x.length;i++) loglik_result=Math.log(poisson_pdf(x[i],lamda_pois))+loglik_result;
return loglik_result;
}
// Defining the poisson loglikelihood which I want to optimize somehow
}