Genetic algorithm and ML library that supports Keras & PyTorch.
Questions tagged [pygad]
23 questions
3
votes
1 answer
PyGAD: How to constrain genes to sample set without replacement?
Suppose I have an assignment problem where I need to assign riders to seats. I need to enforce the constraint that at most, one rider is assigned to any given seat and every rider is assigned one seat.
Linear programming offers a means to articulate…

jbuddy_13
- 902
- 2
- 12
- 34
3
votes
1 answer
PyGAD is not receiving integer parameters according to documentation
I am trying to use PyGAD to optimize hyper-parameters in ML models. According to documentation
The gene_space parameter customizes the space of values of each gene ... list, tuple, numpy.ndarray, or any range like range, numpy.arange(), or…

jbuddy_13
- 902
- 2
- 12
- 34
2
votes
2 answers
TypeError: can't multiply sequence by non-int of type 'GA'
I am making a Genetic Algorithm(GA) in python with pygad, but I keep getting this error:
TypeError: can't multiply sequence by non-int of type 'GA'
here is my whole code:
import pygad
import numpy
print(pygad.__version__)
inputs =…

R1B07008
- 33
- 5
2
votes
0 answers
Avoiding zero-valued gene using pygad
I am optimizing a function with 3 parameters according to experimental data. I defined a value space for the genes:
gene_space=[np.linspace(0.6,0.8,100), np.linspace(0.1,0.2,100),np.linspace(34,35,1000)]
and this is my general configuration:
…

Raúl Lazo-Molina
- 21
- 1
2
votes
1 answer
Genetic Algorithm with PyGAD
I'm trying to make a genetic algorithm with PyGAD to find the best value that maximize this function: Z = (3*(x^2 - y)^2 + (100 - x)^2) + (y- x) , x and y between [-4, 4].
Could someone send me an example of something similar to this function? The…

Thorsen
- 53
- 5
1
vote
0 answers
PYGAD how to debug the built-in parent selection method
I am using PYGAD GA module to write a genetic programming, I want to use the tournament selection for my parent matching, I do not known how to use print() to debug the parent selection method, here is my code:
import numpy as np
import pygad
def…

Cn Hu
- 57
- 6
1
vote
1 answer
Multi-objective optimization with PyGAD - maximin algorithm
I have a multi-objective optimization problem for which I would like to use the PyGAD library. I would like to use the maximin algorithm for multi-objective optimization, but in order to do so I need access to the fitness values of each other design…

Ryan Larson
- 23
- 3
1
vote
0 answers
PYGAD issue with Parallel Processing
I am using PYGAD for optimizing parameters for a backtrading strategy. It switches from using multiple threads to single threads every generation. I am confused as to why. It was working perfectly fine previously. I changed the mutation_type to…

thecodeman
- 49
- 5
1
vote
0 answers
Why am I getting NaN returned from the categorical_crossentropy which causes an index error when using pyGAD for optimizing a keras ANN parameters?
I've been trying to implement a GA to optimize the parameters of my ANN. I'm new to both of these libraries and I've used this as help to implement it https://blog.paperspace.com/train-keras-models-using-genetic-algorithm-with-pygad/. I'm…

Illuminy
- 11
- 1
1
vote
1 answer
How do i scale my fitness values? (using PyGAD)
As the title says, i want to use fitness scalling methods, such as sigma scalling, for i'm having problems with premature genetic conversion in non-optimal solutions.
I know that PyGAD has a on_fitness method that is called after the fitness values…

yna ponte
- 41
- 5
1
vote
1 answer
PyGAD - how to create solution which will return me list of 0 and 1
I'm experimenting with pygad.
Have created initial population of lists of 0 and 1:
llist = [[random.randint(0,1) for _ in range(40)] for _ in range(10)]
my fitness functions does simple
sum(solution)
I'm trying to create model which will evolve…

Bill
- 63
- 5
1
vote
0 answers
Why is my genetic algorithm not improving?
The fitness output is always 0 when my genetic algorithm is training. This should be normal at first but it does this for the entire duration of the training and does not improve at all. I have the training of the genetic algorithm set up so that it…

BennyC20
- 13
- 3
1
vote
0 answers
How to solve multiple knapsacks problem with genetic algorithm using PyGAD?
I'm trying to solve the multiple knapsacks problem (MKP), in which I want to fit n items into m containers (knapsacks). Items have their weights and knapsacks capacity that they can hold.
I decided to solve it with genetic algorithm in Python using…

Artur
- 31
- 1
- 5
1
vote
0 answers
How to cross validate ML hyperparameters with genetic algorithm PyGAD?
I'm trying to use the Genetic Algorithm library, PyGAD to cross validate hyper-parameters in non-DL machine learning applications.
Data generation
## Create synthetic data
f = np.vectorize(lambda x: int(x>0.5))
X = np.random.uniform(low=0, high=1,…

jbuddy_13
- 902
- 2
- 12
- 34
1
vote
1 answer
How to get the gene values for each solution with pygad?
I'm having a problem with pygad. My goal is to minimize the volume of a structure using the Ansys program.
The Ansys code should read an input file, where I'm trying to write the values of the genes (project variables) for each evaluation of the…