如何在Java中编写sigmoid函数?我的hx = [0.51,0.51,0.51,0.51,0.51]
输出为sigmoid =[1.6,1.6,1.6,1.6,1.6]
,当我在Matlab中执行时,sigmoid的值为[ 0.6248 ,0.6248, 0.6248, 0.6248]
:
public double[] sigmoidFunction() {
int i;
double[] sigmoid = new double[x_theta.length];
for(i=0;i<x_theta.length; i++)
sigmoid[i] = 1 / 1 + StrictMath.exp(-x_theta[i]);
return sigmoid;
}
答案 0 :(得分:1)
你忘记了括号:
sigmoid[i] = 1 / 1 + StrictMath.exp(-x_theta[i]);
相当于
sigmoid[i] = (1 / 1) + StrictMath.exp(-x_theta[i]);
等等
sigmoid[i] = 1 + StrictMath.exp(-x_theta[i]);
,而你似乎需要
sigmoid[i] = 1 / ( 1 + StrictMath.exp(-x_theta[i]) );