How to take the square root of quad_form output in CVXPY?

旧街凉风 提交于 2019-12-11 00:55:34

问题


I am trying to solve a problem that involves \sqrt{w^t \Sigma w} in the objective function. To compute w^t \Sigma w, I use the quad_form function. How do I take its square root?

When in the code I try to write

risk = sqrt(quad_form(w, E))

I am getting a DCP rule error but I am pretty sure it is convex given the other constraints I have. So the question is not really about maths but the actual implementation of the convex program.

The problem I am trying to solve is

ret = mu.T*w 
risk = sqrt(quad_form(w, E))
gamma.value = distr.pdf(distr.ppf(alpha)) / (1 - alpha)
minimizer = Minimize(-ret + risk * gamma) #cvxpy.sqrt(risk) * gamma) 
constraints = [w >= 0, 
               b.T * log(w) >= k] 
prob = Problem(minimizer, constraints)
prob.solve(solver='ECOS_BB',verbose=True)

回答1:


In order to take the square root of the quadratic form, matrix Sigma must be positive semidefinite. Compute a Cholesky decomposition Sigma = Q.T * Q and then include the term norm(Q*w,2) in your objective function.



来源:https://stackoverflow.com/questions/50539925/how-to-take-the-square-root-of-quad-form-output-in-cvxpy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!