bpp-phyl3  3.0.0
MultiProcessSequencePhyloLikelihood.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "../DataFlow/CollectionNodes.h"
7 
8 using namespace std;
9 using namespace bpp;
10 
11 /******************************************************************************/
12 
13 MultiProcessSequencePhyloLikelihood::MultiProcessSequencePhyloLikelihood(
14  std::shared_ptr<const AlignmentDataInterface> data,
15  std::shared_ptr<MultiProcessSequenceEvolution> processSeqEvol,
16  std::shared_ptr<CollectionNodes> collNodes,
17  size_t nSeqEvol,
18  size_t nData) :
19  AbstractPhyloLikelihood(collNodes->context()),
20  AbstractAlignedPhyloLikelihood(collNodes->context(), data->getNumberOfSites()),
21  AbstractSequencePhyloLikelihood(collNodes->context(), processSeqEvol, nSeqEvol, nData),
22  AbstractParametrizableSequencePhyloLikelihood(collNodes->context(), processSeqEvol, nSeqEvol),
23  mSeqEvol_(processSeqEvol),
24  vLikCal_()
25 {
26  resetParameters_(); // Do not keep the original parameters to get ConfiguredParameters
27  // initialize parameters:
28 
29  const vector<size_t>& nProc = processSeqEvol->getSubstitutionProcessNumbers();
30 
31  for (auto n:nProc)
32  {
33  auto liksing = std::make_shared<LikelihoodCalculationSingleProcess>(collNodes,
34  data,
35  n);
36  liksing->makeLikelihoods();
37  vLikCal_.push_back(liksing);
38  shareParameters_(liksing->getParameters());
39  }
40 }
41 
42 /******************************************************************************/
43 
44 void MultiProcessSequencePhyloLikelihood::setData(std::shared_ptr<const AlignmentDataInterface> sites, size_t nData)
45 {
47 
48  for (auto& lik : vLikCal_)
49  {
50  lik->setData(sites);
51  }
52 }
53 
54 /******************************************************************************/
55 
57 {
59  for (size_t i = 0; i < l.size(); ++i)
60  {
61  Vdouble* l_i = &l[i];
62  l_i->resize(getNumberOfSubstitutionProcess());
63  for (size_t c = 0; c < l_i->size(); ++c)
64  {
65  (*l_i)[c] = convert(getLikelihoodForASiteForAProcess(i, c));
66  }
67  }
68  return l;
69 }
size_t getNumberOfSites() const
Get the number of sites in the dataset.
virtual void shareParameters_(const ParameterList &parameters)
virtual void setData(std::shared_ptr< const AlignmentDataInterface > sites, size_t nData=0)
Set the dataset for which the likelihood must be evaluated.
std::vector< std::shared_ptr< LikelihoodCalculationSingleProcess > > vLikCal_
size_t getNumberOfSubstitutionProcess() const
Return the number of process used for computation.
void setData(std::shared_ptr< const AlignmentDataInterface > sites, size_t nData=0) override
Set the dataset for which the likelihood must be evaluated.
DataLik getLikelihoodForASiteForAProcess(size_t site, size_t p) const
Get the likelihood for a site for a process.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
double convert(const bpp::ExtendedFloat &ef)
std::vector< Vdouble > VVdouble