Sigmoid function using Jama math library no output in sigmoidfunction

422 Views Asked by At

I'm trying to code my sigmoid function using Jama library. I'm not sure if my code works so i call my sigmoidFunction in my test function:

public matrix sigmoidFunction() {
    matrix theta = new matrix(x_theta,m);
    matrix X = new matrix(x);
    matrix theta_transpose = theta.transpose();
    matrix HX = theta_transpose.times(X);
    double[][] hx = HX.getArray();
    int m = HX.getRowdimension();
    int n = HX .getColdimension();

    for (int i = 0; i < m; i++) {
        for (int j = 0; j<n; j++) {
             hx[i][j] = 1 / (1 + StrictMath.exp(hx[i][j]));
        }
    }
    matrix sigmoid = new matrix(hx);
return sigmoid;
}

but, when I run it, there's no output. It's like there's no value inside my sigmoidFunction. I don't know why.

public static void main(String[] args) {

    double[ ][ ] x={ {1,2}, {1,2}, {1,2} ,{1,2}, {1,2} };
        double[] theta = {0.5,0.005};
    double[] y = {1,1,0,1,0};

    LogisticRegression l = new LogisticRegression(x,theta,y);

    System.out.println(l.sigmoidFunction().getArray()[1]);

}

1

There are 1 best solutions below

2
On BEST ANSWER

You define the new matrix inside your function. Print out and see whether X and theta in your sigmoidFunction have values. Actually you need to define X and theta inside the function.