Define optimization objective independently of the dimension
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Matt J
le 11 Juil 2018
Modifié(e) : Matt J
le 11 Juil 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 commentaires
Matt J
le 11 Juil 2018
Modifié(e) : Matt J
le 11 Juil 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.
Plus de réponses (1)
Torsten
le 11 Juil 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 commentaires
Voir également
Catégories
En savoir plus sur Linear Least Squares dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!