Guest User

Untitled

a guest
Mar 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import cvxpy as cp
  2. import numpy as np
  3.  
  4. objective = cp.Minimize(0.5 / n * cp.sum_squares(y - X_model * beta))
  5. problem = cp.Problem(objective)
  6. result = problem.solve()
  7. betas = beta.value
  8.  
  9. def quantile_function(tau_val, x):
  10. return 0.5 * abs(x) + (tau_val - 0.5)*x
  11.  
  12. objective = cp.Minimize(np.sum(quantile_function(tau_val=tau, x=(y - X_model * beta))))
  13. problem = cp.Problem(objective)
  14. result1 = problem.solve()
  15. betas1 = beta.value
  16.  
  17. Traceback (most recent call last):
  18. File "<input>", line 1, in <module>
  19. File "<input>", line 2, in quantile_function
  20. TypeError: bad operand type for abs(): 'AddExpression'
  21.  
  22. objective = 0
  23. for i in range(n):
  24. tmp = y[i] - np.sum(X_model[i,:] * beta)
  25. objective += 0.5 * abs(tmp) + (tau - 0.5) * tmp
  26.  
  27. prob = cp.Problem(cp.Minimize(objective))
Add Comment
Please, Sign In to add comment