Maximum likelihood and optimization

16 Ansichten (letzte 30 Tage)
Riccardo Bartoloni
Riccardo Bartoloni am 11 Mai 2019
I would like to try to use maximum likelihood, could it be helpful? This is the code of my function.
function [SQ_TOT] = Myobjectivefunction(Param,DatiDish,t)
DUM=DatiDish(1:4,:);
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,:)=[];
F_A=(1-(Param(3)./(Param(3)+cumsum(cohort,2))).^Param(2)).*(1-Param(1));
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=[];
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)+cumsum(cohort_R,2))).^Param(9));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%Addition%%%%
housed=DatiDish(5,:);
HouseCha1=housed;
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=[];
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
the inputs are:
DATANEFLIX12=[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 0 0 745 0 0 3479 0 0 2011.93000000000 0 0 2551.30000000000 0 0 3670.21000000000 0 0 4761.52700000000 0 0 2387.07600000000 0 0 3404.50200000000 0 0 4527.26100000000 0 0 5858.15200000000 0 0 3151.69600000000 0 0 4005.77600000000 0 0 5240.31200000000 0 0 6668.32800000000 0 0 4696.71300000000 0 0 5006.06200000000 0 0 6602.51300000000 0 0 8780.65300000000 0 0 4287.08900000000 0 0 5459.29600000000 0 0 7977.22800000000 0 0 7589.34000000000 0 0 7126.43800000000 0 0 7561.93600000000 0 0 9221.57500000000 0 0 11024.1000000000 0 0 8424.55000000000 0 0 9176.85000000000 0 0 12097.5500000000 0 0 12946.2160000000;
0 0 0 645 0 0 648 0 0 732.930000000000 0 0 771.300000000000 0 0 797.210000000000 0 0 880.527000000000 0 0 993.076000000000 0 0 1033.50200000000 0 0 1102.26100000000 0 0 1160.15200000000 0 0 1291.69600000000 0 0 1343.77600000000 0 0 1418.31200000000 0 0 1525.32800000000 0 0 1609.71300000000 0 0 1693.06200000000 0 0 1782.51300000000 0 0 1912.65300000000 0 0 2098.08900000000 0 0 2077.29600000000 0 0 2165.22800000000 0 0 2316.34000000000 0 0 2453.43800000000 0 0 2574.93600000000 0 0 2600.57500000000 0 0 2766.10000000000 0 0 2972.55000000000 0 0 3108.85000000000 0 0 3260.55000000000 0 0 3342.21600000000;
21500 0 0 21600 0 0 24431 0 0 25710 0 0 27490 0 0 30363 0 0 34244 0 0 35638 0 0 38009 0 0 41434 0 0 46132 0 0 47992 0 0 50654 0 0 54476 0 0 59619 0 0 62706 0 0 66019 0 0 70839 0 0 77707 0 0 79896 0 0 83278 0 0 89090 0 0 94363 0 0 99036 0 0 104023 0 0 110644 0 0 118902 0 0 124354 0 0 130422 0 0 139259 0 0 148863];
ti=[1/3:1/3:30+1/3];
So if i want to call the function to minimize it for example with fminsearch, i have to write:
fun=@(Param) Myobjectivefunction(Param,DATANETFLIX12,ti)
The problem is that with traditional optimization method like fminsearch i don't reach the real absolute minimum and i'm far from it. If there is another method to find global minimum (different from maximum likelihood) it's all the same!
Please it's very importante for me, thank you very much!

Antworten (0)

Kategorien

Mehr zu Curve Fitting Toolbox 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!

Translated by