10-23-2015 10:37 AM
Hello,
THis is my attempt to code the firefly algorithm in Labview.
I am based on this paper
http://arxiv.org/pdf/1003.1464v1.pdf
Begin 1) Objective function:; 2) Generate an initial population of fireflies
;. 3) Formulate light intensity
so that it is associated with
(for example, for maximization problems,
or simply
; 4) Define absorption coefficient
While (t < MaxGeneration) for i = 1 : n (all n fireflies) for j = 1 : n (n fireflies) if (
), move firefly i towards j; end if Vary attractiveness with distance r via
; Evaluate new solutions and update light intensity; end for j end for i Rank fireflies and find the current best; end while Post-processing the results and visualization; end
Could anyone help me to fix the code because it is not working yet and I don't have any idea what I should modify to make it work.
I started by optimizing a simple function
f(x,y)=exp(-(x^2+y^2))
Thank you for your help.
Zied
10-23-2015 12:43 PM
I'm not familiar with the algorthm and can't spend all day diving deep in to this code, but I took a glance and compared the algorithm in your post to the code and found some weird stuff. Here is the code with my comments added:
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
11-01-2015 02:20 PM
Thank you very much James. I tried to add more comments to the vi, I corrected several things and I used the Auckley function for test. I expect to find a global maximum f(x)=0 at (0,0,0,..0).
Unfortunately the Vi fails to converge. I hope someone can help me to find the source of the error.
Thanks,
Zied
11-01-2015 03:02 PM
I added to the vi a graph to show the fireflies in a 2d space. It is clear that the fireflies don't fly in all the space and miss the (0,0) coordinates. Is it related to the Levy flights that add the randomness to the space scan or an error in the code I still cannot find?
Thanks,
Zied
11-04-2015 08:40 AM
@ziedhosni wrote:
I added to the vi a graph to show the fireflies in a 2d space. It is clear that the fireflies don't fly in all the space and miss the (0,0) coordinates. Is it related to the Levy flights that add the randomness to the space scan or an error in the code I still cannot find?
Thanks,
Zied
hi,
did you take a look at "..\National Instruments\LabVIEW 20XX\examples\Mathematics\Optimization\Find Global Min on Surface.vi"?
Start:
after 50 Iterations:
11-05-2015 03:56 AM
Thank you very much. It is a useful vi but my objective is to write the fireflies algorithm with a levy flights distribution. The behaviour of the code changed when I added a Cauchy distribution as I did not find the Levy distribution. The results is a bit closer to what I expect.
Thanks,
Zied
11-05-2015 11:23 AM
why do you think your code isn't wright?
what's the ouput you would expect supposed to look like?
You say your code is "not working" - but it does produces an ouput each time I run your vi.
Your "initial I" and "X initial" is quite randomly generated each time the .vi is started.
Let's use a fix input, to see if the algorithm generates the same output for the same input.
Ok, we get different ouputs for the same input.
Is this what you would expect?
I didn't change anything at "formula (SubVI).vi"
11-06-2015 07:30 AM
THank you Alex. You helped me to make the vi more organised. In my previous version, I added the random generator according to the Cauchy distribution. This helped to improve the result. But I think it is still not enough. I expect to see 2 things.
1- The intensity (Ii) or at least the maximum which is the golbal maximum to increase as function of the generation until I reach 0 which is the real global maximum for the function (Ackley) I defined in the subVI.
2- In the plot of the Xi for 2 dimentional space (x and y for each Xi are the coordinates of each firefly). So I expect to see the point try to apporach from 0 after each generation until they fall in the global maximum (0,0).
You find attached the VI with the Cauchy distribution. Ideally, I would like to use the Levy distribution
Cheers,
Zied
11-06-2015 12:36 PM - edited 11-06-2015 12:38 PM
@ziedhosni wrote:
THank you Alex. You helped me to make the vi more organised. In my previous version, I added the random generator according to the Cauchy distribution. This helped to improve the result. But I think it is still not enough. I expect to see 2 things.
1- The intensity (Ii) or at least the maximum which is the golbal maximum to increase as function of the generation until I reach 0 which is the real global maximum for the function (Ackley) I defined in the subVI.
2- In the plot of the Xi for 2 dimentional space (x and y for each Xi are the coordinates of each firefly). So I expect to see the point try to apporach from 0 after each generation until they fall in the global maximum (0,0).
You find attached the VI with the Cauchy distribution. Ideally, I would like to use the Levy distribution
Cheers,
Zied
Please get rid of the "Build XY Graph"-Express.vi - I think, your LabView skills are advanced enough!
XY Graph 3 is easy to replace by the "bundle" function from the cluster palette:
XY Graph 2 should be fairly easy to replace, but I have to look into detail, what's happening inside this other Express VI.
11-06-2015 01:32 PM - edited 11-06-2015 01:36 PM
Ok, now understand what's going on in both XY Graphs, the "other" Express Vi is like an unlimited growing buffer which may be coded with the Insert Array.vi
I attached my version of "core algorithm.vi" & "formula (SubVI).vi" converted to LabView 2010, as I don't know your LabView Version.
So I expect to see the point try to apporach from 0 after each generation until they fall in the global maximum (0,0).
I'm sorry I don't understand. Isn't this happening already?
Ideally, I would like to use the Levy distribution
According to wikipedia, the Levy distribution is a "[...] a special case of the inverse-gamma distribution."
Couldn't you use the Continous Inverse CDF.vi ?