Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Definition of the initial population for the genetic algorithm by the user #171

Answered by ahmedfgad
zsbeheshti asked this question in Q&A
Discussion options

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

You must be logged in to vote

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

Comment options

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?

You must be logged in to vote
0 replies
Comment options

@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.

You must be logged in to vote
1 reply
Comment options

You are not using PyGAD but a different library. Please post this question to the library's GitHub repository.

Comment options

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?

You must be logged in to vote
2 replies
Comment options

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.

Answer selected by ahmedfgad
Comment options

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested

AltStyle によって変換されたページ (->オリジナル) /