16 PartitionProcessPhyloLikelihood::PartitionProcessPhyloLikelihood(
18 std::shared_ptr<PartitionSequenceEvolution> processSeqEvol,
23 context, processSeqEvol->getNumberOfSites(),
24 (processSeqEvol->getSubstitutionProcessNumbers().size() != 0) ? processSeqEvol->substitutionProcess(processSeqEvol->getSubstitutionProcessNumbers()[0]).getNumberOfStates() : 0, 0),
28 mSeqEvol_(processSeqEvol),
38 map<size_t, vector<size_t>>& mProcPos = processSeqEvol->mapOfProcessSites();
40 vProcPos_.resize(processSeqEvol->getNumberOfSites());
45 for (
const auto& it : mProcPos)
47 auto nProcess = it.first;
49 auto l = std::make_shared<LikelihoodCalculationSingleProcess>(collNodes, nProcess);
51 auto nPL = make_shared<SingleProcessPhyloLikelihood>(
context, l, nProcess);
53 pC->addPhyloLikelihood(nProcess, nPL);
55 for (
size_t i = 0; i < it.second.size(); ++i)
70 std::shared_ptr<const AlignmentDataInterface> data,
71 std::shared_ptr<PartitionSequenceEvolution> processSeqEvol,
77 context, data->getNumberOfSites(),
78 (processSeqEvol->getSubstitutionProcessNumbers().size() != 0) ? processSeqEvol->substitutionProcess(processSeqEvol->getSubstitutionProcessNumbers()[0]).getNumberOfStates() : 0, nData),
82 mSeqEvol_(processSeqEvol),
87 if (data->getNumberOfSites() != processSeqEvol->getNumberOfSites())
88 throw BadIntegerException(
"PartitionProcessPhyloLikelihood::PartitionProcessPhyloLikelihood, data and sequence process lengths do not match.",
static_cast<int>(data->getNumberOfSites()));
94 map<size_t, vector<size_t>>& mProcPos = processSeqEvol->mapOfProcessSites();
96 vProcPos_.resize(processSeqEvol->getNumberOfSites());
101 for (
const auto& it:mProcPos)
103 auto nProcess = it.first;
105 auto l = std::make_shared<LikelihoodCalculationSingleProcess>(collNodes, nProcess);
107 auto nPL = make_shared<SingleProcessPhyloLikelihood>(
context, l, nProcess, nData);
109 pC->addPhyloLikelihood(nProcess, nPL);
111 for (
size_t i = 0; i < it.second.size(); ++i)
113 vProcPos_[it.second[i]].nProc = nProcess;
127 std::shared_ptr<const AlignmentDataInterface> data,
128 std::shared_ptr<PartitionSequenceEvolution> processSeqEvol,
129 std::shared_ptr<CollectionNodes> collNodes,
135 collNodes->context(), data->getNumberOfSites(),
136 (processSeqEvol->getSubstitutionProcessNumbers().size() != 0) ? processSeqEvol->substitutionProcess(processSeqEvol->getSubstitutionProcessNumbers()[0]).getNumberOfStates() : 0, nData),
140 mSeqEvol_(processSeqEvol),
145 if (data->getNumberOfSites() != processSeqEvol->getNumberOfSites())
146 throw BadIntegerException(
"PartitionProcessPhyloLikelihood::PartitionProcessPhyloLikelihood, data and sequence process lengths do not match.",
static_cast<int>(data->getNumberOfSites()));
148 map<size_t, vector<size_t>>& mProcPos = processSeqEvol->mapOfProcessSites();
150 vProcPos_.resize(processSeqEvol->getNumberOfSites());
155 for (
const auto& it : mProcPos)
157 auto nProcess = it.first;
159 auto l = std::make_shared<LikelihoodCalculationSingleProcess>(collNodes, nProcess);
161 auto nPL = make_shared<SingleProcessPhyloLikelihood>(this->
context(), l, nProcess, nData);
163 pC->addPhyloLikelihood(nProcess, nPL);
165 for (
size_t i = 0; i < it.second.size(); ++i)
167 vProcPos_[it.second[i]].nProc = nProcess;
181 std::shared_ptr<const AlignmentDataInterface> data,
184 if (data->getNumberOfSites() !=
mSeqEvol_->getNumberOfSites())
185 throw BadIntegerException(
"PartitionProcessPhyloLikelihood::PartitionProcessPhyloLikelihood, data and sequence process lengths do not match.",
static_cast<int>(data->getNumberOfSites()));
189 const auto& mProcPos =
mSeqEvol_->mapOfProcessSites();
191 for (
const auto& it : mProcPos)
208 map<size_t, size_t> mProcInd;
213 vLik.push_back(dynamic_pointer_cast<AlignedLikelihoodCalculation>(lik)->getSiteLikelihoods(
false));
217 std::map<size_t, size_t> nProc2iProc;
218 for (
size_t i = 0; i <
nPhylo_.size(); ++i)
235 matching(Eigen::Index(i), 0) = nProc2iProc[
vProcPos_[i].nProc];
236 matching(Eigen::Index(i), 1) =
vProcPos_[i].pos;
241 vLik.push_back(matchingDF);
245 likCal_->setSiteLikelihoods(sL);
249 likCal_->setLikelihoodNode(lik);
The PhyloLikelihoodSet class, to manage a subset of PhyloLikelihoods from a given PhyloLikelihoodCont...
std::shared_ptr< PhyloLikelihoodContainer > pPhyloCont_
pointer to a PhyloLikelihoodContainer
std::vector< size_t > nPhylo_
vector of AbstractPhyloLikelihood numbers
std::shared_ptr< PhyloLikelihoodContainer > getPhyloContainer() override
std::vector< std::shared_ptr< LikelihoodCalculation > > vLikCal_
virtual bool addPhyloLikelihood(size_t nPhyl, const std::string &suff="") override
adds a PhyloLikelihood already stored in the PhyloLikelihoodContainer, iff it is an AbstractPhyloLike...
const Context & context() const override
virtual void setData(std::shared_ptr< const AlignmentDataInterface > sites, size_t nData=0)
Set the dataset for which the likelihood must be evaluated.
Context for dataflow node construction.
static std::shared_ptr< Self > create(Context &c, Args &&... args)
Build a new NumericConstant node with T(args...) value.
PartitionProcessPhyloLikelihood(Context &context, std::shared_ptr< PartitionSequenceEvolution > processSeqEvol, size_t nSeqEvol=0)
std::vector< ProcPos > vProcPos_
std::shared_ptr< AlignedLikelihoodCalculation > likCal_
void setData(std::shared_ptr< const AlignmentDataInterface > data, size_t nData=0) override
Set the dataset for which the likelihood must be evaluated.
size_t getNumberOfSites() const override
Get the number of sites in the dataset.
std::map< size_t, std::shared_ptr< AlignmentDataInterface > > mData_
std::shared_ptr< PartitionSequenceEvolution > mSeqEvol_
to avoid the dynamic casts
The PhyloLikelihoodContainer, owns and assigns numbers to Phylolikelihoods.
static ValueRef< DataLik > create(Context &c, NodeRefVec &&deps, const Dimension< F > &mDim)
Build a new SumOfLogarithms node with the given input matrix dimensions.
Defines the basic types of data flow nodes.
std::vector< NodeRef > NodeRefVec
Alias for a dependency vector (of NodeRef).
Eigen::Matrix< size_t, -1, 2 > MatchingType