Probability density function used in random generator. Options: 'gaussian' or 'uniform'
String
Example 1
Use the Genetic Algorithm optimization method to optimize the 2D sphere function. Use a total of 100 iterations to perform the optimization. Consider the limits \(\mathbf{x}_L = [-5.0, -5.0]\) and \(\mathbf{x}_U = [5.0, 5.0]\) for the problem design variables. Consider the initial guess (three agents) \(\mathbf{pop}_0 = [-0.74, 1.25]\), \(\mathbf{pop}_1 = [3.58, -3.33]\) and \(\mathbf{pop}_2 = [1.50, 1.50]\). Use roulette wheel for selection procedure, linear crossover for crossover (82% rate) and hill climbing mutation (12% rate, \(cov=15\%\) and Gaussian generator).
"""Run optimization: your_problem.py or your_problem.ipynb"""# import libray
# pip install metapy-toolbox or pip install --upgrade metapy-toolbox
frommetapy_toolboximportgenetic_algorithm_01fromof_fileimportmy_function# External .py file with your objective function
# Algorithm setup
setup={'number of iterations':100,'number of population':3,'number of dimensions':2,'x pop lower limit':[-5,-5],'x pop upper limit':[5,5],'none variable':None,'objective function':my_obj_function,'algorithm parameters':{'selection':{'type':'roulette'},'crossover':{'crossover rate (%)':82,'type':'linear'},'mutation':{'mutation rate (%)':12,'type':'hill climbing','cov (%)':15,'pdf':'gaussian'},}}# Initial guess
init_pop=[[-0.74,1.25],[3.58,-3.33],[1.50,1.50]]"""
or # random guess
from metapy_toolbox import initial_population_01
init_pop = initial_population_01(setup['number of population'],
setup['number of dimensions'],
setup['x pop lower limit'],
setup['x pop upper limit'])
"""# Seed
seed=None# Call function
settings=[setup,init_pop,seed]df_all_results,df_resume,time_cost,report=genetic_algorithm_01(settings)