Simmetrical Constraints in Multivariate Regression
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mario
am 25 Jan. 2025
Bearbeitet: John D'Errico
am 25 Jan. 2025
Hi everyone!
This is my problem:
My data are related in this way: F = H*V + B*A where F is a 2xn matrix, V and A are 2xn matrices while H and B are 2x2 matrices.
H and B must be simmetrical.
I've already got F, V and A and I want to calculate H and B with a multivariate regression. How can I do it?
Thank you in advance!
1 Kommentar
John D'Errico
am 25 Jan. 2025
Bearbeitet: John D'Errico
am 25 Jan. 2025
Will you please not keep on asking the same question daily? adding additional information each day? I've closed your last question, because it said nothing different (and less) than the current one.
Akzeptierte Antwort
John D'Errico
am 25 Jan. 2025
Bearbeitet: John D'Errico
am 25 Jan. 2025
Now please stop asking this question. I already suggested 3 ways you MIGHT solve it, the first time you asked. You could have added this additional information to your last question, or added a comment to my answer.
Since you give no data, I'll make some up.
F = rand(2,20);
A = rand(2,20);
V = rand(2,20);
And now the solution. I'll use an optimproblem, which makes it very clear what I am doing.
prob = optimproblem
Note that the default is to minimize, which is perfect for our problem.
% Two unknown arrays.
H = optimvar('H',[2,2]);
B = optimvar('B',[2,2]);
% an objective, just the sum of squares of all errors.
obj = sum((F - (H*V + B*A)).^2,'all');
prob.Objective = obj;
% and two constraints of SYMMETRY.
prob.Constraints.H = H == H.';
prob.Constraints.B = B == B.';
% Some starting values, but they will be ignored
% since lsqlin will be the solver. Solve demands
% starting values, even though lsqlin laughs at the idea.
X0.H = eye(2);
X0.B = eye(2);
% and see what solve has to say
res = solve(prob,X0,solver = 'lsqlin')
res.H
res.B
As you can see, two nicely symmetric matrices. The beauty of this approach is it lets the optimproblem and solve do all the thinking for you, in terms of how to implement the constraints, and how to farm out the solution to lsqlin. You might argue the downside is it hides some of the intracacies inside solve and the optimproblem. But at the same time, you probably don't appreciate the intracacies of how lsqlin solves the problem in the first place. So this approach really costs you little, yet gains a lot.
I could have set it up to go into lsqlin directly, but that would have been a bit less clear what I was doing. The solution itself would have obfuscated what I was doing. It could be instructive for you to look at how lsqlin would be set up directly without recourse to an optimproblem. But I would suggest you do that yourself, in the event that you really wanted to solve it that way. The only way to learn is by doing.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear Least Squares finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!