本文整理汇总了C++中Chain::compute_partialJointPosteriorDensity_mutationScalars_overSubLoci方法的典型用法代码示例。如果您正苦于以下问题:C++ Chain::compute_partialJointPosteriorDensity_mutationScalars_overSubLoci方法的具体用法?C++ Chain::compute_partialJointPosteriorDensity_mutationScalars_overSubLoci怎么用?C++ Chain::compute_partialJointPosteriorDensity_mutationScalars_overSubLoci使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chain
的用法示例。
在下文中一共展示了Chain::compute_partialJointPosteriorDensity_mutationScalars_overSubLoci方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeLogJointDensity_mutationScalars_MPI_overSubLoci
// 10/27/2015
// 'demographicPara' is a 1x6 matrix.
long double MaxPosterior::computeLogJointDensity_mutationScalars_MPI_overSubLoci(Eigen::MatrixXd demographicPara, IM im, popTree* poptree, Chain coldCh, unsigned int nProcs, unsigned int crr_procID)
{
poptree->replacePara(demographicPara);
coldCh.compute_partialJointPosteriorDensity_mutationScalars_overSubLoci(poptree, im, crr_procID, nProcs);
unsigned int nSample = coldCh.get_nSubSample();
std::vector<long double> fullLogJointPosterior_local = coldCh.get_partialLogJointCoalProb();
std::vector<long double> fullLogJointPosterior_global;
fullLogJointPosterior_global.resize(nSample);
// std::vector<double> expectationOfEachCoalProb = coldCh.get_expectationOfCoalProb();
// unsigned int numSubLoci = coldCh.getNumSubLoci();
// double posterior = 1;
if(nSample != fullLogJointPosterior_local.size())
{
std::cout << "** Error In MaxPosterior::computeLogJointDensity_mutationScalars_MPI_overSubLoci() **\n";
std::cout << "nSample = " << nSample
<< " fullLogJointPosterior_local.size() = " << fullLogJointPosterior_local.size() <<"\n\n";
}
long double local_logPosterior =0;
long double global_logPosterior = 0;
long double sumJointPosterior = 0.0;
long double logSumJointPosterior = 0.0;
long double max_logPosterior = -1*numeric_limits<long double>::infinity();
for(unsigned int ii=0; ii< nSample; ii++)
{
local_logPosterior = fullLogJointPosterior_local.at(ii);
global_logPosterior = 0;
MPI::COMM_WORLD.Barrier();
MPI::COMM_WORLD.Allreduce(&local_logPosterior, &global_logPosterior, 1, MPI_LONG_DOUBLE, MPI_SUM);
MPI::COMM_WORLD.Barrier();
if(crr_procID==0)
{
Eigen::Vector3d paraMax = im.get_paraMax();
double priorPopTree = poptree->computeJointPrior(paraMax);
fullLogJointPosterior_global.at(ii) = global_logPosterior;
sumJointPosterior += exp(global_logPosterior);
if(max_logPosterior < global_logPosterior)
max_logPosterior = global_logPosterior;
}
}
if(crr_procID==0)
{
long double ratios = 0.0;
for(unsigned int ii=0; ii< nSample; ii++)
{
ratios += exp(fullLogJointPosterior_global.at(ii)-max_logPosterior);
}
logSumJointPosterior = max_logPosterior + log(ratios);
}
// REMOVE
// if(crr_procID==0)
// {
// std::cout << "fullLogJointPosterior_global.at(ii) = ";
// for(unsigned int ii=0; ii< nSample; ii++)
// {
// std::cout << fullLogJointPosterior_global.at(ii) << " (" << exp(fullLogJointPosterior_global.at(ii)) <<") ";
// }
// std::cout << "\n" << " sumJointPosterior =" << sumJointPosterior
// <<" logSumJointPosterior = " <<logSumJointPosterior <<"\n";
// }
// MPI::COMM_WORLD.Barrier();
// MPI::COMM_WORLD.Allreduce(&local_logPosterior_subLoci, &global_logPosterior, 1, MPI_DOUBLE, MPI_SUM);
// MPI::COMM_WORLD.Barrier();
long double logPosterior = 0;
if(crr_procID ==0)
{
Eigen::Vector3d paraMax = im.get_paraMax();
double priorPopTree = poptree->computeJointPrior(paraMax);
//posterior = exp(global_logPosterior+log(priorPopTree));
logPosterior = logSumJointPosterior + log(priorPopTree)-log(nSample);
}
if(crr_procID ==0)
{
totalComputingTime_eigen += coldCh.get_eachComputingTime_eigen();
totalComputingTime_condiProb += coldCh.get_eachComputingTime_condiProb();
totalNum_eigenFunctionCalls++;
totalNum_condiProbFunctionCalls += coldCh.get_countCondiProbFunctionCalls();
// std::cout << "totalComputingTime_eigen = " << totalComputingTime_eigen.count()/1000 << "milliseconds\n";
}
return logPosterior;
}