guofei9987 / scikit-opt

Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Optimization Algorithm,Immune Algorithm, Artificial Fish Swarm Algorithm, Differential Evolution and TSP(Traveling salesman)
https://scikit-opt.github.io/scikit-opt/#/en/
MIT License
5.27k stars 991 forks source link

计算加速 #218

Open xiaowodaweiwang opened 1 year ago

xiaowodaweiwang commented 1 year ago

老师您好,我想请问下,如何对一个多个循环做优化,例如对下面得Array里头每一列都做优化(因为Array的列有几千列),如何加速? 谢谢老师!

def loss_fun(p, x, y): a, b, c, d = p m = x.shape[0] J = ((1+a np.exp(-b (x-c)))/(1-a np.exp(-b (x-c))) * d - y) ** 2 J = sum(J)/m return J

def func(p): a, b, c, d = p return loss_fun(p, x, y)

x = np.arange(1, 201) result = [] for i in range(Array.shape[1]):
y = A[:, i] ga = GA(func=func, n_dim=4, size_pop=50, max_iter=800, prob_mut=0.001, precision=1e-7) weight, f = ga.run() result.append(weight)