bpp-phyl  2.2.0
RHomogeneousTreeLikelihood.h
Go to the documentation of this file.
1 //
2 // File: RHomogeneousTreeLikelihood.h
3 // Created by: Julien Dutheil
4 // Created on: Fri Oct 17 18:14:51 2003
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _RHOMOGENEOUSTREELIKELIHOOD_H_
41 #define _RHOMOGENEOUSTREELIKELIHOOD_H_
42 
44 #include "../Model/SubstitutionModel.h"
46 
47 #include <Bpp/Numeric/VectorTools.h>
48 #include <Bpp/Numeric/Prob/DiscreteDistribution.h>
49 
50 namespace bpp
51 {
52 
84  {
85  private:
86 
88 
89  protected:
90  double minusLogLik_;
91 
92  public:
109  const Tree& tree,
110  SubstitutionModel* model,
111  DiscreteDistribution* rDist,
112  bool checkRooted = true,
113  bool verbose = true,
114  bool usePatterns = true)
115  throw (Exception);
116 
133  const Tree& tree,
134  const SiteContainer& data,
135  SubstitutionModel* model,
136  DiscreteDistribution* rDist,
137  bool checkRooted = true,
138  bool verbose = true,
139  bool usePatterns = true)
140  throw (Exception);
141 
143 
145 
146  virtual ~RHomogeneousTreeLikelihood();
147 
149 
150  private:
151 
155  void init_(bool usePatterns) throw (Exception);
156 
157  public:
158 
166  void setData(const SiteContainer& sites) throw (Exception);
167  double getLikelihood() const;
168  double getLogLikelihood() const;
169  double getLikelihoodForASite (size_t site) const;
170  double getLogLikelihoodForASite(size_t site) const;
179  double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
180  double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
181  double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
182  double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
198  void setParameters(const ParameterList& parameters) throw (ParameterNotFoundException, ConstraintException);
199  double getValue() const throw(Exception);
200 
201  size_t getSiteIndex(size_t site) const throw (IndexOutOfBoundsException) { return likelihoodData_->getRootArrayPosition(site); }
202 
208  double getFirstOrderDerivative(const std::string& variable) const throw (Exception);
216  double getSecondOrderDerivative(const std::string& variable) const throw (Exception);
217  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const throw (Exception) { return 0; } // Not implemented for now.
220  public: // Specific methods:
221 
224 
225  void computeTreeLikelihood();
226 
227  virtual double getDLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
228 
229  virtual double getDLikelihoodForASite(size_t site) const;
230 
231  virtual double getDLogLikelihoodForASite(size_t site) const;
232 
233  virtual double getDLogLikelihood() const;
234 
235  virtual void computeTreeDLikelihood(const std::string& variable);
236 
237  virtual double getD2LikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
238 
239  virtual double getD2LikelihoodForASite(size_t site) const;
240 
241  virtual double getD2LogLikelihoodForASite(size_t site) const;
242 
243  virtual double getD2LogLikelihood() const;
244 
245  virtual void computeTreeD2Likelihood(const std::string& variable);
246 
247 
248  protected:
249 
255  virtual void computeSubtreeLikelihood(const Node* node); //Recursive method.
256  virtual void computeDownSubtreeDLikelihood(const Node*);
257 
258  virtual void computeDownSubtreeD2Likelihood(const Node*);
259 
260  void fireParameterChanged(const ParameterList& params);
261 
267  virtual void displayLikelihood(const Node* node);
268 
270  };
271 
272 
273 } //end of namespace bpp.
274 
275 #endif //_RHOMOGENEOUSTREELIKELIHOOD_H_
276 
virtual void computeDownSubtreeDLikelihood(const Node *)
RHomogeneousTreeLikelihood * clone() const
Interface for all substitution models.
RHomogeneousTreeLikelihood(const Tree &tree, SubstitutionModel *model, DiscreteDistribution *rDist, bool checkRooted=true, bool verbose=true, bool usePatterns=true)
Build a new RHomogeneousTreeLikelihood object without data.
double getLogLikelihoodForASite(size_t site) const
Get the logarithm of the likelihood for a site.
size_t getSiteIndex(size_t site) const
Get the index (used for inner computations) of a given site (original alignment column).
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...
size_t getRootArrayPosition(size_t currentPosition) const
DRASRTreeLikelihoodData * likelihoodData_
virtual double getD2LogLikelihoodForASite(size_t site) const
virtual void computeDownSubtreeD2Likelihood(const Node *)
virtual double getD2LikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
virtual void computeTreeD2Likelihood(const std::string &variable)
DRASRTreeLikelihoodData * getLikelihoodData()
discrete Rate Across Sites, (simple) Recursive likelihood data structure.
double getLikelihood() const
Get the likelihood for the whole dataset.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
double getSecondOrderDerivative(const std::string &variable1, const std::string &variable2) const
This class implement the &#39;traditional&#39; way of computing likelihood for a tree.
virtual double getDLogLikelihoodForASite(size_t site) const
const DRASRTreeLikelihoodData * getLikelihoodData() const
void fireParameterChanged(const ParameterList &params)
double getLogLikelihood() const
Get the logarithm of the likelihood for the whole dataset.
virtual double getD2LikelihoodForASite(size_t site) const
The phylogenetic node class.
Definition: Node.h:90
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site.
void setParameters(const ParameterList &parameters)
Implements the Function interface.
double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the logarithm of the likelihood for a site knowing its rate class.
virtual void computeTreeDLikelihood(const std::string &variable)
virtual void computeSubtreeLikelihood(const Node *node)
Compute the likelihood for a subtree defined by the Tree::Node node.
virtual double getDLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
double getSecondOrderDerivative(const std::string &variable) const
virtual double getDLikelihoodForASite(size_t site) const
double getFirstOrderDerivative(const std::string &variable) const
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
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.
Partial implementation for homogeneous model of the TreeLikelihood interface.
void init_(bool usePatterns)
Method called by constructors.
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the likelihood for a site knowing its rate class.
void setData(const SiteContainer &sites)
Set the dataset for which the likelihood must be evaluated.