Is it possible to optimize correlation coefficient under linear constraint? I am new to optimization and recently bump into a problem where I have to optimize the correlation coefficient of a series of values with the absolute value of another vector under the linear constraint, but I am not sure if optimization correlation is possible and stable? If it is, should it be seen as nonlinear programming or quadratic programming? Any package recommendation in R?
Additional information:
I have a vector B which is given,for example :\begin{bmatrix}25&7&0.2&5.8&1.17&0.25\end{bmatrix}
I also have a matrix A which is also known:
\begin{bmatrix}0&1&-1&0&0&0\\-1&0&2&0&1&1\\1&0&-1&0&1&-1\end{bmatrix}
The vector V is unknown and the input value should have both positive and negative values:\begin{bmatrix}v1\\v2\\v3\\v4\\v5\\v6\end{bmatrix}
The linear constraint will be:
A V=0
The objective function is to maximize the correlation of the absolute value of vector V with vector B under the constraint that A V=0
Thank you!
 A: In case you want to maximize Pearson's correlation coefficient, it seems to be a unconstrained optimization problem with linear objective function, linear equality constraints and one quadratic equality constraint that can be solved using the BFGS algorithm.
Instead of considering $B\in\mathbb{R}^d$, consider its shifted version
$$b=B-(\frac{1}{d}\sum_{i=1}^dB_i)\cdot(1, \ldots, 1)^T$$
that satisfies $\frac{1}{d}\sum_{i=1}b_i=0$. For that (fixed) $b$, let $w_i=\frac{b_i}{\|b\|_2}$. By definition, Pearsons correlation coefficient of $b$ and an other vector $v\in\mathbb{R}^d$ such that $\frac{1}{d}\sum_{i=1}^d v_i=0$ and $\|v\|_2=1$ is simply
$$\text{corr}(b, v)=\sum_{i=1}^d w_i\cdot v_i$$
Particularly, you are looking for $v\in\mathbb{R}^d$ such that
$$\max \sum_{i=1}^d w_i\cdot v_i$$
subject to
$$A\cdot (v+(\frac{1}{d}\sum_{i=1}^dB_i)\cdot(1, \ldots, 1)^T) =0 \text{ and } \sum_{i=1}^d v_i = 0 \text{ and }  \sum_{i=1}^d v_i^2 = 1$$
Except for the spherical constraint $\sum_{i=1}^d v_i^2 = 1$, everything is linear. As all constraints are equality constraints, using Lagrange Multipliers, this optimisation problem can be re-written to a unconstrained one, which than can be solved using the BFGS algorithm (the R package optim seems to have an implementation of this).
Given such a vector $v$ that solves this optimization problem, the shifted vector $V:=v+(\frac{1}{d}\sum_{i=1}^dB_i)\cdot(1, \ldots, 1)^T$ has maximal correlation to $B$ such that $A\cdot V =0$.
