GeneticAlgorithmPython
GeneticAlgorithmPython copied to clipboard
How do I do it for multiple values of xi and yi?
How do I do it for multiple values of xi and yi? For example, I have:
X=
[[1.875, 1.875, 1.875, 2.5 ],
[0.625, 3.125, 1.25 , 3.125],
[3.125, 1.25 , 1.875, 0.625],
[0.625, 1.25 , 0.625, 1.25 ],
[0.625, 3.125, 0.625, 0.625]]
y=
[[3.],
[6.],
[9.],
[9.],
[6.]]
How do I calculate the weights for X that would fit y using the code above? Is there a way to calculate the error for each case and optimize accordingly from within the library?
This should be a multi-objective optimization problem. PyGAD only supports single-objective problems.
To do it in PyGAD, you should do the following:
- Set the number of genes in PyGAD to 20 (because X shape is 5x4=20).
- In the fitness function, reshape the solution into a 5x4 array.
- Multiply the solution by X, row by row, sum the results of each row to get only 5 outputs.
- Compare the 5 outputs to the y array and calculate the error for each y.
- Based on the 5 errors calculated, you should return a single value that represents the fitness.
I hope this helps. Please get back if further clarification is needed.
@oq-9 Hi, oq-9! Have you solved the problem? I've encountered the same problem with you. Could u share some experiences? Any help will be greatly appreciated!