在云上运行重组并行 python 代码的最佳方式
我有一个Python优化程序,它是这样的:
def optimize_score(alpha=0.5, init_point=tuple(np.ones(48)/48),total_paths=5000, iteration_size=0.02,iteration_limit=20):
best_point=init_point
point_size=np.size(init_point)
scores=np.zeros(point_size)
for i in range(iteration_limit):
#improve init_point 20 times
for j in range(point_size):
#find best directional improvement of previous best point
current_point=best_point*(1-iteration_size)
current_point[j]=current_point[j]+iteration_size
scores[j]=get_score(alpha=alpha, point=current_point,total_paths=total_paths)
best_direction=scores.index(min(scores))
best_point=best_point*(1-iteration_size)
best_point[best_direction]=best_point[best_direction]+iteration_size
return best_point
def get_score( alpha=0.5,point=tuple(np.ones(48)/48),total_paths=5000):
result=np.ones(total_paths)
for k in range(total_paths):
result[k]=get_result(path=k, point=point)
reward=result[0]
risk=reward-min(result)
score=risk-alpha*(risk+reward)
return score
get_result
很长,所以我不会在这里发布它。但本质上它返回一个浮点数,并从一个少于 100,000 行数据的小型数据库中读取
我正在尝试使用云来分割模拟计算,因为模拟在单台计算机上花费的时间太长。我找到了一个使用谷歌云的例子,但教程特别说它无法处理重组并行计算。任何人都有关于如何执行此操作的示例以及完成此类任务的最佳服务是什么?
I have a python optimization program that goes something like this:
def optimize_score(alpha=0.5, init_point=tuple(np.ones(48)/48),total_paths=5000, iteration_size=0.02,iteration_limit=20):
best_point=init_point
point_size=np.size(init_point)
scores=np.zeros(point_size)
for i in range(iteration_limit):
#improve init_point 20 times
for j in range(point_size):
#find best directional improvement of previous best point
current_point=best_point*(1-iteration_size)
current_point[j]=current_point[j]+iteration_size
scores[j]=get_score(alpha=alpha, point=current_point,total_paths=total_paths)
best_direction=scores.index(min(scores))
best_point=best_point*(1-iteration_size)
best_point[best_direction]=best_point[best_direction]+iteration_size
return best_point
def get_score( alpha=0.5,point=tuple(np.ones(48)/48),total_paths=5000):
result=np.ones(total_paths)
for k in range(total_paths):
result[k]=get_result(path=k, point=point)
reward=result[0]
risk=reward-min(result)
score=risk-alpha*(risk+reward)
return score
get_result
is quite long so I won't post it here. But essentially it returns a single floating number and is reading from a small database of less than 100,000 lines of data
I'm trying to split the simulation calculations using the cloud because the simulation takes too long on a single computer. I found an example using google cloud, but the tutorial specifically said it cannot handle recombining parallel calculation. Anyone has an example on how to do this and what's the best service for this kind of task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论