baopng / NSGA-II

Implementation of NSGA-II algorithm in form of a python library.
179 stars 48 forks source link

Creating population for the next generation #2

Closed Davoodzf closed 1 year ago

Davoodzf commented 3 years ago

Hi,

Hope all is well with you. Would you please explain to me what is the purpose of the code block from line 33 to 37 in the evolution.py file? I see you are returning "returned_population.fronts[0]" at the end of the generations. So, if the algorithm is going through its final generation then the lines 33 to 37 seem to be useless because, I guess it is creating the population for the next generation and has nothing to do with the final output at the last generation, right?

Thanks,

tramloiquan commented 3 years ago

Hi,

we get "returned_population.fronts[0]" because F1 of the last generation is the best solution to the optimization problem.

K. Deb, A. Pratap, S. Agarwal and T. Meyarivan, "A fast and elitist multiobjective genetic algorithm: NSGA-II," in IEEE Transactions on Evolutionary Computation, vol. 6, no. 2, pp. 182-197, April 2002, doi: 10.1109/4235.996017.

Davoodzf commented 3 years ago

Hi, I know that you return the F1 because it is the best solution. My question is about line 33 to 37 as below: self.population = new_population self.utils.fast_nondominated_sort(self.population) for front in self.population.fronts: self.utils.calculate_crowding_distance(front) children = self.utils.create_children(self.population)

What is this part doing when the algorithm is in its final generation??

baopng commented 3 years ago

Hi!

Thank you very much for your concern. I believe Mr.Quan has misread a little bit. I have checked the code and as you have pointed out, the code was poorly written. Creating new children in the last iteration is pointless. We will fix this soon.

Regards.

Davoodzf commented 3 years ago

Thank you so much for your clarification. Would you also let me know why you use : def choose_with_prob(self, prob): if random.random() <= prob: return True return False at the end of the utils.py ? I see you are using it inside tournament function, but why?

baopng commented 3 years ago

I think it stated in the original paper or somewhere that when comparing participants we should give the weak one a chance to rise. This is for the sake of diversity, so our population will less likely be stuck in local optimal.

I am very happy that you are interested in our project. Please feel free to discuss if you have further questions.

Davoodzf commented 3 years ago

Thanks for your help. Now I have another question regarding the Evolution.py file in line 32 as follows: returned_population = self.population why you do not use "returned_population = new_population" instead?

baopng commented 3 years ago

Again, it is due to poor writing. But with the current structure you cannot assign new_population to returned_population because new_population size is actually smaller than self.population (for appending children later).