bpp-phyl  2.2.0
RNonHomogeneousTreeLikelihood.h
Go to the documentation of this file.
1 //
2 // File: RNonHomogeneousTreeLikelihood.h
3 // Created by: Julien Dutheil
4 // Created on: Tue Oct 9 16:03 2007
5 // From file: RHomogeneousTreeLikelihood.h
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for phylogenetic data analysis.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef _RNONHOMOGENEOUSTREELIKELIHOOD_H_
42 #define _RNONHOMOGENEOUSTREELIKELIHOOD_H_
43 
45 #include "../Model/SubstitutionModelSet.h"
47 
48 #include <Bpp/Numeric/VectorTools.h>
49 #include <Bpp/Numeric/Prob/DiscreteDistribution.h>
50 
51 namespace bpp
52 {
53 
88  {
89  private:
90 
92  double minusLogLik_;
93 
94  public:
111  const Tree& tree,
112  SubstitutionModelSet* modelSet,
113  DiscreteDistribution* rDist,
114  bool verbose = true,
115  bool usePatterns = true,
116  bool reparametrizeRoot = false)
117  throw (Exception);
118 
134  const Tree& tree,
135  const SiteContainer& data,
136  SubstitutionModelSet* modelSet,
137  DiscreteDistribution* rDist,
138  bool verbose = true,
139  bool usePatterns = true,
140  bool reparametrizeRoot = false)
141  throw (Exception);
142 
144 
146 
148 
150 
151  private:
152 
156  void init_(bool usePatterns) throw (Exception);
157 
158  public:
159 
167  void setData(const SiteContainer& sites) throw (Exception);
168  double getLikelihood() const;
169  double getLogLikelihood() const;
170  double getLikelihoodForASite(size_t site) const;
171  double getLogLikelihoodForASite(size_t site) const;
172  size_t getSiteIndex(size_t site) const throw (IndexOutOfBoundsException) { return likelihoodData_->getRootArrayPosition(site); }
181  double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
182  double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
183  double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
184  double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
200  void setParameters(const ParameterList& parameters) throw (ParameterNotFoundException, ConstraintException);
201  double getValue() const throw(Exception);
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  virtual 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 
257  virtual void computeDownSubtreeDLikelihood(const Node *);
258 
259  virtual void computeDownSubtreeD2Likelihood(const Node *);
260 
261  void fireParameterChanged(const ParameterList & params);
262 
268  virtual void displayLikelihood(const Node * node);
269 
270 
272  };
273 
274 
275 } //end of namespace bpp.
276 
277 #endif //_RNONHOMOGENEOUSTREELIKELIHOOD_H_
278 
virtual void computeDownSubtreeDLikelihood(const Node *)
This class implement the &#39;traditional&#39; way of computing likelihood for a tree, allowing for non-homog...
Substitution models manager for non-homogeneous / non-reversible models of evolution.
Partial implementation for branch non-homogeneous models of the TreeLikelihood interface.
virtual void computeTreeD2Likelihood(const std::string &variable)
size_t getRootArrayPosition(size_t currentPosition) const
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site.
STL namespace.
double getFirstOrderDerivative(const std::string &variable) const
void fireParameterChanged(const ParameterList &params)
discrete Rate Across Sites, (simple) Recursive likelihood data structure.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
size_t getSiteIndex(size_t site) const
Get the index (used for inner computations) of a given site (original alignment column).
double getLogLikelihoodForASite(size_t site) const
Get the logarithm of the likelihood for a site.
const DRASRTreeLikelihoodData * getLikelihoodData() const
virtual double getD2LikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the likelihood for a site knowing its rate class.
virtual double getD2LikelihoodForASite(size_t site) const
void setData(const SiteContainer &sites)
Set the dataset for which the likelihood must be evaluated.
RNonHomogeneousTreeLikelihood(const Tree &tree, SubstitutionModelSet *modelSet, DiscreteDistribution *rDist, bool verbose=true, bool usePatterns=true, bool reparametrizeRoot=false)
Build a new NonHomogeneousTreeLikelihood object without data.
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 getDLikelihoodForASite(size_t site) const
virtual double getDLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
The phylogenetic node class.
Definition: Node.h:90
virtual double getDLogLikelihoodForASite(size_t site) const
double getSecondOrderDerivative(const std::string &variable) const
void init_(bool usePatterns)
Method called by constructors.
void setParameters(const ParameterList &parameters)
Implements the Function interface.
double getLikelihood() const
Get the likelihood for the whole dataset.
double getLogLikelihood() const
Get the logarithm of the likelihood for the whole dataset.
virtual double getD2LogLikelihoodForASite(size_t site) const
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.
RNonHomogeneousTreeLikelihood * clone() const
double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the logarithm of the likelihood for a site knowing its rate class.
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...