I need to minimize a function using genetic algorithm and PSO.
Different posts suggest to use DEAP (I am using python) but I do not even understand how to start.
We can consider for example f on the interval i
i=arange(-10,10,0.1)
def f(x):
return x*sin(x)
How can I minimize this function using DEAP?
I realise I'm late in my reply but hopefully I can help someone out there new to the DEAP library.
In order to minimise you must create a FitnessMin class as shown below:
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
Note how I have a weight of -1.0, if we were to have this as 1.0 we would be maximising.
Then once you do this, apply the fitness class to your Individual, which is essentially the Chromosome you wish to train:
creator.create("Individual", list, fitness=creator.FitnessMin)
Take a look at eaSimple in the DEAP library as it is the best one to start with. Here is a list of algorithms provided by DEAP out of the box: http://deap.readthedocs.io/en/master/api/algo.html
Actually there is an example for that : http://deap.rtfd.org/en/master/examples/pso_basic.html
Note that I'm a DEAP developer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With