[英]Solve matrix equation in matlab
I have an equation of the type c = Ax + By
where c
, x
and y
are vectors of dimensions say 50,000 X 1, and A
and B
are matrices with dimensions 50,000 X 50,000. 我有一个类型
c = Ax + By
的等式,其中c
, x
和y
是尺寸为50,000 X 1的向量, A
和B
是尺寸为50,000 X 50,000的矩阵。
Is there any way in Matlab to find matrices A
and B
when c
, x
and y
are known? 当
c
, x
和y
已知时,Matlab中是否有任何方法可以找到矩阵A
和B
?
I have about 100,000 samples of c
, x
, and y
. 我有大约100,000个
c
, x
和y
样本。 A
and B
remain the same for all. A
和B
对所有人保持不变。
Let X
be the collection of all 100,000 x
s you got (such that the i
-th column of X
equals the x_i
-th vector). 设
X
是你得到的所有100,000 x
s的集合(这样X
的第i
列等于x_i
-th向量)。
In the same manner we can define Y
and C
as 2D collections of y
s and c
s respectively. 以相同的方式,我们可以将
Y
和C
分别定义为y
s和c
s的2D集合。
What you wish to solve is for A
and B
such that 你想要解决的是
A
和B
这样的
C = AX + BY
You have 2 * 50,000^2 unknowns (all entries of A
and B
) and numel(C)
equations. 您有2 * 50,000 ^ 2个未知数(
A
和B
所有条目)和numel(C)
方程。
So, if the number of data vectors you have is 100,000 you have a single solution (up to linearly dependent samples). 因此,如果您拥有的数据向量数为100,000,则您只有一个解决方案(最多取决于线性相关的样本)。 If you have more than 100,000 samples you may seek for a least-squares solution.
如果您有超过100,000个样本,您可以寻求最小二乘解。
Re-writing: 重新书写:
C = [A B] * [X ; Y] ==> [X' Y'] * [A';B'] = C'
So, I suppose 所以,我想
[A' ; B'] = pinv( [X' Y'] ) * C'
In matlab: 在matlab中:
ABt = pinv( [X' Y'] ) * C';
A = ABt(1:50000,:)';
B = ABt(50001:end,:)';
Correct me if I'm wrong... 如我错了请纠正我...
EDIT: 编辑:
It seems like there is quite a fuss around dimensionality here. 这里似乎有很大的维度。 So, I'll try and make it as clear as possible.
所以,我会尽量让它变得清晰。
Model: There are two (unknown) matrices A
and B
, each of size 50,000x50,000 (total 5e9 unknowns). 模型:有两个(未知)矩阵
A
和B
,每个矩阵大小为50,000x50,000(总共5e9个未知数)。
An observation is a triplet of vectors : ( x
, y
, c
) each such vector has 50,000 elements (total of 150,000 observed points at each sample ). 观察是向量的三元组:(
x
, y
, c
)每个这样的载体具有50,000个元素( 每个样品总共150,000个观察点)。 The underlying model assumption is that an observation is generated by c = Ax + By
in this model. 基础模型假设是在该模型中由
c = Ax + By
生成观测值。
The task: given n
observations (that is n
triplets of vectors { ( x_i
, y_i
, c_i
) }_ i=1..n
) the task is to uncover A
and B
. 任务:给定
n
观测值(即n
三元组的向量 {( x_i
, y_i
, c_i
)} _ i=1..n
),任务是揭示A
和B
Now, each sample ( x_i
, y_i
, c_i
) induces 50,000 equations of the form c_i = Ax_i + By_i
in the unknown A
and B
. 现在,每个样本(
x_i
, y_i
, c_i
)在未知A
和B
c_i = Ax_i + By_i
形式为c_i = Ax_i + By_i
50,000个方程。 If the number of samples n
is greater than 100,000, then there are more than 50,000 * 100,000 ( > 5e9 ) equations and the system is over constraint . 如果样本数
n
大于 100,000,则存在超过50,000 * 100,000(> 5e9)个方程,并且系统超出约束 。
To write the system in a matrix form I proposed to stack all observations into matrices: 为了以矩阵形式编写系统,我建议将所有观察结果堆叠到矩阵中:
X
of size 50,000 x n
with its i
-th column equals to observed x_i
X
的大小为50,000 x n
,其第i
列等于观察到的x_i
Y
of size 50,000 x n
with its i
-th column equals to observed y_i
Y
的大小为50,000 x n
,其第i
列等于观察到的y_i
C
of size 50,000 x n
with its i
-th column equals to observed c_i
C
的大小为50,000 x n
,其第i
列等于观察到的c_i
With these matrices we can write the model as: 使用这些矩阵,我们可以将模型编写为:
C = A*X + B*Y C = A * X + B * Y.
I hope this clears things up a bit. 我希望这可以解决一些问题。
Thank you @Dan and @woodchips for your interest and enlightening comments. 感谢@Dan和@woodchips的兴趣和启发性评论。
EDIT (2): 编辑(2):
Submitting the following code to octave . 提交以下代码到八度 。 In this example instead of 50,000 dimension I work with only 2, instead of
n=100,000
observations I settled for n=100
: 在这个例子而不是50,000维度我只使用2,而不是
n=100,000
观察我确定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';
Checking the difference between ground truth model ( A
and B
) and recovered ABt
: 检查地面实况模型(
A
和B
)与恢复的ABt
之间的差异:
ABt - [A' ; B']
Yields 产量
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
Which is close enough to zero. 哪个足够接近零。 (remember, the observations were noisy and solution is a least-square one).
(记住,观察结果是嘈杂的,解决方案是最不正方形的)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.