double GeneralPathSuffStatMultipleMatrixMixtureProfileProcess::ProfileSuffStatLogProb(int cat, int l) { double total = 0; SubMatrix* mat = matrixarray[cat][l]; if (! mat) { cerr << "error : null matrix\n"; cerr << cat << '\t' << Ncomponent << '\n'; cerr << occupancy[cat] << '\n'; exit(1); } const double* stat = mat->GetStationary(); for (map<int,int>::iterator i = profilerootcount[cat][l].begin(); i!= profilerootcount[cat][l].end(); i++) { total += i->second * log(stat[i->first]); } for (map<int,double>::iterator i = profilewaitingtime[cat][l].begin(); i!= profilewaitingtime[cat][l].end(); i++) { total += i->second * (*mat)(i->first,i->first); } for (map<pair<int,int>, int>::iterator i = profilepaircount[cat][l].begin(); i!= profilepaircount[cat][l].end(); i++) { total += i->second * log((*mat)(i->first.first, i->first.second)); } if (isnan(total)) { cerr << "error: in GPSSMultipleMat ProfileSuffStatLogProb: nan\n"; exit(1); } return total; }
double GeneralPathSuffStatMultipleMatrixMixtureProfileProcess::LogStatProb(int site, int cat) { double total = 0; int l = GetSubAlloc(site); SubMatrix* mat = matrixarray[cat][l]; const double* stat = mat->GetStationary(); int rootstate = GetSiteRootState(site); if (rootstate != -1) { total += log(stat[GetSiteRootState(site)]); map<int,double>& waitingtime = GetSiteWaitingTime(site); for (map<int,double>::iterator i = waitingtime.begin(); i!= waitingtime.end(); i++) { total += i->second * (*mat)(i->first,i->first); } map<pair<int,int>, int>& paircount = GetSitePairCount(site); for (map<pair<int,int>, int>::iterator i = paircount.begin(); i!= paircount.end(); i++) { total += i->second * log((*mat)(i->first.first, i->first.second)); } } return total; }