Given data $(y_1, ..., y_n)$ and each $y_i \in \mathbb{R}^p$, and $V$ is a $p \times q$ matrix with $q$ orthogonal unit vectors as columns. How do I differentiate the following ? And what is the solution ?
$$\min_{V} \sum^N_{i=1} || y_i - V V^T y_i ||^2$$
This is not a complete anwer but it may help. (It is more a reformulation than an answer but it was too long for a comment)
Briefly, the requested minimum is the sum of the first $p-q$ eigenvalues of the matrix $YY^T$ (see below)
Since the columns of $V$ form an orthonormal system, the vector $VV^Ty$ is just the component of $y$ along the space spanned by the columns of $V$.
If follows that $y-VV^Ty$ is the projection of $y$ to the orthogonal of the columns of $V$.
As a corollary we get immediately that if $p=q$ then the requestet minumum is always zero.
In general if we denote by $y^W$ the orthogonal projection of $y$ over a space $W$, we have $||y-VV^Ty||=||y^W||$, where $W$ is the orthogonal of the columns of $V$. In particular $$\min_V=\sum_i||y_i-VV^Ty_i||^2=\min_W\sum_i||y_i^W||^2$$ where now the minimum is taken over all spaces $W$ of dimension $p-q$. If $w_i,\dots,w_{p-q}$ is an orthonormal basis of $W$ we have $$||y^W||^2=\sum_j\langle y,w_j\rangle^2=\sum_j\langle y\langle y,w_j\rangle,w_j\rangle$$
If we denote by $Y$ the matrix which has by columns the vectors $y_i$ we have that $$YY^Tw_j=\sum_iy_i\langle y_i,w_j\rangle$$ therefore $$\sum_i||y_i^W||^2=\sum_{i,j}\langle y_i\langle y_i,w_j\rangle,w_j\rangle=\sum_j\langle\sum_i y_i\langle y_i,w_j\rangle,w_j\rangle=\sum_j\langle YY^Tw_j,w_j\rangle$$
In conclusion, the requestet minimum equals $$\min_{w_1,\dots,w_{p-q}}\sum_j\langle Aw_j,w_j\rangle$$
Where $A=YY^T$ ant the minimum is taken over all choices of $p-q$ orthonormal vectors. Since $A$ is symmetric, it can be diagonalyzed by an orthonormal basis. (Note alson that the condition $A=YY^T$ implies that the eigenvalues of $A$ are positives as $\langle Ax,x\rangle=\langle Y^Tx,Y^Tx\rangle$)
If we denote by $\lambda_1\leq\lambda_2\leq\dots\leq\lambda_p$ the eigenvalues of $A$, the requestet minimum is just $$\lambda_1+\dots+\lambda_{p-q}$$ that is to say, the sum of the first $p-q$ eigenvalues of $A=YY^T$
So the original answer translates as "how can we differentiate the eigenvalues of a matrix of the form $YY^T$ with respect to the components of $Y$?"