How to minimize this function

1 visualización (últimos 30 días)
Riccardo Bartoloni
Riccardo Bartoloni el 8 de Mayo de 2019
Respondida: Jeff Miller el 11 de Mayo de 2019
Hello guys, i'm working for my university on this function. I have to minimize it. I have to get into a good part of the space before using a more traditional optimizer, like fminsearch. It was said that gradients are very helpful, but they need to be in a half-decent part of the space to be able to get started.
This is the code, thank you very much and let me know :D
I want to minimize SQ_TOT which is the SSE of my model with the real data. The model is Hazard proportional and use Weibull baseline.
function [SQ_TOT] = Myobjectivefunction(Param,DatiDish)
t=[1/3:1/3:30+1/3];%Param=[0.5254010 11.4402640 29861.1830810 2.0010250 -0.051606000 -0.057373000 0.036517000 -0.099394000 1.647586000 81.195773000 1.422753000 -0.078617000 0.036363000 0.106596000 0.128553000];
DUM=DatiDish(1:4,:);
%Param=Param(1:15);
DUMqA=[Param(5:8)];
expbeta=exp(DUMqA*DUM);
t1=t.^Param(4);
t2=t.^Param(4);
t2(length(t))=[];
t2=[0 t2];
tc=t1-t2;
lt=length(t);
cohort=zeros(1,lt);
for i=1:length(t1);
summ=[zeros(1,i-1) expbeta(i:lt).*tc(1:lt+1-i)];
cohort=[cohort;summ];
end;
cohort(1,:)=[];
HEY_A=cumsum(cohort,2);
F_A=(1-(Param(3)./(Param(3)+HEY_A)).^Param(2)).*(1-Param(1));
%%%%Retention Model%%%%%
DUMqR=[Param(12:15)];
expbeta_R=exp(DUMqR*DUM);
t1R=t.^Param(11);
t2R=t.^Param(11);
t2R(length(t))=[];
t2R=[0 t2R];
tc_R=t1R-t2R;
cohort_R=[];
%cohort_R= matrice riga 1000
for i=1:length(t1);
summ=[zeros(1,i-1) expbeta_R(i:length(t1)).*tc_R(1:length(t)+1-i)];
cohort_R=[cohort_R;summ];
end;
cohort_R(1,:)=[];
HEY_R=cumsum(cohort_R,2);
F_R=(1-(Param(10)./(Param(10)+HEY_R)).^Param(9));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%Addition%%%%
housed=DatiDish(5,:);
HouseCha1=housed;
%HouseCha1= riga 19
housed(end)=[];
HouseCha2=[0 housed];
ChaninPop=HouseCha1-HouseCha2;
F_AZ=[zeros(lt,1) F_A];
EXP_A=[];
EXP_AA=[];
EC_RVERO=zeros(1,lt);
EC=[];
%EC= riga 976 oppure colonna IA e riga 1712
F_RZ=[zeros(lt-1,1) F_R];
F_AZ(:,end)=[];
F_RZ(:,end)=[];
ChaninPopR=ChaninPop(1:end-1);
EC_RVERO=[0];
for i=1:lt
EXP_AA=(F_A-F_AZ).*(ChaninPop+EC_RVERO)';
EC=sum(EXP_AA);
EC(lt)=[];
EXP_RR=(F_R-F_RZ).*(EC)';
EC_RVERO=sum(EXP_RR);
EC_RVERO=[0 EC_RVERO];
EC_RVERO(end)=[];
end
EC=[EC sum(EXP_AA(:,end))];
EC_RVERO(1)=[];
EC_RVERO=[EC_RVERO sum(EXP_RR(:,end))];
EC3m_R=[0 0];
for i=3:lt;
summ=sum(EC_RVERO(i-2:i));
EC3m_R=[EC3m_R summ];
end;
EC3m=[EC(1) sum(EC(1:2))];
for i=3:lt;
summ=sum(EC(i-2:i));
EC3m=[EC3m summ];
end;
ADD=DatiDish(6,:);
DIV_=ADD~=0;
DIVEC3=DIV_.*EC3m;
DIV_A=(DIVEC3-ADD);
DIV_A2=(DIV_A).^2;
SQ_ADD=sum(DIV_A2(1,:));
LOSS=DatiDish(7,:);
DIV=LOSS~=0;
DIV_L=DIV.*EC3m_R;
DIV_LOSS=(DIV_L-LOSS);
DIV_LOSS2=(DIV_LOSS).^2;
SQ_LOSS=sum(DIV_LOSS2(1,:));
EXP_E=EC-EC_RVERO;
EXP_END=cumsum(EXP_E);
END=DatiDish(8,:);
DIV1=END~=0;
DIV2=DIV1-DIV_;
DIV_E=DIV2.*EXP_END;
END_DIV=DIV2.*END;
DIV_E(1)=EXP_END(1);
SQ_EN=[(EXP_END(1))^2];
pos=find(DIV2==1);
for i=4:3:pos(length(pos));
DIV_END=((DIV_E(i)-DIV_E(i-3))-(END_DIV(i)-END_DIV(i-3)))^2;
SQ_EN=[SQ_EN DIV_END];
end;
SQ_END=sum(SQ_EN(1,:));
SQ_END=SQ_END+(END(length(END))-EXP_END(length(EXP_END)))^2;
SQ_TOT=SQ_LOSS+SQ_END+SQ_ADD
end
Param (1x15) is the variable that i want to optimize, so i create the function:
fun=@(Param) Myobjectivefunction(Param,DATANETFLIX12)
This is the input of my function
DATANETFLIX12=[0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1;
0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 ;
1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
5675528 5681982 5688437 5694891 5701345 5707799 5714253 5720707 5727162 5733616 5740070 5746524 5752978 5759450 5765921 5772392 5778863 5785335 5791806 5798277 5804748 5811220 5817691 5824162 5830633 5837109 5843585 5850061 5856536 5863012 5869488 5875964 5882440 5888915 5895391 5901867 5908343 5914812 5921282 5927752 5934222 5940692 5947161 5953631 5960101 5966571 5973041 5979510 5985980 5957108 5928235 5899362 5870490 5841617 5812744 5783872 5754999 5726127 5697254 5668381 5639509 5681982 5688437 5694891 5701345 5707799 5714253 5720707 5727162 5733616 5740070 5746524 5718660 5759450 5765921 5772392 5778863 5785335 5791806 5798277 5804748 5811220 5817691 5824162 5798380 5837109 5843585 5850061 5856536 5863012 5869488;
0.000 0.000 0.000 745.000 0.000 0.000 3479.000 0.000 0.000 2011.930 0.000 0.000 2551.300 0.000 0.000 3670.210 0.000 0.000 4761.527 0.000 0.000 2387.076 0.000 0.000 3404.502 0.000 0.000 4527.261 0.000 0.000 5858.152 0.000 0.000 3151.696 0.000 0.000 4005.776 0.000 0.000 5240.312 0.000 0.000 6668.328 0.000 0.000 4696.713 0.000 0.000 5006.062 0.000 0.000 6602.513 0.000 0.000 8780.653 0.000 0.000 4287.089 0.000 0.000 5459.296 0.000 0.000 7977.228 0.000 0.000 7589.340 0.000 0.000 7126.438 0.000 0.000 7561.936 0.000 0.000 9221.575 0.000 0.000 11024.100 0.000 0.000 8424.550 0.000 0.000 9176.850 0.000 0.000 12097.550 0.000 0.000 12946.216;
0.000 0.000 0.000 645.000 0.000 0.000 648.000 0.000 0.000 732.930 0.000 0.000 771.300 0.000 0.000 797.210 0.000 0.000 880.527 0.000 0.000 993.076 0.000 0.000 1033.502 0.000 0.000 1102.261 0.000 0.000 1160.152 0.000 0.000 1291.696 0.000 0.000 1343.776 0.000 0.000 1418.312 0.000 0.000 1525.328 0.000 0.000 1609.713 0.000 0.000 1693.062 0.000 0.000 1782.513 0.000 0.000 1912.653 0.000 0.000 2098.089 0.000 0.000 2077.296 0.000 0.000 2165.228 0.000 0.000 2316.340 0.000 0.000 2453.438 0.000 0.000 2574.936 0.000 0.000 2600.575 0.000 0.000 2766.100 0.000 0.000 2972.550 0.000 0.000 3108.850 0.000 0.000 3260.550 0.000 0.000 3342.216;
21500.000 0.000 0.000 21600.000 0.000 0.000 24431.000 0.000 0.000 25710.000 0.000 0.000 27490.000 0.000 0.000 30363.000 0.000 0.000 34244.000 0.000 0.000 35638.000 0.000 0.000 38009.000 0.000 0.000 41434.000 0.000 0.000 46132.000 0.000 0.000 47992.000 0.000 0.000 50654.000 0.000 0.000 54476.000 0.000 0.000 59619.000 0.000 0.000 62706.000 0.000 0.000 66019.000 0.000 0.000 70839.000 0.000 0.000 77707.000 0.000 0.000 79896.000 0.000 0.000 83278.000 0.000 0.000 89090.000 0.000 0.000 94363.000 0.000 0.000 99036.000 0.000 0.000 104023.000 0.000 0.000 110644.000 0.000 0.000 118902.000 0.000 0.000 124354.000 0.000 0.000 130422.000 0.000 0.000 139259.000 0.000 0.000 148863.000];
%

Respuesta aceptada

Jeff Miller
Jeff Miller el 11 de Mayo de 2019
If the problem is to find good starting parameter values, then maybe you could start with a grid search over your parameter space to find some points that produce reasonably low SSE values. Then start fminsearch from one (or several) of those. If fminsearch is pretty fast on your problem, you could even generate starting parameter values randomly and save the best result across thousands of random starting points.

Más respuestas (0)

Categorías

Más información sobre Optimization Toolbox en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by