GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

Avoiding zero-valued gene

Open raulazo-m opened this issue 3 years ago • 1 comments

I am optimizing a function with 3 parameters according to experimental data. I defined a value space for the 3 genes:

gene_space=[np.linspace(0.6,0.8,100), np.linspace(0.1,0.2,100),np.linspace(34,35,1000)]

and this is my general configuration:

ga_instance = pygad.GA(num_generations=num_generations, num_parents_mating=num_parents_mating, fitness_func=fitness_function, sol_per_pop=sol_per_pop, num_genes=num_genes, on_generation=callback_generation, crossover_type=crossover_func, parent_selection_type=parent_selection_func, gene_space=gene_space, mutation_type="adaptive", mutation_probability = [0.5, 0.1])

I get a fairly accurate final value with respect to the experimental value in the iterative process I am using. However, sometimes some of the parameters become zero and the range of values I imposed for the genes is not respected.

Is there any way to force the genes to take a non-zero value?

Thank you very much for any help!

raulazo-m avatar Oct 21 '22 13:10 raulazo-m

@raulazo-m,

Apologize for the late follow-up.

I see that you defined a custom crossover and parent selection functions. I doubt if they would be the reason.

I tested a code with supported crossover and parent selection functions and I did not have this issue.

Can you please share a full example to replicate the issue?

Thank you!

ahmedfgad avatar Feb 22 '23 13:02 ahmedfgad