当前位置: 首页>>代码示例>>C++>>正文


C++ Chain::compute_partialJointPosteriorDensity_mutationScalars_overSubLoci方法代码示例

本文整理汇总了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;
}
开发者ID:yujin-chung,项目名称:MIST,代码行数:97,代码来源:optimization.cpp


注:本文中的Chain::compute_partialJointPosteriorDensity_mutationScalars_overSubLoci方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。