# How to optimize a singular covariance-weighted residual?

Definitions:

$$v(x)\equiv\{g_1(x),g_2(x),\ldots,g_n(x)\}^T$$

$$C\equiv \operatorname{cov}(v)=\langle vv^T \rangle -\langle v\rangle \langle v^T \rangle =\int f(x)v(x)v(x)^T \, dx-\int f(x)v(x) \, dx \int f(x')v(x')^T \, dx'$$

$$R(x)\equiv v(x)^T C^\dagger v(x)$$

z is an implicit parameter of f(x) and of all the g(x)'s. How can one go about optimizing R wrt z if C is singular?

For an non-singular D, then we'd simply use $\frac{d}{dz}D^{-1}=-D^{-1}\frac{dD}{dz}D^{-1}$.

I found this helpful EQUATION for the derivative of a pseudoinverse, but it only applies when the change in z does not change the rank of C, because an $\epsilon$-order variation in the null space of C creates a $\epsilon^{-1}$-order variation in the null space of $C^{\dagger}$, inducing an $\epsilon^{0}$-order change in R.

So R has possible discontinuities in z whenever the change in z induces a change the integer rank of C. I gather that I need to check the values of R at each of those discontinuities and also values of z where $\frac{dR}{dz}=0$ between the discontinuities. But I have no idea how to do either of those. Testing for when C changes from full rank to rank deficient is easy, just check if the determinate is zero or non-zero. But I don't what tests would tell us when the rank simply changes.

It's important in this problem to note that v(x) will always have 0 component in the null space of C, so that simplifies the problem a little and assures us that R and its discontinuities will always be finite.

So how can I go about optimizing R(x)?