-1
我有一个函数,我想最小化。它是普通最小二乘的矢量化版本。使用数组作为参数最小化函数
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压扁我向量化被彻底打破(线822 0.13.2 scipy版本)。我甚至无法完成代码并查看结果,导致我没有足够的内存,并且一切都按照计算差异出现问题。