-2
$\begingroup$

The closed-loop dynamics of a linear optimal controller are simple but have interesting properties. From a starting state $\mathbf{v}(0)$ the dynamic can be iterated to reach a final state $\mathbf{v}(N)$ as in

$$ \mathbf{v}(N) = (A - BC)^N\mathbf{v}(0). $$

I would like to optimize the transition parameter matrix $A$ through gradient descent with rate $\eta$:

$$ A' = A - \eta\frac{df}{dA} $$

with loss function $f$ is the error between a generic resultant state $(A - BC)^N\mathbf{v}$ and a target state $\mathbf{w}$. $\newcommand\norm[1]{\lVert#1\rVert}$I'm struggling to find the derivative $\frac{\partial{f(A)}}{\partial{A}}$ of this scalar loss function (L2 norm) $$ f(A) = \norm{(A - BC)^N\mathbf{v} - \mathbf{w}}_2^2 $$ where $A\in\mathbb{R}^{n\times n}$, $B\in\mathbb{R}^{n\times m}$, $C\in\mathbb{R}^{m\times n}$, and $\mathbf{v},\mathbf{w}\in\mathbb{R}^{n}$.

Using chain rule, I can write this as $$ \frac{\partial{f(X)}}{\partial{X}} = \frac{\partial{f(X)}}{\partial{g(X)}} \frac{\partial{g(X)}}{\partial{h(X)}} \frac{\partial{h(X)}}{\partial{X}} $$ where \begin{align*} f(X) & {}= g(h(X)) \\ g(X) & {}= \norm{X\mathbf{v} - \mathbf{w}}_2^2 \\ h(X) & {}= (X-BC)^N. \end{align*}

The problem is, I'm not clear on how to take these these intermediate derivatives.

$\endgroup$
2
  • $\begingroup$ You have $f(X) = g(h(X))$, and then you define $g(X)$ and $q(X)$. Presumably $q$ is meant to be $h$? $\endgroup$
    – LSpice
    Commented Feb 20, 2021 at 16:54
  • $\begingroup$ fixed, thank you $\endgroup$ Commented Feb 20, 2021 at 17:27

1 Answer 1

0
$\begingroup$

Note that $A$ only appears in the combination $M=A-BC$, so the derivative with respect to $A$ equals the derivative with respect to $M$; The function $f(A)$ is given by $$f(A)=||(A - BC)^Nv - w||_2^2=(M^Nv)^T M^Nv+w^Tw-2w^TM^Nv.$$ For a simple case, let me first consider a scalar perturbation, $f(A+\epsilon I)=f(A)+\epsilon df/dA$, with derivative $$\frac{df}{dA} =2N(M^Nv-w)^TM^{N-1}v.$$

Next consider the derivative with respect to a given matrix element $A_{ij}$ of $A$. The expressions are more lengthy, basically each matrix $M$ gives a separate term so we have a sum $\sum_{k=1}^N$ instead of the factor $N$: $$\frac{\partial f}{\partial A_{ij}}= 2\sum_{k=1}^N\sum_{p,q=1}^n (M^Nv-w)_q (M^{k-1})_{qi} (M^{N-k})_{jp} v_p.$$ Note that the scalar perturbation is the trace of the matrix of elementwise perturbations, $df/dA=\sum_{i=1}^n \partial f/\partial A_{ii}$.

$\endgroup$
8
  • $\begingroup$ Thanks Professor Beenakker. I'm a little confused why the gradient here is scalar, when I expected a gradient in terms of the elements of A? That is, I expect the gradient here to tell me the change in f(A) with respect to each element of A. What am I missing? $\endgroup$ Commented Feb 20, 2021 at 21:35
  • $\begingroup$ Yes, this is for a scalar perturbation, $f(A+\epsilon I)=f(A)+\epsilon \partial f/\partial A$. The expressions for the derivative with respect to a given matrix element of A are more lengthy, I will write them down tomorrow. $\endgroup$ Commented Feb 20, 2021 at 22:55
  • $\begingroup$ I see, this makes sense. Thank you. This calculator is interesting-- I'm not able to reproduce the scalar perturbation but it produces a nice-looking solution for a general derivative with input norm2((A-B*C).^N*v-w)^2. I'm curious to see if the answer there is interpretable to you. It's difficult for me to form an intuition about it unfortunately. $\endgroup$ Commented Feb 20, 2021 at 23:33
  • $\begingroup$ my answer for the elementwise derivative is not what I seem to get from this online calculator, which gives (if I understand the syntax correctly) that $\partial f/\partial A_{ij}= 2N(M^Nv-w)_i (M^{N-1})_{ij} v_j.$ I don't understand why. This latter result also does not satisfy the relation that the scalar derivative is the trace of the matrix of elementwise derivatives. Quite possibly I am missing something essential. $\endgroup$ Commented Feb 21, 2021 at 12:58
  • $\begingroup$ Thanks Professor! I've numerically confirmed the online calculator and your scalar perturbation results. I discovered the online calculator is performing elementwise exponentiation, explaining the discrepancy. I'm working now to convert your elementwise derivative to a matrix expression for computation. It seems a tensor product might help. Context: I'm working on gradient descent for Markov dynamical systems. If you have any references or suggestions to help me proceed with similar calculations, I would be very grateful. I'm hoping to compute second-order (Newton's method) as well. $\endgroup$ Commented Feb 21, 2021 at 16:26

Not the answer you're looking for? Browse other questions tagged .