Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

计算加速 #218

Open
xiaowodaweiwang opened this issue Sep 6, 2023 · 0 comments
Open

计算加速 #218

xiaowodaweiwang opened this issue Sep 6, 2023 · 0 comments

Comments

@xiaowodaweiwang
Copy link

xiaowodaweiwang commented Sep 6, 2023

老师您好,我想请问下,如何对一个多个循环做优化,例如对下面得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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant