How to use the weighted least square method for accurate calculation of parameters?
3 次查看(过去 30 天)
显示 更早的评论
I know this is a very basic questin but I am stuck with the problem for a long time.I have two matrices, B(352*1) and A(352*28). Using B and A, the X is required to be determined where X is a (28*1) matrix. One way is the use of backslash X=A\B. Other one is the use of weighted matrix. But I am not sure how can I use the weighted matrix concept. I have tried many ways to write the code but I get the inaccurate answers. It would be much appriciated if anyone can help me on this. I have attached the X_original, A, and B as .mat file.
1 个评论
Torsten
2023-7-19
I have tried many ways to write the code but I get the inaccurate answers.
If you know your code gives inaccurate answers, how do you measure this "degree of inaccuracy" ?
回答(1 个)
John D'Errico
2023-7-19
编辑:John D'Errico
2023-7-19
How many times will you ask this question? Please stop reposting it.
load X_actual
load A
load B
whos
A = A_primary_A;
B = Vp_ref_A_downsample_noise_final;
First, BEFORE YOU DO ANYTHING.
What is the rank of A? Is A a well conditioned matrix?
rank(A)
So A is 352x28, but it has rank 27. A IS SINGULAR!!!!!!! Wanting to use weights is a bit silly. (I'm sorry, but it is. Weights will not help you.) THE PROBLEM IS SINGULAR. THERE ARE INFINITELY MANY ANSWERS, all of which are equivalent. (And in this case, all of which will be equivalently poor. See below.)
Is there an exact solution anyway? That is, does B lie in the column space of A?
rank([A,B])
So B is NOT representable as a linear combination of the column of A. There is NO exact solution,
Is X_actual a solution? Of course not, since none exists.
norm(B)
norm(A*X_actual - B)
So your claimed "actual" solution is not even close. The error resulting from that solution is larger than the norm of B itself, which tells me that X_actual is not even close to being actual. Talk about signal to noise ratio.
How well can we do, using a simple tool, disregarding any question about weights?
Xest = lsqminnorm(A,B);
norm(A*Xest - B)
100*norm(A*Xest - B)/norm(B)
And that is, while not terribly small, considerably better than what X_actual yields. It predicts roughly 96% of the signal in B.
Again though, using weights is NOT your problem. And weights are irrelevant, since you have never given us any indication of what you think the weights should be, or how they would be derived. I think you are grasping at straws, hoping there is some magical solution, and you have heard the buzz word weights, so you have decided that is what you need.
Your problem lies in understanding what a singular matrix means, what it implies about the existence of a solution. Your problem is NOT in how to use weights to solve this system. Did you formulate the matrix A incorrectly? We cannot know that, since we are not told what A or B mean, or, for that matter, why you think X_actual has anything to do with the problem you have given us.
I would strongly suggest you start over. Make sure that A and B actually are computed correctly. Until then, there is nothing you can do. And skip the weights.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!