bpp-phyl  2.2.0
DRNonHomogeneousTreeLikelihood.h
Go to the documentation of this file.
1 //
2 // File: DRNonHomogeneousTreeLikelihood.h
3 // Created by: Julien Dutheil
4 // Created on: Fri Dec 28 19:14 2007
5 //
6 
7 /*
8 Copyright or © or Copr. CNRS, (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 _DRNONHOMOGENEOUSTREELIKELIHOOD_H_
41 #define _DRNONHOMOGENEOUSTREELIKELIHOOD_H_
42 
44 #include "DRTreeLikelihood.h"
46 
47 #include <Bpp/Numeric/VectorTools.h>
48 #include <Bpp/Numeric/Prob/DiscreteDistribution.h>
49 
50 namespace bpp
51 {
52 
70  public DRTreeLikelihood
71 {
72  protected:
74  double minusLogLik_;
75 
76  public:
92  const Tree& tree,
93  SubstitutionModelSet* modelSet,
94  DiscreteDistribution* rDist,
95  bool verbose = true,
96  bool reparametrizeRoot = false)
97  throw (Exception);
98 
114  const Tree& tree,
115  const SiteContainer& data,
116  SubstitutionModelSet* modelSet,
117  DiscreteDistribution* rDist,
118  bool verbose = true,
119  bool reparametrizeRoot = false)
120  throw (Exception);
121 
126 
128 
130 
132 
133  private:
134 
138  void init_() throw (Exception);
139 
140  public:
141 
149  void setData(const SiteContainer& sites) throw (Exception);
150  double getLikelihood () const;
151  double getLogLikelihood() const;
152  double getLikelihoodForASite (size_t site) const;
153  double getLogLikelihoodForASite(size_t site) const;
154  size_t getSiteIndex(size_t site) const throw (IndexOutOfBoundsException) { return likelihoodData_->getRootArrayPosition(site); }
157  void computeTreeLikelihood();
158 
159 
165  double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
166  double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
167  double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
168  double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
182  void setParameters(const ParameterList& parameters) throw (ParameterNotFoundException, ConstraintException);
183 
187  double getValue() const throw (Exception);
188 
194  double getFirstOrderDerivative(const std::string& variable) const throw (Exception);
202  double getSecondOrderDerivative(const std::string& variable) const throw (Exception);
203  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const throw (Exception) { return 0; } // Not implemented for now.
206  public: // Specific methods:
207 
210 
211  virtual void computeLikelihoodAtNode(int nodeId, VVVdouble& likelihoodArray) const
212  {
213  computeLikelihoodAtNode_(tree_->getNode(nodeId), likelihoodArray);
214  }
215 
216  protected:
217  virtual void computeLikelihoodAtNode_(const Node* node, VVVdouble& likelihoodArray) const;
218 
219 
224  virtual void computeSubtreeLikelihoodPostfix(const Node* node); //Recursive method.
230  virtual void computeSubtreeLikelihoodPrefix(const Node* node); //Recursive method.
231 
232  virtual void computeRootLikelihood();
233 
234  virtual void computeTreeDLikelihoodAtNode(const Node* node);
235  virtual void computeTreeDLikelihoods();
236 
237  virtual void computeTreeD2LikelihoodAtNode(const Node* node);
238  virtual void computeTreeD2Likelihoods();
239 
240  void fireParameterChanged(const ParameterList& params);
241 
242  void resetLikelihoodArrays(const Node* node);
243 
249  virtual void displayLikelihood(const Node* node);
250 
268  static void computeLikelihoodFromArrays(
269  const std::vector<const VVVdouble*>& iLik,
270  const std::vector<const VVVdouble*>& tProb,
271  VVVdouble& oLik, size_t nbNodes,
272  size_t nbDistinctSites,
273  size_t nbClasses,
274  size_t nbStates,
275  bool reset = true);
276 
297  static void computeLikelihoodFromArrays(
298  const std::vector<const VVVdouble*>& iLik,
299  const std::vector<const VVVdouble*>& tProb,
300  const VVVdouble* iLikR,
301  const VVVdouble* tProbR,
302  VVVdouble& oLik,
303  size_t nbNodes,
304  size_t nbDistinctSites,
305  size_t nbClasses,
306  size_t nbStates,
307  bool reset = true);
308 
310 };
311 
312 } //end of namespace bpp.
313 
314 #endif //_DRNONHOMOGENEOUSTREELIKELIHOOD_H_
315 
void setData(const SiteContainer &sites)
Set the dataset for which the likelihood must be evaluated.
Substitution models manager for non-homogeneous / non-reversible models of evolution.
double getLogLikelihoodForASite(size_t site) const
Get the logarithm of the likelihood for a site.
Partial implementation for branch non-homogeneous models of the TreeLikelihood interface.
DRNonHomogeneousTreeLikelihood(const Tree &tree, SubstitutionModelSet *modelSet, DiscreteDistribution *rDist, bool verbose=true, bool reparametrizeRoot=false)
Build a new DRNonHomogeneousTreeLikelihood object without data.
double getLogLikelihood() const
Get the logarithm of the likelihood for the whole dataset.
virtual void computeTreeDLikelihoodAtNode(const Node *node)
STL namespace.
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the likelihood for a site knowing its rate class.
double getFirstOrderDerivative(const std::string &variable) 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.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
virtual void computeSubtreeLikelihoodPostfix(const Node *node)
DRNonHomogeneousTreeLikelihood * clone() const
void init_()
Method called by constructors.
double getValue() const
Function and NNISearchable interface.
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...
void fireParameterChanged(const ParameterList &params)
virtual void computeLikelihoodAtNode(int nodeId, VVVdouble &likelihoodArray) const
Compute the likelihood array at a given node.
double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the logarithm of the likelihood for a site knowing its rate class.
The phylogenetic node class.
Definition: Node.h:90
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
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 getLikelihood() const
Get the likelihood for the whole dataset.
void setParameters(const ParameterList &parameters)
Implements the Function interface.
virtual void computeSubtreeLikelihoodPrefix(const Node *node)
This class implements the likelihood computation for a tree using the double-recursive algorithm...
Interface for double-recursive (DR) implementation of the likelihood computation. ...
Likelihood data structure for rate across sites models, using a double-recursive algorithm.
virtual void computeLikelihoodAtNode_(const Node *node, VVVdouble &likelihoodArray) const
virtual void computeTreeD2LikelihoodAtNode(const Node *node)
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site.
size_t getRootArrayPosition(const size_t site) const
const DRASDRTreeLikelihoodData * getLikelihoodData() const
size_t getSiteIndex(size_t site) const
Get the index (used for inner computations) of a given site (original alignment column).
double getSecondOrderDerivative(const std::string &variable) const