title: Sigmoid function return NaN in Java
body: <p>I am trying to create a logistic regression algorithm in java but when I calculate the logarithm of the likelihood it is always returning NaN. My method which calculates the logarithm looks like this :</p>
  
  <pre><code>//Calculate log likelihood on given data
  private double getLogLikelihood(double cat, double[] x) {
      return cat * Math.log(findProbability(x))
           + (1 - cat) * Math.log(1 - findProbability(x));
  }
  </code></pre>
  
  <p>And the findProbability method is just take an instance from the dataset and returning the sigmoid funcion result which is between 0 and 1.</p>
  
  <pre><code>//Calculate the sum of w * x for each weight and attribute
  //call the sigmoid function with that s
  public double findProbability(double[] x){
      double s = 0;
      for(int i = 0; i &lt; this.weights.length; i++){
          if(i &gt;= x.length) break;
              s += this.weights[i] * x[i];        
      }
      return sigmoid(s);
  }
  
  private double sigmoid(double s){
      return 1 / (1 + Math.exp(-s));
  }
  </code></pre>
  
  <p>Moreover, my starting weights are :</p>
  
  <pre><code>[-0.2982955509135178, -0.4984900460081106, -1.816880187922516, -2.7325608512266073, 0.12542715714800834, 0.1516078084483485, 0.27631147403449774, 0.1371611094778011, 0.16029832096058613, 0.3117065974657231, 0.04262385176091778, 0.1948263133838624, 0.10788353525185314, 0.770608588466501, 0.2697281907888033, 0.09920694325563077, 0.003224073601703939, 0.021573742410541247, 0.21528348692817675, 0.3275511757298476, -0.1500597314893408, -0.7221692528386277, -2.062544912370121, 1.4315146889363015, 0.2522133355419722, 0.23919315019065995, 0.3200037377021523, 0.059466770771758076, 0.04012493980772944, 0.2553236501265919]
  </code></pre>
  
  <p>Finally, an instance from my dataset is :[<code>M,17.99,10.38,122.8,1001,0.1184,0.2776,0.3001,0.1471,0.2419,0.07871,1.095,0.9053,8.589,153.4,0.006399,0.04904,0.05373,0.01587,0.03003,0.006193,25.38,17.33,184.6,2019,0.1622,0.6656,0.7119,0.2654,0.4601,0.1189</code>]</p>
  
  <p>I tried to initialize the starting weightss with different random numbers but thats didnt solve the problem.</p>