神经网络-SGD-2

接上节:

3、梯度(gradient):

def numerical_gradient(f,x):

  h=1e-5

  grad=np.zeros_like(x)

  for index_x in range(x.size):

    tmp=x[index_x]

    x[index_x]=tmp+h

    fxh1=f(x)

    x[index_x]=tmp-h

    fxh2=f(x)

    grad[idx]=(fxh1-fxh2)/(2*h)

    x[index_x]=tmp

  return grad

 

posted @ 2019-04-01 15:40  竹心_兰君  阅读(197)  评论(0编辑  收藏  举报