Dynamic num_genes
Hello I'm new to genetic algorithms, and I'm trying to figure out if I can use dynamic num of genes to optimise number of parameters and their values in my model, for example
any help would be appreciated
Hiya
Pretty high level abstract question but I’m happy to field it.
You’d need to write a function called say “optimise genes” that took as arguments the number genes and how successful that was and then changes the number of genes.
You’ll need to set constraints for the number of genes and you may need to consider a definition of success in high takes account of computational time.
Do you know where to start?
Best wishes
Keith
Sent from my iPhone
On 18 Jan 2022, at 09:01, nchesk @.***> wrote:
Hello I'm new to genetic algorithms, and I'm trying to figure out if I can use dynamic num of genes to optimise number of parameters in my model, for example
any help would be appreciated
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you are subscribed to this thread.
@urowietu
Thank you for you help!
I'm a little confused to be honest
I supposed that I can't change num_genes once I Initialised it(change them straight-forward would be cool, can I do that?)
I guess that you mean something like:
def optimise_genes(num_of_genes, fitness):
res = []
for k in range(5, 25):
res.append(k, ga.GA( ... num_genes=k, ... ).solution_fitness)
return res
I thought maybe I just need to pass some dynamic structure into GA initialiser, but I'll try suggested option and post update)
@nchesk,
So, you have a model that could accept different numbers of parameters (e.g. 5, 10, 20) and you want to find the perfect number in addition to their values.
Dynamic number of genes is not a supported feature in PyGAD and all the chromosomes must have an equal length.
As @urowietu suggested, you should create multiple instances of the pygad.GA class where each one uses different number. You should build a fitness function that calculates a metric (error for example).
When all the GA complete, return the best solution found by each GA. Then, use the metric to compare the models with different number of parameters. This helps you select the optimal number of parameters.