Machine learning 与Matlab不同的Sigmoid函数结果

Machine learning 与Matlab不同的Sigmoid函数结果,machine-learning,Machine Learning,如何在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,0.6248]: public double[] sigmoidFunction() { int i; double[] sigmoid = new double[x_theta.length]; f

如何在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,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;
}
public double[]sigmoidFunction(){
int i;
double[]sigmoid=新的double[x_theta.长度];

对于(i=0;i您忘记了括号:

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]) );

我想,sigmoid[i]=1/1+StrictMath.exp(-x_θ[i]);应该是sigmoid[i]=1/(1+StrictMath.exp(-x_θ[i]);几乎可以肯定,你不需要StrictMath。如果你只是想得到再现性,就回到数学上来吧。