Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible error in Python version's random initialization #2

Open
cxcorp opened this issue Jul 12, 2024 · 0 comments
Open

Possible error in Python version's random initialization #2

cxcorp opened this issue Jul 12, 2024 · 0 comments

Comments

@cxcorp
Copy link

cxcorp commented Jul 12, 2024

Hello! Thanks very much for the interesting paper and especially for providing the reference implementation in Python! It's made it possible for a hobbyist like myself to try the algorithm out.

I'm trying to reproduce the results in another paper (or rather, apply the methods to my own problem) which used COA to optimize the placement of $n$ wireless routers in 2D space1. While testing the algorithm, I noticed that it seemed a bit too difficult to get the minimum cost to converge to satisfactory values - it was taking me around $10^5$ iterations ("function evaluations") to start reaching even the ballpark of the results in the paper, plateauing around 0.2 (I'm using 0..1 for my cost) They got their results with $10^3$ iterations!

So I started stepping through the implementation, and noticed that the initial random values generated for the coyotes were actually out of the VarMin, VarMax range. I was initially using negative values in VarMin, which made this pop out.

The possible error

I believe that there are parentheses missing in this statement, which generates the initial random values for each coyote:

COA/COA.py

Lines 34 to 35 in e880367

coyotes = np.tile(VarMin, [pop_total, 1]) + np.random.rand(pop_total, D) * np.tile(VarMax, [pop_total, 1]) - \
np.tile(VarMin, [pop_total, 1])

Due to the missing parentheses, this gets evaluated essentially as min + (random() * max) - min, instead of the intended min + random() * (max - min). This causes the initial random values to be biased towards the maximum, depending on min and max.

The latter (min + random() * (max - min)) is also used when generating the puppies:

COA/COA.py

Lines 117 to 119 in e880367

pup = p1*coyotes_aux[parents[0], :] + \
p2*coyotes_aux[parents[1], :] + \
n*(VarMin + np.random.rand(1, D) * (VarMax - VarMin))

After changing that line like the following, I started instantly receiving much better results (first sub-0.1 min cost with 20k function evaluations!)

-coyotes = np.tile(VarMin, [pop_total, 1]) + np.random.rand(pop_total, D) * np.tile(VarMax, [pop_total, 1]) - np.tile(VarMin, [pop_total, 1]) 
+coyotes = np.tile(VarMin, [pop_total, 1]) + np.random.rand(pop_total, D) * (np.tile(VarMax, [pop_total, 1]) - np.tile(VarMin, [pop_total, 1])) 

Footnotes

  1. S. Mekhmoukh Taleb et al. "Solving the Mesh Router Nodes Placement in Wireless Mesh Networks Using Coyote Optimization Algorithm," in IEEE Access, vol. 10, pp. 52744-52759, 2022, doi: 10.1109/ACCESS.2022.3166866.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant