The Firefly Algorithm� Dharmik Trivedi�
The Firefly Algorithm:
In this algorithm behavior of fireflies seen in the nature is used to optimize a function in given domain. The data points of the function to be optimized is considered as a firefly in a given domain.
Certain Assumptions are made which are as following:
Assumptions:
Sample Code for Firefly Algorithm:
% taking x1 and x2 randomly within the domain
x1=lb+rand([n 1]).*(ub-lb);
x2=lb+rand([n 1]).*(ub-lb);
fun=((x1.^2)+x2-11).^2+(x1+(x2.^2)-7).^2; % Himmelblau Function
x=[x1 x2]; % n data points
for c=1:k %Number of iterations
for i=1:n
for j=1:n
if fun(i)>fun(j)
a=x(i,:);b=x(j,:);
r=sqrt((a(1)-b(1))^2+(a(2)-b(2))^2); % distance between i and j
A=a+B0*exp(-gamma*r).*(b-a)+[(a0*delta*(rand-0.5)*L),(a0*delta*(rand-0.5)*L)];
x(i,:)=A;
x1(i)=x(i,1);
x2(i)=x(i,2);
fun=((x1.^2)+x2-11).^2+(x1+(x2.^2)-7).^2;
end
end
end
end
Booth Function solved by Firefly Algorithm | |||
| x1 | x2 | fun |
n=5 t=100 | 1.0233 | 2.9918 | 0.0015 |
1.0596 | 2.9635 | 0.007 | |
0.9258 | 3.0918 | 0.0152 | |
|
| ||
n=8 t=100 | 1.0631 | 2.9687 | 0.009 |
0.9416 | 3.0097 | 0.013 | |
1.0261 | 2.9926 | 0.0021 | |
|
| ||
n=15 t=100 | 1.0098 | 3.006 | 0.0011 |
1.0299 | 2.971 | 0.0017 | |
0.0094 | 2.9942 | 1.72E-04 | |
|
| ||
n=5 t=10000 | 0.9885 | 3.0106 | 2.49E-04 |
0.9895 | 3.0105 | 2.20E-04 | |
0.9963 | 3 | 6.74E-05 | |
0.9992 | 2.9999 | 3.91E-06 | |
Analtic : | 1 | 3 | 0.00E+00 |
Complexity of the algorithm:
Booth Function
The Hybrid Algorithm:
As it can be seen from the table that for even after 10000 iterations we can expect accuracy of order 1e-5. To increase the accuracy we can compile gradient methods with this algorithm. After a fair amount of iterations the Firefly algorithm will give the data pouts that are in the vicinity of the actual solution. Now this point can be used as the initial guess for the gradient method and it will give more accurate results.
Advantages:
A multimodal function may have global minima at multiple points but the algorithm will give only one solution in the end. This can be remedy by using the algorithm multiple times and comparing the solutions.
Solved Examples:
1. Ackley Function:
2. Bird Function:
3. Levi’s Function:
4. McCormik Function:
5.Himmelblau’s Function:
Why Firefly algorithm is efficient ?