Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. _count_oracle0 = 0
  2. _count_oracle1 = 0
  3. _count_oracle2 = 0
  4.  
  5.  
  6. def sigmoid(w):
  7.     res = scipy.special.expit(w)
  8.     return res
  9.  
  10. def predict(w):
  11.     return sigmoid(X @ w)
  12.  
  13. def oracle0(w):
  14.     p = X @ (w)
  15.     res = -np.mean(y*p - np.logaddexp(0, p))
  16.     global _count_oracle0
  17.     _count_oracle0 += 1
  18.     return res
  19.  
  20. def oracle1(w):
  21.     global _count_oracle1
  22.     _count_oracle1 += 1
  23.     return X.T @ (predict(w) - y) / X.shape[0]
  24.  
  25. def oracle2(w, d):
  26.     global _count_oracle2
  27.     _count_oracle2 += 1
  28.     res = X @ d
  29.     res = (predict(w) * (1 - predict(w))) * res
  30.     res = X.T @ res
  31.     return res / X.shape[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement