Define optimization objective independently of the dimension
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Honey Adams
am 11 Jul. 2018
Kommentiert: Honey Adams
am 12 Jul. 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 Kommentare
Akzeptierte Antwort
Matt J
am 11 Jul. 2018
Bearbeitet: Matt J
am 11 Jul. 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 Kommentare
Matt J
am 11 Jul. 2018
Bearbeitet: Matt J
am 11 Jul. 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.
Weitere Antworten (1)
Torsten
am 11 Jul. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Linear Least Squares finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!