【发布时间】:2018-10-20 09:36:59
【问题描述】:
Weight1、Weight2、bias1、bias2 是随机列表:
list1= [[(list of Weight1)], [(list of Weight2)], [(list of bias1)], [list of bias2)]]- l
ist2= [[(list of Weight1)], [(list of Weight2)], [(list of bias1)], [list of bias2)]] list3= [[(list of Weight1)], [(list of Weight2)], [(list of bias1)], [list of bias2)]]
popSize=3
如何获得具有最小tot_error的权重和偏差(Weight1,Weight2,bias1,bias2)
def findGStar(Weight1, Weight2, bias1, bias2):
z1 = X_trainNorm.dot(Weight1) + bias1
a1 = np.tanh(z1)
z2 = a1.dot(Weight2) + bias2
target = np.reshape(y_trainNorm,(-1,1))
error = 0
error = abs(z2-target)
tot_error = sum(error)
return tot_error
vec = []
for i in range(popSize):
vector_new = findGStar(vector[i][0], vector[i][1], vector[i][2], vector[i][3])
vec.append(vector_new)
vec.sort()
minimum = vec[0]
【问题讨论】:
标签: python python-3.x numpy machine-learning neural-network