如何对cvxopt矩阵执行运算? [英] How to perform operations on cvxopt-matrices a la numpy?

查看:373
本文介绍了如何对cvxopt矩阵执行运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cvxopt矩阵,以便在picos库中使用它们。总的来说,我想要一个矩阵,在某个向量上对其求值,减去某些东西,然后取其条目的最大绝对值

I am working with cvxopt matrices in order to use them in picos library. In general I want to take a matrix, evaluate it on a certain vector, subtract something, then take the biggest absolute value of its entries

import picos as pic
import cvxopt as cvx
import numpy as np

(...)

P = pic.Problem()
theta = P.add_variable('theta', size=k, vtype='continuous', lower=-10, upper=10)
theta

P.add_constraint(max(abs(M*theta - b)) <= 5)
P.minimize(theta)

(这里b是一些作为cvxopt矩阵处理的向量。)但是,我得到的错误如下:

(Here b is some vector treated as cvxopt matrix.) However, the error I get is the following:

TypeError                                 Traceback (most recent call last)
<ipython-input-11-8884e5cb14dc> in <module>
      3 theta
      4 
----> 5 P.add_constraint(max(abs(M*theta - b.T)) < 45)
      6 P.minimize(theta)
      7 

TypeError: 'Norm' object is not iterable

我想知道是否存在另一种方法可以进行这些计算, cvxopt?

I was wondering if there is an alternative way of making these computations that would be acceptable to cvxopt?

推荐答案

(几年前从未真正使用过这个lib,除了较小的实验)

(Never really used this lib apart from smaller experiments years ago)

在这些高度复杂的自动转换建模系统工具中,罪魁祸首是隐藏魔术的经典案例。

This looks like the culprit is the classic case of hidden-magic in those highly-complex automatic-transformation modelling system tools.


  • picos 过载 abs abs(M * theta-b)


    • 请参阅:文档

    • 这会导致 Norm 类型(基于picos的类型)

    • picos overloads abs in abs(M*theta - b)
      • see: doc
      • this results in type Norm (a picos-based type)

      • python的max-operator(不是从picos定制的东西)使用的是基于线性搜索的可迭代对象

      • 此处可迭代对象是 Norm 对象;但这不是迭代错误,因为错误显示

      • python's max-operator (not something customized from picos!) will be used which is based on linear-search on some iterable
      • the iterable here would be the Norm object; but it's not iterable as the error shows

      另请参见:重载运算符列表

      在我看来,此功能 max 丢失了。您可以手动将其线性化,但是很好...这很烦人。

      It seems to me, this feature max is missing. You can linearize it manually, but well... that's annoying.

      如果您不需要特殊的picos,请 cvxpy 非常相似,还支持 abs max (并且基于scipy的稀疏矩阵+ numpy数组;感谢上帝!)。

      If you don't need something special of picos, cvxpy is very similar and also supports abs and max (and is based on scipy's sparse-matrices + numpy-arrays; thank god!).

      这篇关于如何对cvxopt矩阵执行运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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