Closed andrecasotti closed 3 years ago
Now we can setup the crossover probability in GA since version 0.6.5
from sko.GA import GA
from sko.operators import crossover
ga = GA(func=lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + (x[2] - 0.5) ** 2
, n_dim=3, size_pop=100, max_iter=500, lb=[-1, -10, -5], ub=[2, 10, 2],
precision=[1e-7, 1e-7, 1])
ga.register(operator_name='crossover', operator=crossover.crossover_2point_prob, crossover_prob=0.5)
best_x, best_y = ga.run()
print('best_x:', best_x, '\n', 'best_y:', best_y)
related: #79
ok, tks! and about mutation probability?
ok, tks! and about mutation probability?
ga = GA(***,prob_mut=0.001)
@guofei9987 I tried the codes you provided for crossover probability setting but it cannot work. I got the error message: module sko.operators.crossover has not attribute 'crossover_2point_prob' Why is this? Do I need to update my sko version? Or is there any typo in the codes you provided? How can I make the code work? @andrecasotti Have you tried the codes? Can you set the crossover rate now?
@guofei9987 I tried the codes you provided for crossover probability setting but it cannot work. I got the error message: module sko.operators.crossover has not attribute 'crossover_2point_prob' Why is this? Do I need to update my sko version? Or is there any typo in the codes you provided? How can I make the code work? @andrecasotti Have you tried the codes? Can you set the crossover rate now?
Try this:
pip install --upgrade scikit-opt
is possible to setup the crossover rate probability in GA?