7ossam81 / EvoloPy

EvoloPy toolbox provides classical and recent nature-inspired metaheuristic for the global optimization.
Apache License 2.0
445 stars 222 forks source link

GWO Algorithm #21

Closed kingshuk76 closed 3 years ago

kingshuk76 commented 5 years ago

Hi, I have been using the GWO algorithm and noticed that the position and score for beta and delta don't get updated to the second or third best position (or previous values of alpha or beta) where the iteration constantly generates better value than current alpha. If the obj function gives a value better than current alpha, shouldn't the current value of alpha get demoted to beta instead of getting lost? eg. in your code if fitness<Alpha_score : Alpha_score=fitness; # Update alpha Alpha_pos=Positions[i,:]

instead shouldn't this be - if fitness<Alpha_score : Delta_score=Beta_score # Update delta Delta_pos=Beta_pos Beta_score=Alpha_score # Update beta Beta_pos=Alpha_pos Alpha_score=fitness; # Update alpha Alpha_pos=Positions[i,:]

Thanks and Regards, Kingshuk

7ossam81 commented 4 years ago

Hi @kingshuk76

The idea of Alpha, Beta and Delta is to hold the best three solutions in the current generation, respectively. So imagine in the second generation we got three new solutions that are better than Alpha from the first generation, in this case all values of Alpha, Beta and Delta will be replaced to hold these new solutions.

ahmed2m commented 4 years ago

Hi @kingshuk76

The idea of Alpha, Beta and Delta is to hold the best three solutions in the current generation, respectively. So imagine in the second generation we got three new solutions that are better than Alpha from the first generation, in this case all values of Alpha, Beta and Delta will be replaced to hold these new solutions.

@7ossam81 But that doesn't hold for your implementation of the algorithm? Here https://github.com/7ossam81/EvoloPy/blob/153a0f277a8cab997eda9dbc2a3fbed3adbdf39f/optimizers/GWO.py#L63-L78 At any given time/case you just replace one of the three because you obtain the best fitness one value for the current generation you don't retrieve the best three? I think you need re-structure the objfun for EvoloPy to have a param to either return the best one or list of the best n ?


Update: After some digging I figured that it's evaluated per individual. So that implementation makes sense but is not intuitive from the first glance.

7ossam81 commented 4 years ago

Hi @Ahmeed2m and @kingshuk76 Thank you for your comments on the update mechanism for alpha, beta and delta. The idea of these three -according to the original paper on GWO [1]- is to hold the best three solutions so far. Therefore, @RaneemQaddoura has updated the code to match this definition.

[1] Mirjalili, Seyedali, Seyed Mohammad Mirjalili, and Andrew Lewis. "Grey wolf optimizer." Advances in engineering software 69 (2014): 46-61.

ahmed2m commented 4 years ago

Hi @Ahmeed2m and @kingshuk76 Thank you for your comments on the update mechanism for alpha, beta and delta. The idea of these three -according to the original paper on GWO [1]- is to hold the best three solutions so far. Therefore, @RaneemQaddoura has updated the code to match this definition.

[1] Mirjalili, Seyedali, Seyed Mohammad Mirjalili, and Andrew Lewis. "Grey wolf optimizer." Advances in engineering software 69 (2014): 46-61.

Yes, I just checked the original matlab function purposed in the paper has this mistake and the author approved that it's a mistake since 2014 in a comment on mathworks but didn't bother to change the code.