scipy.optimize.fmin结果形状不正确

时间:2016-08-19 19:52:50

标签: python numpy optimization

我想最小化以矩阵whith(3,1)形状作为参数的函数。 我使用scipy.optimize.fmin()。问题是函数fmin()返回形状为(1,)的1D结果。这导致计算错误(点积等问题)如何解决这个问题?

theta=np.zeros((3,1))
def sigmoid(x,mytheta):
    return 1.0/(1.0+np.exp(-np.dot(x,mytheta)))
def costfunction(mytheta,x,y):
    h_xvector=sigmoid(x,mytheta)
    term1=-y*np.log(h_xvector)
    term2=(1-y)*np.log(1-h_xvector)
    J=(1.0/m)*np.sum(term1-term2)
    return J
def optimizeth(mytheta,x,y):
    result=opt.fmin(costfunction,x0=mytheta,args=(x,y),maxiter=400,full_output=True,retall=True)
    return result[0],result[1]
(result, value)=optimizeth(theta,X,Y)

X是(100,3)形状矩阵,Y是(100,1)形状矩阵。

0 个答案:

没有答案
相关问题