ahmedfgad / GeneticAlgorithmPython

Source code of PyGAD, a Python 3 library for building the genetic algorithm and training machine learning algorithms (Keras & PyTorch).
https://pygad.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.79k stars 451 forks source link

maximize the output of a built neural net( by pytorch) with continuous and discrete/integer variables #220

Open AmosJoseph opened 12 months ago

AmosJoseph commented 12 months ago

Hi, can this library be used to maximize the output of a well-built neural net( by pytorch) with continuous and discrete/integer (1, 2, 3 ) variables?

Is there any example?

Best!

ahmedfgad commented 12 months ago

It can train models built in Keras and PyTorch.

Here you can find examples for training PyTorch models: https://github.com/ahmedfgad/GeneticAlgorithmPython/tree/master/examples/TorchGA

AmosJoseph commented 12 months ago

Thank you for your reply! The neural net has been trained and tested with good accuracy.

Then how to maximize the output of the neural net in the input domain?

发自我的iPhone

------------------ Original ------------------ From: Ahmed Gad @.> Date: Fri,Jul 14,2023 10:43 PM To: ahmedfgad/GeneticAlgorithmPython @.> Cc: AmosJoseph @.>, Author @.> Subject: Re: [ahmedfgad/GeneticAlgorithmPython] maximize the output of a builtneural net( by pytorch) with continuous and discrete/integer variables (Issue#220)

ahmedfgad commented 12 months ago

Do you you mean change the inputs (not the neural network itself) so that their outputs are accurate? If this is the case, then yes it can be done. Although there is no example yet, it can be developed easily.

AmosJoseph commented 12 months ago

Yes. Find the inputs (not the neural network itself) so that their outputs are maximum.

Then how to implement this?

Best!

发自我的iPhone

------------------ Original ------------------ From: Ahmed Gad @.> Date: Fri,Jul 14,2023 10:55 PM To: ahmedfgad/GeneticAlgorithmPython @.> Cc: AmosJoseph @.>, Author @.> Subject: Re: [ahmedfgad/GeneticAlgorithmPython] maximize the output of a built neural net( by pytorch) with continuous and discrete/integer variables (Issue #220)

Do you you mean change the inputs (not the neural network itself) so that their outputs are accurate? If this is the case, then yes it can be done. Although there is no example yet, it can be developed easily.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

ahmedfgad commented 5 months ago

Sorry for the long time to follow up. Just decided to reply in case it would still be helpful even for someone else.

Then what evolves is the inputs. Here are the steps:

  1. Set the num_genes parameter to the length of a single input.
  2. Inside the fitness function, pass the input to the neural network to return the predicted output.
  3. Calculate the fitness by comparing the predicted and desired outputs.