bpp-phyl3  3.0.0
RNonHomogeneousTreeLikelihood.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_RNONHOMOGENEOUSTREELIKELIHOOD_H
6 #define BPP_PHYL_LEGACY_LIKELIHOOD_RNONHOMOGENEOUSTREELIKELIHOOD_H
7 
10 
11 #include "../Model/SubstitutionModelSet.h"
14 
15 namespace bpp
16 {
51 {
52 private:
53  mutable std::shared_ptr<DRASRTreeLikelihoodData> likelihoodData_;
54  double minusLogLik_;
55 
56 public:
73  const Tree& tree,
74  std::shared_ptr<SubstitutionModelSet> modelSet,
75  std::shared_ptr<DiscreteDistributionInterface> rDist,
76  bool verbose = true,
77  bool usePatterns = true,
78  bool reparametrizeRoot = false);
79 
95  const Tree& tree,
97  std::shared_ptr<SubstitutionModelSet> modelSet,
98  std::shared_ptr<DiscreteDistributionInterface> rDist,
99  bool verbose = true,
100  bool usePatterns = true,
101  bool reparametrizeRoot = false);
102 
104 
106 
108 
110 
111 private:
115  void init_(bool usePatterns);
116 
117 public:
125  void setData(const AlignmentDataInterface& sites);
126  double getLikelihood() const;
127  double getLogLikelihood() const;
128  double getLikelihoodForASite(size_t site) const;
129  double getLogLikelihoodForASite(size_t site) const;
130  size_t getSiteIndex(size_t site) const { return likelihoodData_->getRootArrayPosition(site); }
139  double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
140  double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
141  double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
142  double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
158  void setParameters(const ParameterList& parameters);
159  double getValue() const;
160 
166  double getFirstOrderDerivative(const std::string& variable) const;
174  double getSecondOrderDerivative(const std::string& variable) const;
175  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const { return 0; } // Not implemented for now.
178 public:
179  // Specific methods:
180 
182 
184 
185  virtual void computeTreeLikelihood();
186 
187  virtual double getDLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
188 
189  virtual double getDLikelihoodForASite(size_t site) const;
190 
191  virtual double getDLogLikelihoodForASite(size_t site) const;
192 
193  virtual double getDLogLikelihood() const;
194 
195  virtual void computeTreeDLikelihood(const std::string& variable);
196 
197  virtual double getD2LikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
198 
199  virtual double getD2LikelihoodForASite(size_t site) const;
200 
201  virtual double getD2LogLikelihoodForASite(size_t site) const;
202 
203  virtual double getD2LogLikelihood() const;
204 
205  virtual void computeTreeD2Likelihood(const std::string& variable);
206 
207 protected:
213  virtual void computeSubtreeLikelihood(const Node* node); // Recursive method.
214 
215  virtual void computeDownSubtreeDLikelihood(const Node*);
216 
217  virtual void computeDownSubtreeD2Likelihood(const Node*);
218 
219  void fireParameterChanged(const ParameterList& params);
220 
226  virtual void displayLikelihood(const Node* node);
227 
228 
230 };
231 } // end of namespace bpp.
232 #endif // BPP_PHYL_LEGACY_LIKELIHOOD_RNONHOMOGENEOUSTREELIKELIHOOD_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).
discrete Rate Across Sites, (simple) Recursive likelihood data structure.
The phylogenetic node class.
Definition: Node.h:59
This class implement the 'traditional' way of computing likelihood for a tree, allowing for non-homog...
double getFirstOrderDerivative(const std::string &variable) const
void init_(bool usePatterns)
Method called by constructors.
virtual double getD2LikelihoodForASite(size_t site) const
void setParameters(const ParameterList &parameters)
Implements the Function interface.
double getLikelihood() const
Get the likelihood for the whole dataset.
virtual void computeTreeDLikelihood(const std::string &variable)
RNonHomogeneousTreeLikelihood & operator=(const RNonHomogeneousTreeLikelihood &lik)
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site.
RNonHomogeneousTreeLikelihood(const Tree &tree, std::shared_ptr< SubstitutionModelSet > modelSet, std::shared_ptr< DiscreteDistributionInterface > rDist, bool verbose=true, bool usePatterns=true, bool reparametrizeRoot=false)
Build a new NonHomogeneousTreeLikelihood object without data.
double getLogLikelihood() const
Get the logarithm of the likelihood for the whole dataset.
void fireParameterChanged(const ParameterList &params)
double getSecondOrderDerivative(const std::string &variable1, const std::string &variable2) const
virtual double getDLikelihoodForASite(size_t site) const
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.
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.
virtual double getD2LogLikelihoodForASite(size_t site) const
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the likelihood for a site knowing its rate class.
void setData(const AlignmentDataInterface &sites)
Set the dataset for which the likelihood must be evaluated.
virtual double getDLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
std::shared_ptr< DRASRTreeLikelihoodData > likelihoodData_
virtual double getDLogLikelihoodForASite(size_t site) const
size_t getSiteIndex(size_t site) const
Get the index (used for inner computations) of a given site (original alignment column).
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
virtual void computeDownSubtreeDLikelihood(const Node *)
virtual double getD2LikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
virtual void computeTreeD2Likelihood(const std::string &variable)
double getLogLikelihoodForASite(size_t site) const
Get the logarithm of the likelihood for a site.
RNonHomogeneousTreeLikelihood * clone() const
const DRASRTreeLikelihoodData & likelihoodData() const
double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the logarithm of the likelihood for a site knowing its rate class.
double getSecondOrderDerivative(const std::string &variable) const
virtual void computeSubtreeLikelihood(const Node *node)
Compute the likelihood for a subtree defined by the Tree::Node node.
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.