SHARE
TWEET

Untitled

a guest May 21st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def compute_alphas(gradients, nu):
  2.     # TODO: Look into both versions with minus and without minus sign
  3.     H = compute_dot_product_matrix(gradients)
  4.     m = len(gradients)
  5.     n = len(gradients[0])
  6.    
  7.  
  8.     #Converting into cvxopt format
  9.     P = cvxopt_matrix(H)
  10.     q = cvxopt_matrix(-np.zeros((m, 1)))
  11.    
  12.     G = np.vstack((np.eye(m), -np.eye(m)))
  13.     print('G:', G)
  14.     G = cvxopt_matrix(G)
  15.    
  16.     h = np.append(np.full((m,), fill_value=1/m),  np.zeros(m))
  17.     print('h:', h)
  18.     h = cvxopt_matrix(h)
  19.    
  20.    
  21.     A = cvxopt_matrix(np.ones((1, m)))
  22.    
  23.     b = cvxopt_matrix(np.ones(1)*nu)
  24.  
  25.     #Setting solver parameters (change default to decrease tolerance)
  26.     cvxopt_solvers.options['show_progress'] = True
  27.     cvxopt_solvers.options['abstol'] = 1e-10
  28.     cvxopt_solvers.options['reltol'] = 1e-10
  29.     cvxopt_solvers.options['feastol'] = 1e-10
  30.  
  31.     #Run solver
  32.     sol = cvxopt_solvers.qp(P, q, G, h, A, b)
  33.     alphas = np.array(sol['x'])
  34.     return alphas
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top