Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cvxpy as cp
- import numpy as np
- objective = cp.Minimize(0.5 / n * cp.sum_squares(y - X_model * beta))
- problem = cp.Problem(objective)
- result = problem.solve()
- betas = beta.value
- def quantile_function(tau_val, x):
- return 0.5 * abs(x) + (tau_val - 0.5)*x
- objective = cp.Minimize(np.sum(quantile_function(tau_val=tau, x=(y - X_model * beta))))
- problem = cp.Problem(objective)
- result1 = problem.solve()
- betas1 = beta.value
- Traceback (most recent call last):
- File "<input>", line 1, in <module>
- File "<input>", line 2, in quantile_function
- TypeError: bad operand type for abs(): 'AddExpression'
- objective = 0
- for i in range(n):
- tmp = y[i] - np.sum(X_model[i,:] * beta)
- objective += 0.5 * abs(tmp) + (tau - 0.5) * tmp
- prob = cp.Problem(cp.Minimize(objective))
Add Comment
Please, Sign In to add comment