title: Java - Ackley Test Function
body: <p>I am testing a new optimisation algorithm and have a whole test framework in Java. I am comparing this to results from previous papers (one is the well known CLPSO paper). More about the function - <a href="http://www.sfu.ca/~ssurjano/ackley.html" rel="nofollow">http://www.sfu.ca/~ssurjano/ackley.html</a></p>
  
  <p>The Ackley function is well known and is part of my test suite, THOUGH in my Java implementation of the function I can't seem to get the function minima to be 0, (this should occur at x[i] = 0 for all i). I'm guessing this is some rounding/handling of exp's in Java. Any suggestions for reducing these calculation errors, (it has to be in Java)? My current implementation is:</p>
  
  <pre><code>public double f(double[] x) {
  double sum1 = 0.0;
  double sum2 = 0.0;
  
  for (int i = 0 ; i &lt; x.length ; i ++) {
          sum1 += Math.pow(x[i], 2);
          sum2 += (Math.cos(2*Math.PI*x[i]));
  }
  
  return (-20.0 * Math.exp(-0.2 * Math.sqrt(sum1 / ((double )x.length))) - 
                  Math.exp(sum2 / ((double )x.length)) + 20.0 + Math.exp(1));
  }
  </code></pre>
  
  <p>I currently get the minima value of 8.881784197001252E-16 at my vector X = 0</p>
  
  <p>--something to do with order/brackets…</p>
  
  <pre><code>    return -20.0*Math.exp(-0.2*Math.sqrt(sum1 / ((double )x.length))) + 20
                       - Math.exp(sum2 /((double )x.length)) + Math.exp(1.0);
  </code></pre>