Solve Matrix Equation in Matrix
I have an equation like c = Ax + By
where c
, x
and y
are size vectors, for example 50,000 X 1, and A
and B
are matrices with dimensions 50,000 x 50,000.
Is there a way in Matlab to find matrices A
and B
, when known c
, x
and y
?
I have about 100,000 samples c
, x
and y
. A
and B
remain unchanged for everyone.
source to share
Let be the X
collection of all 100,000 X
you got (so the i
th column X
equals the x_i
th vector).
In the same way we can define Y
and C
as two-dimensional collections Y
and C
respectively.
What you want to solve is A
and B
so that
C = AX + BY
You have 2 * 50,000 ^ 2 unknowns (all equation records A
and B
) and numel(C)
.
So, if you have 100,000 data vectors, you have one solution (up to linearly dependent samples). If you have more than 100,000 samples, you can search for a least squares solution.
rewriting:
C = [A B] * [X ; Y] ==> [X' Y'] * [A';B'] = C'
So I suppose
[A' ; B'] = pinv( [X' Y'] ) * C'
In Matlab:
ABt = pinv( [X' Y'] ) * C'; A = ABt(1:50000,:)'; B = ABt(50001:end,:)';
Correct me if I'm wrong ...
EDIT:
It looks like there is quite a bit of fuss around the dimension here. So I'll try to make it as clear as possible.
Model: There are two (unknown) matrices A
and B
, each of which is 50,000 x 50,000 in size (5e9 unknowns in total).
Observation is a triplet vectors ( X
, Y
, C
), each such vector has elements 50000 (total 150000 points observed in each sample). The underlying assumption of the model is that c = Ax + By
observation is created in this model .
Objective: taking into account n
the observations (i.e., n
triplets {vectors ( x_i
, y_i
, c_i
)} _ i=1..n
) task is to open A
and B
.
Now, each sample ( x_i
, y_i
, c_i
) induces 50,000 of equations c_i = Ax_i + By_i
in the unknown A
and B
. If the number of samples is n
more than 100,000, then there are more than 50,000 * 100,000 (> 5e9) equations, and the system is limited .
To write the system in matrix form, I suggested collecting all observations in matrices:
- A
X
50,000x matrixn
with itsi
th column is equal to the observedx_i
- A
Y
50,000x matrixn
with itsi
th column is equal to the observedy_i
- A
C
50,000x matrixn
with itsi
th column is equal to the observedc_i
With these matrices, we can write the model as:
C = A * X + B * Y
Hope this makes things a little easier.
Thanks @Dan and @woodchips for your interest and enlightening comments.
EDIT (2):
By sending the following code to octave . In this example, instead of 50,000 measurements, I only work with 2, instead of the n=100,000
observations I set for n=100
:
n = 100;
A = rand(2,2);
B = rand(2,2);
X = rand(2,n);
Y = rand(2,n);
C = A*X + B*Y + .001*randn(size(X)); % adding noise to observations
ABt = pinv( [ X' Y'] ) * C';
Check the difference between the ground truth model ( A
and B
) and reduced ABt
:
ABt - [A' ; B']
Yield
ans =
5.8457e-05 3.0483e-04
1.1023e-04 6.1842e-05
-1.2277e-04 -3.2866e-04
-3.1930e-05 -5.2149e-05
This is close enough to zero. (remember observations were noisy and the solution was least square).
source to share