-
Notifications
You must be signed in to change notification settings - Fork 78
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
Loa algorithm #351
Loa algorithm #351
Conversation
Added lion optimization algorithm implementation, named 'loa.py'
Added example for lion optimization algorithm, named 'run_loa.py'
Added a new row (alphabetically sorted) with Lion Optimization Algorithm's name, acronym and reference.
Added Lion Optimization Algorithm to __init__.py file
Added lion optimization algorithm to factory.py
Fixed some warnings from Scrutinizer test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main problems are:
- Use of the random library and np.random functions. Those functions should be called from the rng of the algorithm so the results can be reproduced if a seed is provided in the constructor.
- Using a for loop instead of task.repair
- With the random functions for example
self.integers(0, 4, 1)[0]
orself.random(1)
,The size argument 1 can be left out (self.integers(0, 4)
will return a single integer between 0 and 4) with size=1 it returns an array of size 1.
Also, could you ad a unit test in niapy/tests? Just copy the BatAlgorithm test in test_ba.py and change the names and imports. That way we can see if it actually runs. It would also be good to compare the results to an existing implementation or to the results in the article, to see if it produces similar results.
niapy/algorithms/basic/loa.py
Outdated
for i,x in enumerate(lion.current_x): | ||
if x > task.upper[i]: | ||
lion.current_x[i] = task.upper[i] | ||
elif x < task.lower[i]: | ||
lion.current_x[i] = task.lower[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced with lion.current_x = task.repair(lion.current_x)
niapy/algorithms/basic/loa.py
Outdated
for i, x in enumerate(lion.current_x): | ||
if x > task.upper[i]: | ||
lion.current_x[i] = task.upper[i] | ||
elif x < task.lower[i]: | ||
lion.current_x[i] = task.lower[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced with lion.current_x = task.repair(lion.current_x)
niapy/algorithms/basic/loa.py
Outdated
for i, x in enumerate(lion.current_x): | ||
if x > task.upper[i]: | ||
lion.current_x[i] = task.upper[i] | ||
elif x < task.lower[i]: | ||
lion.current_x[i] = task.lower[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced with lion.current_x = task.repair(lion.current_x)
niapy/algorithms/basic/loa.py
Outdated
for i, x in enumerate(prey_x): | ||
if x > task.upper[i] : | ||
prey_x[i] = task.upper[i] | ||
elif x < task.lower[i]: | ||
prey_x[i] = task.lower[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced with lion.current_x = task.repair(lion.current_x)
niapy/algorithms/basic/loa.py
Outdated
* pride_size (numpy.ndarray): Pride and nomad sizes. | ||
* gender_distribution (numpy.ndarray): Pride and nomad gender distributions. | ||
""" | ||
nomad_size = (int)(round(self.nomad_ratio * self.population_size)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with int(self.nomad_ratio * self.population_size)
or round(self.nomad_ratio * self.population_size)
. Round returns int already so no conversion is required. The first option will always round down.
niapy/algorithms/basic/loa.py
Outdated
r_two[rand_index] = 1 | ||
else: | ||
#Gram-Schmidt process to find orthogonal vector r_two. | ||
random_vec = np.random.randn(len(r_one)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace with self.standard_normal(len(r_one))
niapy/algorithms/basic/loa.py
Outdated
num_of_mating_males = random.randint(1, num_of_males) | ||
mating_males_x = random.sample(males_x, num_of_mating_males) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with:
num_of_mating_males = self.integers(1, num_of_males)
mating_males_x = self.rng.choice(males_x, num_of_mating_males)
niapy/algorithms/basic/loa.py
Outdated
num_of_mating_males = random.randint(1, num_of_males) | ||
mating_males_x = random.sample(males_x, num_of_mating_males) | ||
|
||
beta = np.random.normal(0.5, 0.1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use self.normal
niapy/algorithms/basic/loa.py
Outdated
rand = self.uniform(0, 1, 1) | ||
# If roaming treshold is met, move lion according to reference paper formula. | ||
if not rand > roaming_probability: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.random() <= roaming_probability:
niapy/algorithms/basic/loa.py
Outdated
counter -= 1 | ||
else: | ||
nomad_females_to_keep = np.append(nomad_females_to_keep, objects_to_array([lion_copy])) | ||
np.random.shuffle(nomad_females_to_move) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use self.rng.shuffle
- Removed "for loops" for checking if x is in limits, using task.repair/task.evaluate instead - Fixed and added some comments
- Removed use of random library and np.random function, instead these functions are called from rng of the algorithm. - Newly used self.rng.choice function was causing some warnings, fixed parts of codes so that the warning does not appear. - Removed size argument where it's not needed when calling random functions - Fixed tournament selection to calculate correct tournament size
Added test file 'test_loa.py' for Lion Optimization Algorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
- Removed use of int() function where round() function was applied - Fixed some scrutinizer warnings
- Replaced one of the placeholder function args descriptions with correct one - Replaced use of np.max() function with max() function
Thank you very much for that comment. I have since then fixed some of the problems:
Extra:
TO-DO:
|
Great! You can post the results as a comment here. Two more things. With |
Minor fixes on some function calls
I fixed those 2 issues. I ran some comparissons. I was checking only for the average value. I used population size of 50, dimension of 60 and max evals of 30000. I ran each of the algorithms 10 times. I compared it to 3 algorithms: Camel algorithm (CA), ParticleSwarmOptimization (PSO) and FireFlyAlgorithm (FA). I ran them against 5 problems: Sphere, Ackley, Bent cigar, Griweank and Rastrigin. Here are the results: Problem - Sphere Problem - Ackley Problem - Bent cigar Problem - Griewank Problem - Rastrigin Based on these quick results, I would say LOA is comparable to other algorithms |
@AljoM -- Are there any referential implementations of this algorithm available online for comparison? |
Original publication got their results by using algorithm against functions that were part of CEC 2014 competition. I made a quick check and as far as I can see (correct me if I'm wrong please), NiaPy only contains the basic functions that were part of CEC 2014. So for example, I can find Bent Cigar function in the library but I can't find the Rotated Bent Cigar function, which is what was used in competition. Same goes with some of the other functions. I also couldn't find any of the hybrid or composition functions. Now, about comparing it with other implementations: I was checking a little and besides the article that was my reference point, I couldn't even find any other official articles that would be testing out this algorithm, let alone providing an implementation in any of the programming languages. It's not a very well researched algorithm, which is part of why I chose to implement it and compare it with others as part of my bachelor's thesis. |
@AljoM -- you may also try to explore the following repository. CEC 2014 and other variations are linked to niapy library. If there is a chance, please run your algorithm using these benchmarks and compare with results in official papers. |
I will check into it and try to get some testing done when I figure it out. I have seen that there was merge being done but that there were some unsuccessful checks. Are those errors of significant meaning that would require me to fix the code? And is the merge going to be cancelled or proceeded? |
There is a linter error. Please fix it so the rest of the tests can get executed. Once all the checks have passed, the code can be merged. |
Fixed linter error.
Can one of the maintainers please approve this, so the checks can execute? |
Fixed errors raised from docstyle check.
Fixed errors caused by scrutinizer check
Fixed some error caused by docstyle check. Fixing them raised errors from scrutinizer check (lovely) so I fixed those as well. Now I'd need another maintainer approval to execute checks. |
I added 2 files ('loa.py', 'run_loa.py'). An implementation of lion optimization algorithm and an example of how to run it. Algorithm steps and formulas are found in an article found on (https://doi.org/10.1016/j.jcde.2015.06.003).
First I created a 'Lion' class that inherits from 'Individual'. Lions are distributed into groups called prides and a group called nomad lions.
Steps of algorithm and progress so far:
Function that checks if lion's position has improved since last iteration ('data_correction') is also completed.
Main function ('run_iteration') is also completed.