cvxpy约束矢量条件值
首先,我是Python的CVXPY模块的新手。
我对Python的CVXPY库中的约束有疑问。
我正在创建一个包含一些规格的向量权重。 我的问题是创建约束列表时。我的规格是:
- 重量不能大于0.2
- 重量总和不能大于1.0的
- 重量不能小于0的
- 所有权重大于0.07不能超过0.5 0.5
的问题。问题是最后一个。我不知道如何在约束定义中过滤体重内部的重量内部。 我认为这不是做到这一点的正确方法。但是我找不到可以在CVXPY网页中帮助/理解的东西。
import cvxpy as cv
w = cv.Variable(mu.shape[1])
constraint=[
cv.sum(w)==1, #all the values have to sum 1
cv.max(w)<=0.2, #each value cant be bigger than 0.2
cv.min(w)>=0.0, #each value cant be less than 0
# w[w>0.07].sum()<0.5 #MY PROBLEM, I dont know how to express this in cvxpy
]
预先感谢您的宝贵时间。
First of all I'm a newbie with the cvxpy module in python.
I have a doubt about the constraint in the CVXPY library in python.
I'm creating a vector weights that contains some specifications.
My problem is when I create the constraint list. My specifications are:
- weight cant be greater than 0.2
- weight sum cant be greater than 1.0
- weight cant be less than 0
- all the weights bigger than 0.07 cant sum more than 0.5
The problem is the last one. I dont know how to filter values inside weight inside is own in the constraint definition.
I think that is not the correct way to do it. But I cant find something that can help/understand in the CVXPY webpage.
import cvxpy as cv
w = cv.Variable(mu.shape[1])
constraint=[
cv.sum(w)==1, #all the values have to sum 1
cv.max(w)<=0.2, #each value cant be bigger than 0.2
cv.min(w)>=0.0, #each value cant be less than 0
# w[w>0.07].sum()<0.5 #MY PROBLEM, I dont know how to express this in cvxpy
]
Thank you in advance for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
try