Genetic algorithm optimisation toolbox

I have set of 50 equations like z1=a1(x1)+b1(x2)+c1(x3)+d1(x4) to z50=a50(x1)+b50(x2)+c50(x3)+d50(x4) . I need to optimise the weights of variables x1,x2,x3,x4 which should be bound to [1 to 5]. The value z1 to z50 varies between 140 to 180. Coefficient (a1 ,b1 ,c1,d1) to (a50,b50,c50,d50) also varies between 1 to 10. How to get solution using ga in optimisation toolbox or any other methods?

10 commentaires

Walter Roberson
Walter Roberson le 21 Mar 2019
It is not entirely clear which are the knowns and which are the unknowns ?
Balaji L
Balaji L le 21 Mar 2019
(z1 to z50) and (coefficient a1 to a50 ... d1 to d50) are knowns. x1, x2, x3 and x4 are unkowns.
Walter Roberson
Walter Roberson le 21 Mar 2019
What is being optimized? Your z* equations form linear equality constraints, and your [1 to 5] form upper and lower bound constraints, but I see no minimization going on. With the information we have, any set of values that satisfies those constraints would be equally as good.
Balaji L
Balaji L le 21 Mar 2019
how to write fitness function for above condition?
Walter Roberson
Walter Roberson le 21 Mar 2019
Given any two sets of x1, x2, x3, x4, x5, where each set satisfies the linear equalities z1 through z50 and the bounds constraints 1 to 5 for the x* values, then how would you decide which of the two sets of x1, x2, x3, x4, x5 is "better" ?
Are you sure you want 50 equality constraints? When you have more equality constraints than variables then unless most of the constraints are redundent, then most of the time there is no solution.
Balaji L
Balaji L le 21 Mar 2019
PFA
The default weight given to x1 to x7 is(5,4,3,2,1,5,3). Sum of the (A*X1+B*X2+..G*X7 = Z) is given in column H.
My objective is to increase (maximize) correlation between (Z and Y) by changing the default weights(x1 to x7). But these weight should bound between [1 to 5].
Fitness function for ga is required.
Walter Roberson
Walter Roberson le 21 Mar 2019
If your correlations were all non-NaN then this would just be the constrained version of
[A B C D E F G]\Correlation
but it is difficult to do much useful when only one of the correlations is non-NaN.
Balaji L
Balaji L le 21 Mar 2019
correlation is non-Nan only. Correlation value is same for all the cells (J2:J11) (0.2419). My objective is to maximise this 0.2419 to good correlation coefficient between (0.6 to 1).
Walter Roberson
Walter Roberson le 21 Mar 2019
I do not understand what the 0.2419 correlation is measuring or how Y fits into all of this??
Balaji L
Balaji L le 21 Mar 2019
0.2419 is correlation betweeen Z(H2:H11) and Y(I2:I11). Value Z is arrived through equation (Ax1+Bx2+Cx3+Dx4+Ex5+Fx6+Gx7=Z), The Values of Y(I2:I11) should not be changed. Need to get optimal solution for (x1,x2,..x7) such that correlation between Z and Y is to be a maximum one.

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 21 Mar 2019
Modifié(e) : Walter Roberson le 21 Mar 2019
nvar = 7;
T = readtable('Attachment.xls');
W = T{:,1:nvar};
Y = T.Y;
obj = @(x) -corr(W*x.', Y);
A = []; b = [];
Aeq = []; beq = [];
lb = ones(1,nvar); ub = 5*ones(1,nvar);
x0 = 2*lb;
[x_fmincon, fval_fmincon] = fmincon(obj, x0, A, b, Aeq, beq, lb, ub);
corr_reached_fmincon = -fval_fmincon;
[x_ga, fval_ga] = ga(obj, nvar, A, b, Aeq, beq, lb, ub);
corr_reached_ga = -fval_ga;
If you try the ga several times you might be able to get a result marginally better than what fmincon achieves, but only barely so. However, the weights might be quite different especially for the 2nd and 3rd variable.

5 commentaires

Balaji L
Balaji L le 21 Mar 2019
Thank you for your help. How to do these operation in optimtool?
Walter Roberson
Walter Roberson le 21 Mar 2019
optimtool would just call ga to do the work. It is only a visual interface that has no special functionality.
Walter Roberson
Walter Roberson le 22 Mar 2019
My tests show that you cannot reach 0.6 with those boundaries. If you relax to upper bound 6 then you can.
Balaji L
Balaji L le 24 Juin 2019
Untitled.jpg
Walter Roberson
Walter Roberson le 26 Juin 2019
Do not name your file fmincon.m . Doing that makes it impossible for the script to call MATLAB's fmincon.m

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by