MAK511 ÖDEV 6 ÇÖZÜM a) FFD tasarımı ile Kriging modeli function HW6_FFD addpath('c:/dace') % Full factorial design % Data points dff = fullfact([3 3]); r = (dff-1)/2; x1 = 0 + (24-0)*r(:,1); % x1=[0,24] x2 = 0 + (36-0)*r(:,2); % x2=[0,36] x = [x1,x2]; F = arrayfun(@func,x1,x2); % Kriging model % Initial values, lower and upper bounds for the correlation parameters % Specification of the input and output data, and the regression and correlation model [dmodel, perf] = dacefit(x, F, @regpoly1, @corrgauss, theta0, lob, upb); % dmodel: a data structure with all the necessary information to feed the predictor function % perf: a data structure with details of the optimization process [Fd, mse] = predictor(x, dmodel); rmse_datapoints = sqrt(mean(mse)) % (i) for i=1:9 xi = x; xi(i,:) = []; Fx = arrayfun(@func,xi(:,1),xi(:,2)); [dmodel1, perf] = dacefit(xi, Fx, @regpoly1, @corrgauss, theta0, lob, upb); Fp = predictor(x, dmodel1); err = (F(i)-Fp(i));
rmse_locv = sqrt(mean(err.^2)) % (ii) % Test points xt_nor = rand(10000,2); xt1 = 0 + (24-0)*xt_nor(:,1); xt2 = 0 + (36-0)*xt_nor(:,2); xt = [xt1,xt2]; Ft = arrayfun(@func,xt1,xt2); [Fpred, mse] = predictor(xt, dmodel); error = Fpred - Ft; rmse_testpoints = sqrt(mean(error.^2)) % (iii) function y = func(x1,x2) y = 1 + sin((pi*x1)/12)*sin((pi*x2)/16)+0.5*((x1/12)^2+(x2/16)^2);
b) LHS tasarımı ile Kriging modeli function HW6_LHS addpath('c:/dace') % Latin hypercube % Data points xnor = lhsdesign(9,2); x1 = 0 + (24-0)*xnor(:,1); % x1=[0,24] x2 = 0 + (36-0)*xnor(:,2); % x2=[0,36] x = [x1,x2]; F = arrayfun(@func,x1,x2); % Kriging model % Initial values, lower and upper bounds for the correlation parameters % Specification of the input and output data, and the regression and correlation model [dmodel, perf] = dacefit(x, F, @regpoly1, @corrgauss, theta0, lob, upb); % dmodel: a data structure with all the necessary information to feed the predictor function % perf: a data structure with details of the optimization process [Fd, mse] = predictor(x, dmodel); rmse_datapoints = sqrt(mean(mse)) % (i) for i=1:9 xi = x; xi(i,:) = []; Fx = arrayfun(@func,xi(:,1),xi(:,2)); [dmodel1, perf] = dacefit(xi, Fx, @regpoly1, @corrgauss, theta0, lob, upb); Fp = predictor(x, dmodel1); err = (F(i)-Fp(i)); rmse_locv = sqrt(mean(err.^2)) % (ii) % Test points xt_nor = rand(10000,2); xt1 = 0 + (24-0)*xt_nor(:,1); xt2 = 0 + (36-0)*xt_nor(:,2); xt = [xt1,xt2]; Ft = arrayfun(@func,xt1,xt2); [Fpred, mse] = predictor(xt, dmodel); error = Fpred - Ft; rmse_testpoints = sqrt(mean(error.^2)) % (iii)
function y = func(x1,x2) y = 1 + sin((pi*x1)/12)*sin((pi*x2)/16)+0.5*((x1/12)^2+(x2/16)^2);
c) FFD ile Optimizasyon FFD tasarımı kullanılarak elde edilen RMSE değeri daha küçük olduğu için FFD veri noktaları ile optimizasyon yapılmıştır. function HW6_FFD_surrogate_based_optimization global dmodel % Data points dff = fullfact([3 3]); r = (dff-1)/2; x1 = 0 + (24-0)*r(:,1); % x1=[0,24] x2 = 0 + (36-0)*r(:,2); % x2=[0,36] x = [x1,x2]; F = arrayfun(@func,x1,x2); % Kriging model [dmodel, perf] = dacefit(x, F, @regpoly1, @corrgauss, theta0, lob, upb); options=optimset('display','iter'); A = []; b = []; Aeq = []; beq = []; % coefficients of linear inequality constraints % limits of linear inequality constraints % coefficients of linear equality constraints % limits of linear equality constraints lb = [0,0]; ub = [4,4]; % Multiple starting point strategy fval_opt = Inf; for ii=1:20 fprintf('i = %4.0f \n',ii) x0 = lb + (ub-lb).*rand(1,2); [xopt,fval,exitflag,output] = fmincon(@fun,x0,a,b,aeq,beq,lb,ub,@nonlcon,options) if fval<fval_opt && exitflag>0 x_opt=xopt; fval_opt=fval; x_opt, fval_opt F_opt = get_f(xopt) function f = fun(x) f = 1 + sin((pi*x(1))/12)*sin((pi*x(2))/16)+0.5*((x(1)/12)^2+(x(2)/16)^2); function [c,ceq] = nonlcon(x) c= []; ceq=[];
function F = get_f(x) global dmodel F = predictor(x, dmodel); function y = func(x1,x2) y = 1 + sin((pi*x1)/12)*sin((pi*x2)/16)+0.5*((x1/12)^2+(x2/16)^2);
d) Analitik Çözüm function HW6_AnalyticalSolution syms x1 x2 F = 1 + sin((pi*x1)/12)*sin((pi*x2)/16)+0.5*((x1/12)^2+(x2/16)^2); F_x1 = diff(f,x1); F_x2 = diff(f,x2); eqns = [x1/144 + (pi*cos((pi*x1)/12)*sin((pi*x2)/16))/12 == 0,... x2/256 + (pi*cos((pi*x2)/16)*sin((pi*x1)/12))/16 == 0]; vars = [x1 x2]; [x1,x2] = vpasolve(eqns,vars) Fopt = 1 + sin((pi*x1)/12)*sin((pi*x2)/16)+0.5*((x1/12)^2+(x2/16)^2) Sonuçlar karşılaştırıldığında, FFD veri noktaları kullanılarak elde edilen optimum değerler ile analitik çözüm değerlerinin aynı olduğu görülmektedir.