Simmetrical Constraints in Multivariate Regression

3 Ansichten (letzte 30 Tage)
Mario
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
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
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
prob =
OptimizationProblem with properties: Description: '' ObjectiveSense: 'minimize' Variables: [0x0 struct] containing 0 OptimizationVariables Objective: [0x0 OptimizationExpression] Constraints: [0x0 struct] containing 0 OptimizationConstraints No problem defined.
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')
Solving problem using lsqlin. The interior-point-convex algorithm does not accept an initial point. Ignoring X0. Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
res = struct with fields:
B: [2x2 double] H: [2x2 double]
res.H
ans = 2×2
0.2192 -0.0289 -0.0289 0.1215
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
res.B
ans = 2×2
0.1182 0.6452 0.6452 0.2982
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by