-
-
Notifications
You must be signed in to change notification settings - Fork 489
Definition of the initial population for the genetic algorithm by the user #171
-
Dear all,
I am using Python's pypi genetic algorithm 1.0.2 and I want to run this genetic algorithm with my default initial population. How can I do this?
And is it possible that, for example, out of 70 populations, I introduce only one and the genetic algorithm produces the other 69?
Regards
Beta Was this translation helpful? Give feedback.
All reactions
This code is written for a different library, not PyGAD. It looks that some parameters can be mapped to PyGAD code easily and some others need your investigation. Please check the PyGAD documentation to map the code: https://pygad.readthedocs.io/en/latest
Once you write the PyGAD code, then we can help you solve your issues.
Replies: 3 comments 3 replies
-
You can use the initial_population
parameter to set your custom initial population.
ga_instance = pygad.GA(..., initial_population= ...)
Can you further clarify the other question. Do you mean 70 generations or solutions?
Beta Was this translation helpful? Give feedback.
All reactions
-
@ahmedfgad
I use this genetic algorithm code. And the "initial_population" parameter is not defined in this code :
import numpy as np
from geneticalgorithm import geneticalgorithm as ga
def f(X):
return np.sum(X)
varbound=np.array([[0,10]]*3)
algorithm_param = {'max_num_iteration': 3000,
'population_size':100,
'mutation_probability':0.1,
'elit_ratio': 0.01,
'crossover_probability': 0.5,
'parents_portion': 0.3,
'crossover_type':'uniform',
'max_iteration_without_improv':None}
model=ga(function=f,
dimension=3,
variable_type='real',
variable_boundaries=varbound,
algorithm_parameters=algorithm_param)
model.run()
I mean 70 solutions.
Beta Was this translation helpful? Give feedback.
All reactions
-
You are not using PyGAD but a different library. Please post this question to the library's GitHub repository.
Beta Was this translation helpful? Give feedback.
All reactions
-
I am going to minimize a function. Its sample code is as follows; I don't know how to run this code using PyGAD
def LEVYFUNCTION(x):
term1 = (math.sin(3math.pix[0]))**2;
term2 = (x[0]-1)**2 * (1+(math.sin(3math.pix[1]))**2);
term3 = (x[1]-1)**2 * (1+(math.sin(2math.pix[1]))**2);
return (term1 + term2 + term3)
varbound=np.array([[-10,10]]*2)
algorithm_param = {'max_num_iteration': 2000,
'population_size':50,
'mutation_probability':0.1,
'elit_ratio': 0.01,
'crossover_probability': 0.5,
'parents_portion': 0.3,
'crossover_type':'uniform',
'max_iteration_without_improv':None}
model=ga(function=LEVYFUNCTION,dimension=2,variable_type='real',variable_boundaries=varbound,algorithm_parameters=algorithm_param)
model.run()
y = (sin(3pix1))^2 + (x1-1)^2 * (1+(sin(3pix2))^2) + (x2-1)^2 * (1+(sin(2pix2))^2)
x= [-10, 10]
Global Minimum:
f(x)=0, x=(1,1)
If possible please guide how can I run this code using PyGAD?
And if the minimum and maximum range of x is not the same, how should it be defined?
Beta Was this translation helpful? Give feedback.
All reactions
-
This code is written for a different library, not PyGAD. It looks that some parameters can be mapped to PyGAD code easily and some others need your investigation. Please check the PyGAD documentation to map the code: https://pygad.readthedocs.io/en/latest
Once you write the PyGAD code, then we can help you solve your issues.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1