如何在CVXPY中取quad_form输出的平方根? [英] How to take the square root of quad_form output in CVXPY?

查看:1516
本文介绍了如何在CVXPY中取quad_form输出的平方根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决在目标函数中涉及 \sqrt {w ^ t \Sigma w} 的问题。为了计算 w ^ t \Sigma w ,我使用 quad_form 函数。如何取其平方根?

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?

在代码中尝试写入

risk = sqrt(quad_form(w, E))

我收到DCP规则错误,但我很确定鉴于我还有其他限制,它是凸的。因此,问题实际上不是数学,而是凸程序的实际实现。

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.

我要解决的问题是

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)


推荐答案

为了采用二次形式的平方根,矩阵 Sigma 必须为正半定数。计算胆固醇分解 Sigma = QT * Q ,然后在目标函数中包含项 norm(Q * w,2)

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.

这篇关于如何在CVXPY中取quad_form输出的平方根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆