How to use the weighted least square method for accurate calculation of parameters?

3 Ansichten (letzte 30 Tage)
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 Kommentar
Torsten
Torsten am 19 Jul. 2023
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" ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

John D'Errico
John D'Errico am 19 Jul. 2023
Bearbeitet: John D'Errico am 19 Jul. 2023
How many times will you ask this question? Please stop reposting it.
load X_actual
load A
load B
whos
Name Size Bytes Class Attributes A_primary_A 352x28 78848 double Vp_ref_A_downsample_noise_final 352x1 2816 double X_actual 28x1 224 double ans 1x30 60 char cmdout 1x33 66 char
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)
ans = 27
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])
ans = 28
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)
ans = 2.6024e+03
norm(A*X_actual - B)
ans = 4.5078e+03
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)
ans = 115.1799
100*norm(A*Xest - B)/norm(B)
ans = 4.4259
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.

Produkte


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by