【发布时间】:2014-02-07 04:23:55
【问题描述】:
我有一个功能,我想最小化。它是普通最小二乘法的矢量化版本。
import numpy as np
from scipy import optimize
def lr_cost_function(theta, x, y, derivative = False, hypotesis=linear_hypotesis, polynom = 1):
hyp = hypotesis(theta, x, polynom)
print("Hyp: ", hyp.shape)
dif = hyp - y
print("Dif:", dif.shape)
reuslt = dot(dif.T,dif)
print("RES", reuslt.shape)
return 1/len(y)*(dot(dif.T,dif)[0,0])
def linear_hypotesis(theta, x, polynom = 1):
print(x.shape, theta.shape, type(theta))
return np.dot(x, theta)
所以我这样调用最小化:
optimize.minimize(fun=lr_cost_function, x0=theta_copy, args=(x, y))
并且我的代码无法完成,因为在 optimize.py 参数中 x0 变平并且我的矢量化被完全破坏(0.13.2 scipy 版本中的第 822 行)。我什至无法完成代码并查看结果,因为我没有足够的内存,并且在计算差异时一切都出错了。
【问题讨论】: