cvxpy:'sum_entries' is not defined

馋奶兔 提交于 2019-12-24 07:16:03

问题


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)

Here is the error I am getting:

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 

回答1:


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



来源:https://stackoverflow.com/questions/51139272/cvxpysum-entries-is-not-defined

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