CVXMOD – Params

Params

Params are one of the two types of CVXMOD symbols. This page describes the specifics of params; read also about the features common to both symbol types.

Syntax: creating a parameter

param(name=None, rows=1, cols=1)
or
param(name=None, value=None) (rows and cols deduced from value)

Why use params?

Params are used as placeholders to postpone specifying data. This partitions problem creation from problem instantiation and solution. Params are also a repository for a priori information about problem details (such as sparsity structure, param positivity or matrix definiteness).

Example: param
>>> m = param('m')
>>> m
<1x1 param symbol m>

>>> param('A', 10, 5)
<10x5 param symbol A>
Example: param naming
>>> A = param('A', 10, 5)
>>> c = param('c', 5)
>>> A*c
<10x1 expression A*c; optvars: None>

>>> B = param(10, 5)
>>> d = param(5)
>>> B*d
<10x1 expression noname1*noname2; optvars: None>

Specifying param values

Convex problems involving params cannot be solved until all param values have been specified. To specify a param value, simply write to its value attribute.

Values can be retrieved either directly, with obj.value, or using the function value(obj). Using the value function has the advantage that it will behave consistently if obj is an integer, a float or a matrix (3.value would produce an error).

A param’s value should of course be the same size as the param itself. Sizes are checked for consistency immediately prior to solving optimization problems.

Example: specifying param values
>>> m = param('m', value=4)
>>> m
<1x1 param symbol m>
>>> m.value
4
>>> value(m)
4

>>> b = param('b', 3, 1)
>>> b.value = matrix((1,2,3.5))
>>> value(b)

[   1.000]
[   2.000]
[   3.500]

>>> 3.value
------------------------------------------------------------
   File "<ipython console>", line 1
     3.value
           ^
<type 'exceptions.SyntaxError'>: invalid syntax

>>> value(3)
3

Special params

These functions create ‘special’ params, which can be used like ordinary params, but have additional properties.

  • eyeobj(n) returns the size (n, n) symbolic identity matrix named I.

  • unitvec(i, rows) returns the ith symbolic unit vector named, for example, e2. (Consistent with indexing from zero, the i unitvec has entry i-1 = 1.

Extra information

Sometimes it is known ahead of time that a parameter is (say) positive, symmetric or negative semi-definite. These properties are handled in CVXMOD as param attributes. For example, if x is an optvar, set x.pos = True if x is positive. This can be useful for verifying convexity.

Available attributes for all params a:

  • a.pos means a geq 0.

  • a.neg means a leq 0.

Available attributes for square params A:

  • A.symm means A = A^T.

  • A.psd means A succeq 0 (A in S^{ntimes n}_+) and A = A^T.

  • A.nsd means A preceq 0 (A in S^{ntimes n}_-) and A = A^T.

Example: extra param information
>>> a = param('a')
>>> x = optvar('x')
>>> classify(a*square(x))
nothing special, as far as I know.

>>> a.pos = True
>>> classify(a*square(x))
positive; convex in x.