cvxpy:未定义'sum_entries' [英] cvxpy:'sum_entries' is not defined

查看:629
本文介绍了cvxpy:未定义'sum_entries'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CVXPY解决Python中的投资组合优化问题,但未定义错误sum_entries。我正在使用Anaconda 2.7和Jupyter笔记本。我已经使用conda pip install安装了cvxpy,msgpack,argpack和cvxopt。下面是代码片段。有建议吗?

I am trying to resolve a portfolio optimization problem in Python using CVXPY but getting an error sum_entries is not defined. I am using Anaconda 2.7 and Jupyter notebook. I have installed cvxpy, msgpack, argpack and cvxopt using conda pip install. Below is the snippet of the code. Any suggestions?

w=Variable(len(CovMatrix))
risk=quad_form(w,Sigma)
constraints=[]
constraints.append(w>=0)
constraints.append(sum_entries(w)==1)
prob=Problem(cvx.Minimize(risk),constraints)
prob.solve(solver='CVXOPT',verbose=True)

此处是我得到的错误:

NameError Traceback (most recent call last) <ipython-input-20-7f2f1e65a66e> in <module>() 4 constraints=[] 5 constraints.append(w>=0) ----> 6 constraints.append(sum_entries(w)==1) 7 8 

prob=Problem(cvx.Minimize(risk),constraints) NameError: name 


推荐答案

应为 cvx.sum_entries 而不是 sum_entries 。同样,您的问题应为 cvx.Problem

It should be cvx.sum_entries instead of sum_entries. Similarly, your Problem should be cvx.Problem.

这篇关于cvxpy:未定义'sum_entries'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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