bpp-phyl3  3.0.0
DRHomogeneousTreeLikelihood.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_DRHOMOGENEOUSTREELIKELIHOOD_H
6 #define BPP_PHYL_LEGACY_LIKELIHOOD_DRHOMOGENEOUSTREELIKELIHOOD_H
7 
10 
13 #include "DRTreeLikelihood.h"
14 
15 namespace bpp
16 {
30  public virtual DRTreeLikelihoodInterface
31 {
32 private:
33  mutable std::unique_ptr<DRASDRTreeLikelihoodData> likelihoodData_;
34 
35 protected:
36  double minusLogLik_;
37 
38 public:
54  const Tree& tree,
55  std::shared_ptr<TransitionModelInterface> model,
56  std::shared_ptr<DiscreteDistributionInterface> rDist,
57  bool checkRooted = true,
58  bool verbose = true);
59 
75  const Tree& tree,
77  std::shared_ptr<TransitionModelInterface> model,
78  std::shared_ptr<DiscreteDistributionInterface> rDist,
79  bool checkRooted = true,
80  bool verbose = true);
81 
86 
88 
90 
91  DRHomogeneousTreeLikelihood* clone() const override { return new DRHomogeneousTreeLikelihood(*this); }
92 
93 private:
97  void init_();
98 
99 public:
107  void setData(const AlignmentDataInterface& sites) override;
108  double getLikelihood() const override;
109  double getLogLikelihood() const override;
110  double getLikelihoodForASite (size_t site) const override;
111  double getLogLikelihoodForASite(size_t site) const override;
112  size_t getSiteIndex(size_t site) const override { return likelihoodData_->getRootArrayPosition(site); }
115  void computeTreeLikelihood();
116 
117 
123  double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const override;
124  double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const override;
125  double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const override;
126  double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const override;
140  void setParameters(const ParameterList& parameters) override;
141 
145  double getValue() const override;
146 
152  double getFirstOrderDerivative(const std::string& variable) const override;
160  double getSecondOrderDerivative(const std::string& variable) const override;
161  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const override { return 0; } // Not implemented for now.
164 public:
165  // Specific methods:
166 
168  const DRASDRTreeLikelihoodData& likelihoodData() const override { return *likelihoodData_; }
169 
170  virtual void computeLikelihoodAtNode(int nodeId, VVVdouble& likelihoodArray) const override
171  {
172  computeLikelihoodAtNode_(tree_->getNode(nodeId), likelihoodArray);
173  }
174 
175 protected:
176  virtual void computeLikelihoodAtNode_(const Node* node, VVVdouble& likelihoodArray, const Node* sonNode = 0) const;
177 
182  virtual void computeSubtreeLikelihoodPostfix(const Node* node); // Recursive method.
188  virtual void computeSubtreeLikelihoodPrefix(const Node* node); // Recursive method.
189 
190  virtual void computeRootLikelihood();
191 
192  virtual void computeTreeDLikelihoodAtNode(const Node* node);
193  virtual void computeTreeDLikelihoods();
194 
195  virtual void computeTreeD2LikelihoodAtNode(const Node* node);
196  virtual void computeTreeD2Likelihoods();
197 
198  virtual void fireParameterChanged(const ParameterList& params) override;
199 
200  virtual void resetLikelihoodArrays(const Node* node);
201 
207  virtual void displayLikelihood(const Node* node);
208 
226  static void computeLikelihoodFromArrays(
227  const std::vector<const VVVdouble*>& iLik,
228  const std::vector<const VVVdouble*>& tProb,
229  VVVdouble& oLik, size_t nbNodes,
230  size_t nbDistinctSites,
231  size_t nbClasses,
232  size_t nbStates,
233  bool reset = true);
234 
255  static void computeLikelihoodFromArrays(
256  const std::vector<const VVVdouble*>& iLik,
257  const std::vector<const VVVdouble*>& tProb,
258  const VVVdouble* iLikR,
259  const VVVdouble* tProbR,
260  VVVdouble& oLik,
261  size_t nbNodes,
262  size_t nbDistinctSites,
263  size_t nbClasses,
264  size_t nbStates,
265  bool reset = true);
266 
268 };
269 } // end of namespace bpp.
270 #endif // BPP_PHYL_LEGACY_LIKELIHOOD_DRHOMOGENEOUSTREELIKELIHOOD_H
Partial implementation for homogeneous model 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.
A class to compute the average of several DRHomogeneousTreeLikelihood defined from a Mixed Substituti...
This class implements the likelihood computation for a tree using the double-recursive algorithm.
double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const override
Get the likelihood for a site knowing its rate class and its ancestral state.
virtual void fireParameterChanged(const ParameterList &params) override
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const override
Get the likelihood for a site knowing its rate class.
virtual void computeLikelihoodAtNode(int nodeId, VVVdouble &likelihoodArray) const override
Compute the likelihood array at a given node.
double getLikelihood() const override
Get the likelihood for the whole dataset.
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 &variable) const override
DRHomogeneousTreeLikelihood * clone() const override
virtual void resetLikelihoodArrays(const Node *node)
double getFirstOrderDerivative(const std::string &variable) const override
double getValue() const override
Function and NNISearchable interface.
double getLikelihoodForASite(size_t site) const override
Get the likelihood for a site.
void init_()
Method called by constructors.
const DRASDRTreeLikelihoodData & likelihoodData() const override
double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const override
Get the logarithm of the likelihood for a site knowing its rate class and its ancestral state.
virtual void computeTreeDLikelihoodAtNode(const Node *node)
void setParameters(const ParameterList &parameters) override
Implements the Function interface.
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
virtual void computeTreeD2LikelihoodAtNode(const Node *node)
virtual void computeLikelihoodAtNode_(const Node *node, VVVdouble &likelihoodArray, const Node *sonNode=0) const
double getLogLikelihood() const override
Get the logarithm of the likelihood for the whole dataset.
double getSecondOrderDerivative(const std::string &variable1, const std::string &variable2) const override
DRHomogeneousTreeLikelihood(const Tree &tree, std::shared_ptr< TransitionModelInterface > model, std::shared_ptr< DiscreteDistributionInterface > rDist, bool checkRooted=true, bool verbose=true)
Build a new DRHomogeneousTreeLikelihood object without data.
virtual void computeSubtreeLikelihoodPrefix(const Node *node)
double getLogLikelihoodForASite(size_t site) const override
Get the logarithm of the likelihood for a site.
void setData(const AlignmentDataInterface &sites) override
Set the dataset for which the likelihood must be evaluated.
std::unique_ptr< DRASDRTreeLikelihoodData > likelihoodData_
size_t getSiteIndex(size_t site) const override
Get the index (used for inner computations) of a given site (original alignment column).
DRHomogeneousTreeLikelihood & operator=(const DRHomogeneousTreeLikelihood &lik)
DRASDRTreeLikelihoodData & likelihoodData() override
double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const override
Get the logarithm of the likelihood for a site knowing its rate class.
virtual void computeSubtreeLikelihoodPostfix(const Node *node)
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