Define optimization objective independently of the dimension
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Honey Adams
el 11 de Jul. de 2018
Comentada: Honey Adams
el 12 de Jul. de 2018
How do i define this objective function in matlab .the x are all vectors and i would like to solve this using the genetic algorithm.can matlab identify the function without expanding the function .what if i have 20 variables to deal deal with?
Minimze ∑_(i=1:n ) (A0i + A1*x_i1 + A2*x_i2 + A3*x_i3 - y )^2 + 1⁄6(B0 + B1*x_i1 + B2*x_i2 + B3*x_i3- z )^2
A AND B are my paramters.
0 comentarios
Respuesta aceptada
Matt J
el 11 de Jul. de 2018
Editada: Matt J
el 11 de Jul. de 2018
I don't know why you would want to use the genetic algorithm for such a simple quadratic function. However, the general answer to your question is that you should be using vectorized commands to write these expressions. I.e., you would put your x_ij in a matrix X and write the function something like below. Notice that this works regardless of the size of X.
X=_____;
y=_____;
z=_____;
p_opt = ga(@(p) myfitness(p,X,y,z),______);
function out=myfitness(params, X,y,z)
n=size(X,2);
A=params(1:n);
B=params(n+1:end);
out= norm(X*A-y)^2 +1/6*norm(X*B-z)^2 ;
end
13 comentarios
Matt J
el 11 de Jul. de 2018
Editada: Matt J
el 11 de Jul. de 2018
Thank you for your answer matt. the quaprog couldn't solve this due to the problem being non_covex.
Incidentally, you should be using lsqlin(), not quadprog(), to solve this problem as it is more directly tailored to linear least squares optimization.
Also, The problem is convex, but depending on how small the eigenvalues of your H-matrix are, quadprog can have difficulty recognizing that.
Más respuestas (1)
Torsten
el 11 de Jul. de 2018
Write your objective as
(x*A-y).'*(x*A-y) + 1/6*(x*B-z).'*(x*B-z)
and expand.
I get
[A.', B.']*[x.'*x, 0; 0, 1/6*x.'*x]*[A;B] + [-2*y.'*x,-1/3*z.'*x]*[A;B] + constant term
This can directly used for quadprog.
Best wishes
Torsten.
5 comentarios
Ver también
Categorías
Más información sobre Linear Least Squares en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!