9 using namespace numeric;
13 OneProcessSequencePhyloLikelihood::OneProcessSequencePhyloLikelihood(
15 std::shared_ptr<OneProcessSequenceEvolution> evol,
19 AbstractSingleDataPhyloLikelihood(context, 0, (evol->getSubstitutionProcessNumbers().size() != 0) ? evol->substitutionProcess(evol->getSubstitutionProcessNumbers()[0]).getNumberOfStates() : 0, 0),
28 auto sp = evol->getSubstitutionProcess();
29 likCal_ = std::make_shared<LikelihoodCalculationSingleProcess>(
context, sp);
38 std::shared_ptr<const AlignmentDataInterface> data,
39 std::shared_ptr<OneProcessSequenceEvolution> evol,
44 AbstractSingleDataPhyloLikelihood(context, data->getNumberOfSites(), (evol->getSubstitutionProcessNumbers().size() != 0) ? evol->substitutionProcess(evol->getSubstitutionProcessNumbers()[0]).getNumberOfStates() : 0, nData),
53 const auto& sp = evol->getSubstitutionProcess();
54 likCal_ = std::make_shared<LikelihoodCalculationSingleProcess>(
context, data, sp);
61 std::shared_ptr<const AlignmentDataInterface> data,
62 std::shared_ptr<OneProcessSequenceEvolution> evol,
63 std::shared_ptr<CollectionNodes> collNodes,
68 AbstractSingleDataPhyloLikelihood(collNodes->context(), data->getNumberOfSites(), (evol->getSubstitutionProcessNumbers().size() != 0) ? evol->substitutionProcess(evol->getSubstitutionProcessNumbers()[0]).getNumberOfStates() : 0, nData),
77 likCal_ = std::make_shared<LikelihoodCalculationSingleProcess>(collNodes, data, nSeqEvol);
99 if (!rates || rates->getNumberOfCategories() == 1)
103 auto probas = rates->getProbabilities();
104 std::vector<DataLik> vv(rates->getNumberOfCategories());
105 for (
size_t i = 0; i < vv.size(); i++)
111 Vdouble res(rates->getNumberOfCategories());
113 for (
size_t i = 0; i < vv.size(); i++)
130 if (!rates || rates->getNumberOfCategories() == 1)
139 Eigen::VectorXd probas;
143 for (
size_t i = 0; i < nbS; i++)
145 vv[i].resize(
size_t(vvLik.rows()));
160 vector<size_t> classes(nbSites);
161 for (
size_t i = 0; i < nbSites; ++i)
163 classes[i] = VectorTools::whichMax<double>(l[i]);
181 for (
size_t i = 0; i < nbSites; i++)
183 for (
size_t j = 0; j < nbClasses; j++)
185 prates[i] +=
convert((pb[i][j] / l[i]) * probas[j] * rates[j]);
202 for (uint i = 0; i < (uint)nbSites; i++)
208 for (uint st = 0; st < (uint)
nbStates_; st++)
211 for (uint i = 0; i < (uint)nbSites; i++)
213 s += pp[(size_t)i][
size_t(st)];
216 v[size_t(st)] = s / (double)nbSites;
VDataLik getLikelihoodPerSite() const
Get the likelihood for each site.
size_t getNumberOfSites() const
Get the number of sites in the dataset.
virtual void shareParameters_(const ParameterList ¶meters)
const Context & context() const override
Context for dataflow node construction.
virtual Vdouble getCategories() const=0
virtual Vdouble getProbabilities() const=0
const ExtendedFloat & sum() const
const SubstitutionProcessInterface & substitutionProcess() const
Return the ref to the SubstitutionProcess.
std::shared_ptr< LikelihoodCalculationSingleProcess > getLikelihoodCalculationSingleProcess() const
VVdouble getPosteriorProbabilitiesPerSitePerClass() const
Vdouble getPosteriorStateFrequencies(uint nodeId)
std::shared_ptr< LikelihoodCalculationSingleProcess > likCal_
Vdouble getPosteriorRatePerSite() const
Vdouble getPosteriorProbabilitiesForSitePerClass(size_t pos) const
std::vector< size_t > getClassWithMaxPostProbPerSite() const
LikelihoodCalculationSingleProcess & likelihoodCalculationSingleProcess() const
VVdouble getLikelihoodPerSitePerClass() const
OneProcessSequencePhyloLikelihood(Context &context, std::shared_ptr< OneProcessSequenceEvolution > evol, size_t nSeqEvol=0)
size_t getNumberOfClasses() const
Get the number of model classes.
virtual const DiscreteDistributionInterface & rateDistribution() const =0
Get the rate distribution.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
template void copyEigenToBpp(const ExtendedFloatMatrixXd &eigenMatrix, std::vector< std::vector< double >> &bppMatrix)
template void copyBppToEigen(const std::vector< ExtendedFloat > &bppVector, Eigen::RowVectorXd &eigenVector)
double convert(const bpp::ExtendedFloat &ef)
std::vector< Vdouble > VVdouble