Answers.Body: <p>I wrote some python code to reproduce this paper's purported results. My code very efficiently optimizes simple smooth functions like bowls, but does not come close to reproducing the paper's claimed results on more complex functions, including with the parameters the authors report. I think that, since both @Jairo and I were unable to reproduce the results from the information in the paper, independently, it is likely that something is wrong with the paper.</p>
  
  <p>It <em>may</em> be possible to reproduce the paper's claimed behaviors using a library like <a href="https://pyswarms.readthedocs.io/en/latest/" rel="nofollow noreferrer">py_swarm</a>, however the paper is using a Firefly Algorithm (already a rarer form of a PSO), and is using a home-brew variant of that algorithm, so my guess is that rolling your own is required, as we both did.</p>
  
  <p>Additionally, I find the paper's claims fairly unlikely. For example, in section 4.1, they claim to converge on the global minimum of a function with many local minima in just 10 iterations. It seems to me like most of the time the fireflies will quickly converge on the bottom of one of the gullies in this function, and get stuck there. This is also what I observe in my replications. I suspect the authors may have cherry-picked their results from the best runs without reporting this, or have omitted some key detail from the paper.</p>
  
  <p>Here is my replication code, in case someone else wants to try to reproduce this:</p>
  
  <pre><code>from math import sin, pi, exp, sqrt
  from random import random
  from copy import deepcopy
  
  def michalewiz_objective(x):
      result = 0
      for i, x_i in enumerate(x):
          result -= sin(x_i)*(sin(i*(x_i**2)/pi))**20
      return -result
  
  def bowl_objective(x):
      return -sum([x_i**2 for x_i in x])
  
  pop_size = 40
  max_generations = 10
  alpha = 0.2
  gamma = 1
  beta_0 = 1
  d = 2
  I = michalewiz_objective
  #I = bowl_objective
  
  def move(firefly, other_firefly):
      radius = sqrt(sum([(firefly[i] - other_firefly[i])**2 for i in range(0, len(firefly))]))
      for i, value in enumerate(firefly):
          firefly[i] += beta_0*exp(-gamma*radius**2)*(other_firefly[i] - firefly[i])
          firefly[i] += alpha * (random() - 0.5)
  
  # Using 4*random() to match Figure 3's apparent spread.
  fireflies = [[4*random() for i in range(0, d)] for j in range(0, pop_size)]
  
  for generation in range(0, max_generations):
      new_fireflies = [deepcopy(firefly) for firefly in fireflies]
      for index, firefly in enumerate(fireflies):
          for other_firefly in fireflies:
              if I(other_firefly) &gt; I(firefly):
                  move(new_fireflies[index], other_firefly)
      fireflies = new_fireflies
      best = max([I(f) for f in fireflies])
      mean = [sum([f[0] for f in fireflies]), sum([f[1] for f in fireflies])]
      print(best)
      print(mean)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-24T02:21:48.703Z
Answers.LastActivityDate: 2019-11-23T04:31:35.337Z
Answers.LastEditDate: 2019-11-23T04:31:35.337Z
Answers.UserDisplayName: John Doucette
Body: <p>I have been trying to reproduce the experiments done in the original: <a href="https://arxiv.org/pdf/1003.1466" rel="nofollow noreferrer">Firefly Algorithm for multimodal optimization</a> (2010) by Xin-She Yang, but so far unsuccessfully. For the moment being, I'm okay if anyone points me in the right direction.</p>
  <p>I wrote the algorithm as specified in the paper in C++ programming language (I also downloaded several other implementations from the internet for comparison purposes) and used the very same parameters as specified in the paper (a random steep of 0.2, an initial light intensity of 1.0 and a light decay coefficient of 1.0, a population size of 40). I used the two bright update equations given and for De Jung test function (as for example) a number of dimensions of 256 in a search domain in [-5.12, 5.12] as referred to in common optimization literature and in the paper.</p>
  <p>In the paper, the algorithm converges very quickly, as can be expected, since this is a very simple test function. However, neither my implementation nor any code I have downloaded converges with that parameters.</p>
  <p>My final questions are:</p>
  <ol>
  <li><p>Am I doing something wrong with the experimental methodology or am I using the wrong parameter settings (may be something different than the original paper)?</p>
  </li>
  <li><p>Do anyone knows where can I find a code sample of the Firefly Algorithm that I can use to reproduce the experiments of the mentioned paper?</p>
  </li>
  </ol>
  <p>Please, notice that there may be a lot of variations of this algorithm that can produce better results, but right now I'm only interested in reproducing the experiments of the so-called paper.</p>
  
Tags: <papers><optimization><swarm-intelligence><meta-heuristics><firefly-algorithm>
Title: Why can't I reproduce the experiments in the original paper that introduced the Firefly Algorithm?
UserDisplayName: Jairo
ThreadText: # Why can't I reproduce the experiments in the original paper that introduced the Firefly Algorithm?
  
  (Asked by: username_0 on 2017-02-13)
  
  I have been trying to reproduce the experiments done in the original: [Firefly Algorithm for multimodal optimization](https://arxiv.org/pdf/1003.1466) (2010) by Xin-She Yang, but so far unsuccessfully. For the moment being, I'm okay if anyone points me in the right direction.
  
  I wrote the algorithm as specified in the paper in C++ programming language (I also downloaded several other implementations from the internet for comparison purposes) and used the very same parameters as specified in the paper (a random steep of 0.2, an initial light intensity of 1.0 and a light decay coefficient of 1.0, a population size of 40). I used the two bright update equations given and for De Jung test function (as for example) a number of dimensions of 256 in a search domain in [-5.12, 5.12] as referred to in common optimization literature and in the paper.
  
  In the paper, the algorithm converges very quickly, as can be expected, since this is a very simple test function. However, neither my implementation nor any code I have downloaded converges with that parameters.
  
  My final questions are:
  
  1. Am I doing something wrong with the experimental methodology or am I using the wrong parameter settings (may be something different than the original paper)?
  2. Do anyone knows where can I find a code sample of the Firefly Algorithm that I can use to reproduce the experiments of the mentioned paper?
  
  Please, notice that there may be a lot of variations of this algorithm that can produce better results, but right now I'm only interested in reproducing the experiments of the so-called paper.
  
  **Tags:** papers, optimization, swarm-intelligence, meta-heuristics, firefly-algorithm
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-24. Score: 2
  
  I wrote some python code to reproduce this paper's purported results. My code very efficiently optimizes simple smooth functions like bowls, but does not come close to reproducing the paper's claimed results on more complex functions, including with the parameters the authors report. I think that, since both @username_0 and I were unable to reproduce the results from the information in the paper, independently, it is likely that something is wrong with the paper.
  
  It *may* be possible to reproduce the paper's claimed behaviors using a library like [py\_swarm](https://pyswarms.readthedocs.io/en/latest/), however the paper is using a Firefly Algorithm (already a rarer form of a PSO), and is using a home-brew variant of that algorithm, so my guess is that rolling your own is required, as we both did.
  
  Additionally, I find the paper's claims fairly unlikely. For example, in section 4.1, they claim to converge on the global minimum of a function with many local minima in just 10 iterations. It seems to me like most of the time the fireflies will quickly converge on the bottom of one of the gullies in this function, and get stuck there. This is also what I observe in my replications. I suspect the authors may have cherry-picked their results from the best runs without reporting this, or have omitted some key detail from the paper.
  
  Here is my replication code, in case someone else wants to try to reproduce this:
  
  ```
  from math import sin, pi, exp, sqrt
  from random import random
  from copy import deepcopy
  
  def michalewiz_objective(x):
      result = 0
      for i, x_i in enumerate(x):
          result -= sin(x_i)*(sin(i*(x_i**2)/pi))**20
      return -result
  
  def bowl_objective(x):
      return -sum([x_i**2 for x_i in x])
  
  pop_size = 40
  max_generations = 10
  alpha = 0.2
  gamma = 1
  beta_0 = 1
  d = 2
  I = michalewiz_objective
  #I = bowl_objective
  
  def move(firefly, other_firefly):
      radius = sqrt(sum([(firefly[i] - other_firefly[i])**2 for i in range(0, len(firefly))]))
      for i, value in enumerate(firefly):
          firefly[i] += beta_0*exp(-gamma*radius**2)*(other_firefly[i] - firefly[i])
          firefly[i] += alpha * (random() - 0.5)
  
  # Using 4*random() to match Figure 3's apparent spread.
  fireflies = [[4*random() for i in range(0, d)] for j in range(0, pop_size)]
  
  for generation in range(0, max_generations):
      new_fireflies = [deepcopy(firefly) for firefly in fireflies]
      for index, firefly in enumerate(fireflies):
          for other_firefly in fireflies:
              if I(other_firefly) > I(firefly):
                  move(new_fireflies[index], other_firefly)
      fireflies = new_fireflies
      best = max([I(f) for f in fireflies])
      mean = [sum([f[0] for f in fireflies]), sum([f[1] for f in fireflies])]
      print(best)
      print(mean)
  
  ```
  
  
  ---
  
  