Go to the documentation of this file.00001 #include "statsLib.h"
00002
00014 dvariable multifan(const dmatrix oprop,const dvar_matrix& pprop, const int& Nsamp)
00015 {
00016 dvariable extra=0.1/14.;
00017 dvar_matrix resid=elem_div((oprop-pprop),sqrt((elem_prod(pprop,1.-pprop)+extra)/Nsamp));
00018 return sum(0.5*log(elem_prod(pprop,1. -pprop)+extra) -log(mfexp(-0.5*elem_prod(resid,resid))+0.01));
00019 }
00020
00021 dvariable multifan(const int& n, const dmatrix obs, const dvar_matrix pred,double& nef)
00022 {
00023 int A=obs.colmax()-obs.colmin()+1;
00024
00025 dvar_matrix xi=(elem_prod(1.-obs,obs)+0.1/A)/n;
00026 dvar_matrix resid=obs-pred;
00027 nef=value(sum(elem_prod(1.-pred,pred))/sum(elem_prod(resid,resid)));
00028 return sum(0.5*log(2.*M_PI*xi)-log(mfexp(-0.5*elem_div(elem_prod(resid,resid),xi))+0.01));
00029 }
00030
00031 dvariable multifan(const double& s,const dvector obsQ,const dvar_vector& preQ, double& nmle)
00032 {
00033
00034
00035
00036
00037 dvariable like;
00038 dvariable tau;
00039 int lb=obsQ.indexmin();
00040 int nb=obsQ.indexmax();
00041
00042 dvar_vector epsilon(lb,nb);
00043 dvar_vector Q=obsQ/sum(obsQ);
00044 dvar_vector Qhat=preQ/sum(preQ);
00045
00046
00047 nmle=value(sum(elem_prod(Qhat,1.-Qhat))/norm2(Q-Qhat));
00048 cout<<nmle<<endl;
00049 tau=1./s;
00050 epsilon=elem_prod(1.-Qhat,Qhat);
00051
00052 like=0.5*sum(log(2.*M_PI*(epsilon+0.1/nb)))+nb*log(sqrt(tau));
00053 like+= -1.*sum(log(mfexp(-1.*elem_div(square(Q-Qhat),2.*tau*(epsilon+0.1/nb)))+0.01));
00054
00055 return like;
00056 }
00057