Advertisement
jensyao

Overflow in ipykernel

Feb 9th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. def obj_gradA(w,x,y):
  2.     grad = []
  3.     yh = yhat(x,w)
  4.     for j in range(len(w)):
  5.         tmp = 0
  6.         for i in range(len(x)):
  7.             tmp = tmp+yh[i]*(y[i]-yh[i])*(1-yh[i])*x[i,j]
  8.         grad.append(-2*tmp)
  9.     return np.array(grad)
  10.  
  11. def obj_gradB(w,x,y):
  12.     grad = []
  13.     yh = yhat(x,w)
  14.     tmp = yh*(y-yh)*(1-yh)
  15.     for j in range(len(w)):
  16.         grad.append(-2*np.sum(tmp*x[:,j]))
  17.     return np.array(grad)
  18.  
  19. def obj_gradC(w,x,y):
  20.     yh = yhat(x,w)
  21.     return -2*np.dot(yh*(y-yh)*(1-yh,x))
  22.  
  23. from scipy.optimize import minimize
  24. w_start = np.random.rand(*w_exact.shape)
  25. w_found = minimize(obj, w_start, method = 'Nelder-Mead',args=(x_rand,y))
  26. print(w_found)
  27. print('exact val', w_exact)
  28.  final_simplex: (array([[ 1806.07992755,  -358.33266465],
  29.        [ 1806.07999633,  -358.33267886],
  30.        [ 1806.07999898,  -358.33267909]]), array([-6.67715058, -6.67715058, -6.67715058]))
  31.            fun: -6.6771505843807075
  32.        message: 'Optimization terminated successfully.'
  33.           nfev: 195
  34.            nit: 78
  35.         status: 0
  36.        success: True
  37.              x: array([ 1806.07992755,  -358.33266465])
  38. exact val [5 3]
  39. C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\__main__.py:2: RuntimeWarning: overflow encountered in exp
  40.   from ipykernel import kernelapp as app
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement