AlessiaLeclercq / ComputationalIntelligence_S291871

Computational Intelligence 2022/2023 Politecnico di Torino.
1 stars 1 forks source link

Lab 2 Review #5

Open Peipi98 opened 1 year ago

Peipi98 commented 1 year ago

Pros and Observations

for number_iteration in range(N_MAX_ITERATIONS):
    offspring = list()
    for i in range(OFFSPRING_SIZE):

        parent1 = select_parent(population, tournament_size = tournament_size)
        parent2 = select_parent(population, tournament_size = tournament_size)
        new_individual = crossover(parent1.genome, parent2.genome) 

        if np.random.uniform() <= mutation_rate: #Mutation perfomed 50% of the times
            if number_iteration < N_MAX_ITERATIONS/negation_rate: #First mutations are rweigth loss aimed
                new_individual = negations(random.choice([parent1.genome, parent2.genome, new_individual])) 
            else: #single flip mutation 
                new_individual = single_mutation(random.choice([parent1.genome, parent2.genome, new_individual]))

In the internal if there is a condition in which the mutation_rate is 0.5 and number_iteration is minor than N_MAX_ITERATIONS, so your condition will always be true since number_iteration will always be less than the double of his N_MAX_ITERATIONS (I've checked with a print inside the else, and it never prints out).

Suggestions

AlessiaLeclercq commented 1 year ago

Hi :) Thank you for your review. I fixed the internal if to N_MAX_ITERATIONS*negation_rate and now it works faster, however it still returns the same results (see below). I implemented the fitness as you suggested (and also changed the code accordingly from a maximization to a minimization problem) as follows: image Here I report some statistics of your version (in green) and mine (yellow) and they are pretty similar. image

Thank you again :)