Need help with solving a system of linear equations

38 Views Asked by At

Given $n$ samples of vectors $\vec{x}\in R^k$ and n corresponding ground-truths $\vec{y}\in R^k$

I need to find the least square solution $A\vec{x}+\vec{b}=\vec{y}$ i.e. solve for $A$ and $\vec{b}$

Can someone please assist?

Thanks

1

There are 1 best solutions below

0
On

Assuming $A$ is any $k \times k$ matrix, you can flatten all its terms this way (for readability: example for k=2):

$$ \underbrace{ \begin{pmatrix} x_1^1 & x_2^1 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & x_1^1 & x_2^1 & 1 \\ x_1^2 & x_2^2 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & x_1^2 & x_2^2 & 1 \\ & & ... \end{pmatrix} }_M \underbrace{ \begin{pmatrix} a_{11} \\ a_{12} \\ b_1 \\ a_{21} \\ a_{22} \\ b_2 \\ \end{pmatrix} }_y = \underbrace{ \begin{pmatrix} y_1^1 \\ y_2^1 \\ y_1^2 \\ y_2^2 \\ ... \end{pmatrix} }_h $$

Superscript refers to the number of the sample and subscript the item index in the vector.

You could then solve this system using classical least square methods or by pseudo-inversion ($y = M^\dagger h$)