Obtaining jacobians of general nonlinear objective function and constraints from YALMIP's internal symbolic representation

131 views
Skip to first unread message

Mirko Hahn

unread,
Nov 5, 2014, 7:54:26 AM11/5/14
to yal...@googlegroups.com
Hi there,

I've been trying to implement a couple of cutting plane methods for mixed-integer nonlinear optimization using YALMIP. By this, I mean that I want to use YALMIP to solve the subproblems while writing the outer loops myself. I've so far tried the following ways of obtaining jacobians:
  • '@sdpvar/jacobian' and '@lmi/sdpvar': This only works for polynomial expressions but fails for more complicated nonlinear expressions.
  • 'compileinterfacedata' -> 'build_recursive_scheme' -> 'fmincon_fun'/'fmincon_grad': This is somewhat reverse-engineered, so I don't really know if this is even supposed to work. I found that gradients of nonlinear variables (i.e. variables with an extstruct) are computed correctly. However, linear relationships between variables (even auxilliary variables) don't seem to yield proper jacobians. I have so far been unable to find the appropriate data structures to implement this myself.

My question is as follows: Is there an intended way to obtain jacobians of general nonlinear objective functions and constraints using YALMIP? Note that the linearization points can be assumed to be the output of the most recent call to 'optimize'.

Thanks in advance,

Mirko Hahn

Johan Löfberg

unread,
Nov 5, 2014, 9:27:35 AM11/5/14
to yal...@googlegroups.com
jacobian only possible on polynomials.

Note sure what you mean with linear relations. If you do exp(ax+b), YALMIP will work internally (with fmincon etc) with the model exp(y), y == a*x+b


Mirko Hahn

unread,
Nov 5, 2014, 2:16:59 PM11/5/14
to yal...@googlegroups.com
Let's pick a simple example like:
x = sdpvar(1,1);
f = exp(5*x);
Let's say 'f' is my objective function. If I examine the output of 'compileinterfacedata', I see that YALMIP has introduced two auxilliary variables y and z, where
y == 5 * x,
z == exp(y).
The latter is encoded in an entry in the 'evalMap' field of the returned data structure whereas the former is encoded in a linear equation which can be found among the first 'K.f' lines of 'F_struc', which can be found in the same data structure. In my case, the variables are indexed in the following order: x, z, y. Prior clearing of the YALMIP internals means that no other variables exist.

What I'm looking for is (in this little example) (df/dx)(0), which should be equal to 5*exp(0) == 5. After applying (in that order) 'build_recursive_scheme' and 'yalmip2nonlinearsolver' (which I forgot to mention) to the output of 'compileinterfacedata', I call
[X, dX] = fmincon_fun([0 0], model);
where 'model' refers to the processed output of 'compileinterfacedata'. The output is
X == 1
dX == [0 1]

which correctly states that (df/dy)(0) = 1, but fails to take into account the definition of y as a multiple of x. To find out whether YALMIP did ignore this intermediate linear equality, I also ran
X = apply_recursive_evaluation(interface, [0 0 0]);
dX = full(apply_recursive_differentiation(interface, X, true(1,3));
and got
X == [0; 1; 0]
dX == [1 0;
       0 1;
       0 1]

With this simple example, I can probably circumvent this problem by solving a couple of linear equation systems using the output of 'apply_recursive_differentiation'. However, I also tried this with the more complicated example
f = exp(5 * exp(x))
To get df/dx in this case, I would have to do the same thing through multiple levels of the evaluation tree. So far, I haven't been able to figure out how to obtain information about the nodes in that tree that are implied by linear equations.

My question is: Is there a YALMIP function that recursively differentiates "through" the linear nodes (i.e. auxilliary variables fixed by linear equations) in the evaluation tree? If not, is there any way to examine either the compiled interface data or YALMIP's internal data structures (without any alterations to YALMIP's code) to figure out the full structure of the evaluation tree?

Johan Löfberg

unread,
Nov 5, 2014, 3:01:50 PM11/5/14
to
y is not a function of x, that is the whole idea. The artificial variable y is introduced to have the model in a normalized canonical form. y and x are two independent variables which have to satisfy y == 5*x at optimality. Hemce, with,e.g, exp(y)<=1, you will have two jacobians, one for the equality, and for the inequality, both depending on two variables (the jacobian for the linear stuff is done internally in fmincon, so YALMIP never has to deal with that, as all linear equalities and inequalities are communicated to fmincon when calling it. This in contrast to , e.g, ipopt, where YALMIP has to include the linear stuff)

Reply all
Reply to author
Forward
0 new messages