我使用的是Scipy包中的L-BFGS-B优化器。这是documentation.
我的代码具有以下结构。目标函数是用来最小化“a”的目标函数。为此,obj_func只能返回“a”。你知道吗
问:有没有办法从objèu func获得“b”和“c”?你知道吗
目前我正在使用函数属性。但我不确定这是首选的方式。你知道吗
def obj_func(x, *args)
a, b, c = compute(x) # compute is where major computation happens
# I want to access b and c from outside the function
obj_func.result = [b,c] # use function attribute
return a
result = optimize.fmin_l_bfgs_b(obj_func, x0, bounds=bounds, args=args)
b, c = obj_func.result
目前没有回答
相关问题 更多 >
编程相关推荐