Minimalization problem LinearConstraint and conjugate gradient optimizer
5 views (last 30 days)
Show older comments
Problem, input data and equations are described in details in attachment. This matrix is called Ms in the below mentioned equation.
The equation is the function F(ω). Omega (ω) are the seven wages which I’m looking for by minimize values of the second equation. The condition is that ω1 + ω2 + ω3 + ω4 + ω5 + ω6 + ω7 = 1.
When using Scipy.stats, the LinearConstraint and Conjugate gradient optimizer were used.
The obtained results were: 0.20141944, 0.1590185 , 0.13852083, 0.08702209, 0.13283426, 0.14539815, 0.14247747. Sum of these wages equals 1.
I very appreciate if someone help me out to write code or use Optimization tool to obtain these results.The input matrix Ms is in attached file.
Best Regards,
Tomi
2 Comments
Torsten
on 25 Sep 2022
What are you trying to minimize ? What are your constraints ? I don't get it from your decription.
Accepted Answer
Torsten
on 26 Sep 2022
Edited: Torsten
on 26 Sep 2022
According to the Python code, F is maximized, not minimized. Change in the below code if appropriate.
M = [0.170543 0.327434 0.174194 0 0.421053 0.307167 0.297659
0.155039 0.504425 0.664516 0.530612 0.102493 0.05802 0.053512
0.255814 0.318584 0.212903 0 0.445983 0.337884 0.311037
0.224806 0.548673 0.664516 0.591837 0.141274 0.068259 0.053512
0.383721 0.389381 0.303226 0 0.573407 0.433447 0.41806
0.360465 0.716814 0.883871 0.755102 0.227147 0.078498 0.073579
0.449612 0.566372 0.36129 0 0.775623 0.573379 0.498328
0.484496 0.920354 0.948387 1 0.265928 0.109215 0.107023
0.375969 0.539823 0.303226 0 0.648199 0.481229 0.438127
0.399225 0.769912 0.716129 0.857143 0.224377 0.102389 0.100334
0.356589 0.39823 0.264516 0 0.717452 0.498294 0.444816
0.391473 0.761062 0.703226 0.795918 0.218837 0.098976 0.09699
0.290698 0.327434 0.251613 0 0.770083 0.518771 0.464883
0.395349 0.761062 0.767742 0.795918 0.207756 0.085324 0.09699
0.352713 0.380531 0.277419 0 0.797784 0.501706 0.501672
0.426357 0.778761 0.870968 0.877551 0.265928 0.112628 0.100334
0.403101 0.336283 0.309677 0 0.761773 0.467577 0.491639
0.468992 0.743363 0.877419 0.897959 0.224377 0.119454 0.090301
0.387597 0.345133 0.341935 0 0.775623 0.518771 0.551839
0.496124 0.787611 0.877419 0.857143 0.263158 0.122867 0.113712
0.333333 0.380531 0.341935 0 0.759003 0.566553 0.585284
0.624031 0.80531 0.780645 0.795918 0.293629 0.12628 0.130435
0.534884 0.40708 0.419355 0 0.894737 0.641638 0.628763
0.786822 0.938053 1 0.632653 0.379501 0.197952 0.120401
0.453488 0.380531 0.419355 0 0.842105 0.607509 0.628763
0.554264 0.876106 0.741935 0.877551 0.254848 0.334471 0.130435
0.639535 0.646018 0.593548 0 1 0.8157 0.73913
0.689922 1 0.735484 0.693878 0.351801 0.337884 0.137124
1 0.867257 0.354839 0 0.617729 1 1
0.546512 0.876106 0.703226 0.877551 0.254848 0.334471 0.130435];
w0 = [1/7;1/7;1/7;1/7;1/7;1/7;1/7];
Aeq = ones(1,7);
beq = 1.0;
lb = zeros(7,1);
ub = ones(7,1);
options = optimset('TolFun',1e-10,'TolX',1e-10);
format long
[w,fval] = fmincon(@(w)fun(w,M),w0,[],[],Aeq,beq,lb,ub,[],options)
function value = fun(w,M)
cM = zeros(7,1);
Mw = M*w;
Mwm = mean(Mw);
Mim = mean(M,1);
for i = 1:7
Mi = M(:,i);
cM(i) = sum((Mi-Mim(i)).*(Mw-Mwm))/sqrt(sum((Mi-Mim(i)).^2)*sum((Mw-Mwm).^2));
end
value = -sum(cM);
end
More Answers (2)
Tomi
on 28 Sep 2022
5 Comments
Torsten
on 29 Sep 2022
Edited: Torsten
on 29 Sep 2022
M = [0.170543 0.327434 0.174194 0 0.421053 0.307167 0.297659
0.155039 0.504425 0.664516 0.530612 0.102493 0.05802 0.053512
0.255814 0.318584 0.212903 0 0.445983 0.337884 0.311037
0.224806 0.548673 0.664516 0.591837 0.141274 0.068259 0.053512
0.383721 0.389381 0.303226 0 0.573407 0.433447 0.41806
0.360465 0.716814 0.883871 0.755102 0.227147 0.078498 0.073579
0.449612 0.566372 0.36129 0 0.775623 0.573379 0.498328
0.484496 0.920354 0.948387 1 0.265928 0.109215 0.107023
0.375969 0.539823 0.303226 0 0.648199 0.481229 0.438127
0.399225 0.769912 0.716129 0.857143 0.224377 0.102389 0.100334
0.356589 0.39823 0.264516 0 0.717452 0.498294 0.444816
0.391473 0.761062 0.703226 0.795918 0.218837 0.098976 0.09699
0.290698 0.327434 0.251613 0 0.770083 0.518771 0.464883
0.395349 0.761062 0.767742 0.795918 0.207756 0.085324 0.09699
0.352713 0.380531 0.277419 0 0.797784 0.501706 0.501672
0.426357 0.778761 0.870968 0.877551 0.265928 0.112628 0.100334
0.403101 0.336283 0.309677 0 0.761773 0.467577 0.491639
0.468992 0.743363 0.877419 0.897959 0.224377 0.119454 0.090301
0.387597 0.345133 0.341935 0 0.775623 0.518771 0.551839
0.496124 0.787611 0.877419 0.857143 0.263158 0.122867 0.113712
0.333333 0.380531 0.341935 0 0.759003 0.566553 0.585284
0.624031 0.80531 0.780645 0.795918 0.293629 0.12628 0.130435
0.534884 0.40708 0.419355 0 0.894737 0.641638 0.628763
0.786822 0.938053 1 0.632653 0.379501 0.197952 0.120401
0.453488 0.380531 0.419355 0 0.842105 0.607509 0.628763
0.554264 0.876106 0.741935 0.877551 0.254848 0.334471 0.130435
0.639535 0.646018 0.593548 0 1 0.8157 0.73913
0.689922 1 0.735484 0.693878 0.351801 0.337884 0.137124
1 0.867257 0.354839 0 0.617729 1 1
0.546512 0.876106 0.703226 0.877551 0.254848 0.334471 0.130435];
w0 = [1/7;1/7;1/7;1/7;1/7;1/7;1/7];
Aeq = ones(1,7);
beq = 1.0;
lb = zeros(7,1);
ub = ones(7,1);
options = optimset('TolFun',1e-10,'TolX',1e-10);
Mim = mean(M,1);
fun = @(w) -sum(arrayfun(@(i)sum((M(:,i)-Mim(i)).*(M*w-mean(M*w)))/sqrt(sum((M(:,i)-Mim(i)).^2)*sum((M*w-mean(M*w)).^2)),1:7));
format long
[w,fval] = fmincon(fun,w0,[],[],Aeq,beq,lb,ub,[],options)
See Also
Categories
Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!