【发布时间】:2020-09-07 10:48:21
【问题描述】:
我有一个错误函数,以及 self.array 上所有错误的总和:
#'array' looks something like this [[x1,y1],[x2,y2],[x3,y3],...,[xn,yn]]
#'distances' is an array with same length as array with different int values in it
def calcError(self,n,X,Y): #calculate distance of nth member of array from given point
X,Y = float(X),float(Y)
arrX = float(self.array[n][0])
arrY = float(self.array[n][1])
e = 2.71828
eToThePower = e**(-1*self.distances[n])
distanceFromPoint=math.sqrt((arrX-X)**2+(arrY-Y)**2)
return float(eToThePower*(distanceFromPoint-self.distances[n])**2)
def sumFunction(self,X,Y):
res = 0.0
for i in range(len(self.array)):
res += self.calcError(i,X,Y)
return res
我一直在寻找一种方法来查找 sumFunction 返回值最小的坐标。我听说过 scipy,但我正在寻找一种手动构建的方法。梯度下降似乎也不起作用,因为很难推导出这个求和函数。 谢谢!
【问题讨论】:
标签: python python-3.x gradient-descent