|
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)
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 valuesConvex 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 Extra informationSometimes it is known ahead of time that a parameter is (say) positive, symmetric or negative semidefinite. 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:
Available attributes for square params A:
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. |