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?