Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def compute_alphas(gradients, nu):
- # TODO: Look into both versions with minus and without minus sign
- H = compute_dot_product_matrix(gradients)
- m = len(gradients)
- n = len(gradients[0])
- #Converting into cvxopt format
- P = cvxopt_matrix(H)
- q = cvxopt_matrix(-np.zeros((m, 1)))
- G = np.vstack((np.eye(m), -np.eye(m)))
- print('G:', G)
- G = cvxopt_matrix(G)
- h = np.append(np.full((m,), fill_value=1/m), np.zeros(m))
- print('h:', h)
- h = cvxopt_matrix(h)
- A = cvxopt_matrix(np.ones((1, m)))
- b = cvxopt_matrix(np.ones(1)*nu)
- #Setting solver parameters (change default to decrease tolerance)
- cvxopt_solvers.options['show_progress'] = True
- cvxopt_solvers.options['abstol'] = 1e-10
- cvxopt_solvers.options['reltol'] = 1e-10
- cvxopt_solvers.options['feastol'] = 1e-10
- #Run solver
- sol = cvxopt_solvers.qp(P, q, G, h, A, b)
- alphas = np.array(sol['x'])
- return alphas
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement