bpp-phyl3 3.0.0
DRNonHomogeneousTreeLikelihood.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_LEGACY_LIKELIHOOD_DRNONHOMOGENEOUSTREELIKELIHOOD_H
6#define BPP_PHYL_LEGACY_LIKELIHOOD_DRNONHOMOGENEOUSTREELIKELIHOOD_H
7
10
13#include "DRTreeLikelihood.h"
14
15namespace bpp
16{
35{
36protected:
37 mutable std::unique_ptr<DRASDRTreeLikelihoodData> likelihoodData_;
39
40public:
56 const Tree& tree,
57 std::shared_ptr<SubstitutionModelSet> modelSet,
58 std::shared_ptr<DiscreteDistributionInterface> rDist,
59 bool verbose = true,
60 bool reparametrizeRoot = false);
61
77 const Tree& tree,
79 std::shared_ptr<SubstitutionModelSet> modelSet,
80 std::shared_ptr<DiscreteDistributionInterface> rDist,
81 bool verbose = true,
82 bool reparametrizeRoot = false);
83
88
90
92
94
95private:
99 void init_();
100
101public:
109 void setData(const AlignmentDataInterface& sites);
110 double getLikelihood () const;
111 double getLogLikelihood() const;
112 double getLikelihoodForASite (size_t site) const;
113 double getLogLikelihoodForASite(size_t site) const;
114 size_t getSiteIndex(size_t site) const { return likelihoodData_->getRootArrayPosition(site); }
118
119
125 double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
126 double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
127 double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
128 double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
142 void setParameters(const ParameterList& parameters);
143
147 double getValue() const;
148
154 double getFirstOrderDerivative(const std::string& variable) const;
162 double getSecondOrderDerivative(const std::string& variable) const;
163 double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const { return 0; } // Not implemented for now.
166public:
167 // Specific methods:
168
170
172
173 virtual void computeLikelihoodAtNode(int nodeId, VVVdouble& likelihoodArray) const
174 {
175 computeLikelihoodAtNode_(tree_->getNode(nodeId), likelihoodArray);
176 }
177
178protected:
179 virtual void computeLikelihoodAtNode_(const Node* node, VVVdouble& likelihoodArray) const;
180
181
186 virtual void computeSubtreeLikelihoodPostfix(const Node* node); // Recursive method.
192 virtual void computeSubtreeLikelihoodPrefix(const Node* node); // Recursive method.
193
194 virtual void computeRootLikelihood();
195
196 virtual void computeTreeDLikelihoodAtNode(const Node* node);
197 virtual void computeTreeDLikelihoods();
198
199 virtual void computeTreeD2LikelihoodAtNode(const Node* node);
200 virtual void computeTreeD2Likelihoods();
201
202 void fireParameterChanged(const ParameterList& params);
203
204 void resetLikelihoodArrays(const Node* node);
205
211 virtual void displayLikelihood(const Node* node);
212
230 static void computeLikelihoodFromArrays(
231 const std::vector<const VVVdouble*>& iLik,
232 const std::vector<const VVVdouble*>& tProb,
233 VVVdouble& oLik, size_t nbNodes,
234 size_t nbDistinctSites,
235 size_t nbClasses,
236 size_t nbStates,
237 bool reset = true);
238
259 static void computeLikelihoodFromArrays(
260 const std::vector<const VVVdouble*>& iLik,
261 const std::vector<const VVVdouble*>& tProb,
262 const VVVdouble* iLikR,
263 const VVVdouble* tProbR,
264 VVVdouble& oLik,
265 size_t nbNodes,
266 size_t nbDistinctSites,
267 size_t nbClasses,
268 size_t nbStates,
269 bool reset = true);
270
272};
273} // end of namespace bpp.
274#endif // BPP_PHYL_LEGACY_LIKELIHOOD_DRNONHOMOGENEOUSTREELIKELIHOOD_H
Partial implementation for branch non-homogeneous models of the TreeLikelihood interface.
const AlignmentDataInterface & data() const
Get the dataset for which the likelihood must be evaluated.
const Tree & tree() const
Get the tree (topology and branch lengths).
std::shared_ptr< TreeTemplate< Node > > tree_
Likelihood data structure for rate across sites models, using a double-recursive algorithm.
This class implements the likelihood computation for a tree using the double-recursive algorithm,...
virtual void computeSubtreeLikelihoodPostfix(const Node *node)
DRNonHomogeneousTreeLikelihood(const Tree &tree, std::shared_ptr< SubstitutionModelSet > modelSet, std::shared_ptr< DiscreteDistributionInterface > rDist, bool verbose=true, bool reparametrizeRoot=false)
Build a new DRNonHomogeneousTreeLikelihood object without data.
void setParameters(const ParameterList &parameters)
Implements the Function interface.
double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const
Get the likelihood for a site knowing its rate class and its ancestral state.
void setData(const AlignmentDataInterface &sites)
Set the dataset for which the likelihood must be evaluated.
double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const
Get the logarithm of the likelihood for a site knowing its rate class and its ancestral state.
std::unique_ptr< DRASDRTreeLikelihoodData > likelihoodData_
double getLogLikelihood() const
Get the logarithm of the likelihood for the whole dataset.
double getLikelihood() const
Get the likelihood for the whole dataset.
virtual void computeTreeDLikelihoodAtNode(const Node *node)
double getFirstOrderDerivative(const std::string &variable) const
const DRASDRTreeLikelihoodData & likelihoodData() const
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
size_t getSiteIndex(size_t site) const
Get the index (used for inner computations) of a given site (original alignment column).
virtual void computeLikelihoodAtNode(int nodeId, VVVdouble &likelihoodArray) const
Compute the likelihood array at a given node.
DRNonHomogeneousTreeLikelihood & operator=(const DRNonHomogeneousTreeLikelihood &lik)
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the likelihood for a site knowing its rate class.
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site.
double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the logarithm of the likelihood for a site knowing its rate class.
void fireParameterChanged(const ParameterList &params)
virtual void computeLikelihoodAtNode_(const Node *node, VVVdouble &likelihoodArray) const
virtual void computeTreeD2LikelihoodAtNode(const Node *node)
virtual void computeSubtreeLikelihoodPrefix(const Node *node)
double getSecondOrderDerivative(const std::string &variable) const
static void computeLikelihoodFromArrays(const std::vector< const VVVdouble * > &iLik, const std::vector< const VVVdouble * > &tProb, VVVdouble &oLik, size_t nbNodes, size_t nbDistinctSites, size_t nbClasses, size_t nbStates, bool reset=true)
Compute conditional likelihoods.
double getSecondOrderDerivative(const std::string &variable1, const std::string &variable2) const
DRNonHomogeneousTreeLikelihood * clone() const
double getLogLikelihoodForASite(size_t site) const
Get the logarithm of the likelihood for a site.
double getValue() const
Function and NNISearchable interface.
void init_()
Method called by constructors.
Interface for double-recursive (DR) implementation of the likelihood computation.
The phylogenetic node class.
Definition: Node.h:59
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.
std::vector< VVdouble > VVVdouble