bpp-phyl  2.2.0
DRHomogeneousTreeLikelihood.h
Go to the documentation of this file.
1 //
2 // File: DRHomogeneousTreeLikelihood.h
3 // Created by: Julien Dutheil
4 // Created on: Fri Oct 17 18:14:51 2003
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 _DRHOMOGENEOUSTREELIKELIHOOD_H_
41 #define _DRHOMOGENEOUSTREELIKELIHOOD_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 
66  public DRTreeLikelihood
67 {
68  private:
70 
71  protected:
72  double minusLogLik_;
73 
74  public:
90  const Tree& tree,
91  SubstitutionModel* model,
92  DiscreteDistribution* rDist,
93  bool checkRooted = true,
94  bool verbose = true)
95  throw (Exception);
96 
112  const Tree& tree,
113  const SiteContainer& data,
114  SubstitutionModel* model,
115  DiscreteDistribution* rDist,
116  bool checkRooted = true,
117  bool verbose = true)
118  throw (Exception);
119 
124 
126 
127  virtual ~DRHomogeneousTreeLikelihood();
128 
130 
131  private:
132 
136  void init_() throw (Exception);
137 
138  public:
139 
147  void setData(const SiteContainer & sites) throw (Exception);
148  double getLikelihood () const;
149  double getLogLikelihood() const;
150  double getLikelihoodForASite (size_t site) const;
151  double getLogLikelihoodForASite(size_t site) const;
152  size_t getSiteIndex(size_t site) const throw (IndexOutOfBoundsException) { return likelihoodData_->getRootArrayPosition(site); }
155  void computeTreeLikelihood();
156 
157 
163  double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
164  double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
165  double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
166  double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
180  void setParameters(const ParameterList & parameters) throw (ParameterNotFoundException, ConstraintException);
181 
185  double getValue() const throw (Exception);
186 
192  double getFirstOrderDerivative(const std::string& variable) const throw (Exception);
200  double getSecondOrderDerivative(const std::string& variable) const throw (Exception);
201  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const throw (Exception) { return 0; } // Not implemented for now.
204  public: // Specific methods:
205 
208 
209  virtual void computeLikelihoodAtNode(int nodeId, VVVdouble& likelihoodArray) const
210  {
211  computeLikelihoodAtNode_(tree_->getNode(nodeId), likelihoodArray);
212  }
213 
214  protected:
215  virtual void computeLikelihoodAtNode_(const Node* node, VVVdouble& likelihoodArray, const Node* sonNode = 0) const;
216 
221  virtual void computeSubtreeLikelihoodPostfix(const Node* node); //Recursive method.
227  virtual void computeSubtreeLikelihoodPrefix(const Node* node); //Recursive method.
228 
229  virtual void computeRootLikelihood();
230 
231  virtual void computeTreeDLikelihoodAtNode(const Node* node);
232  virtual void computeTreeDLikelihoods();
233 
234  virtual void computeTreeD2LikelihoodAtNode(const Node* node);
235  virtual void computeTreeD2Likelihoods();
236 
237  virtual void fireParameterChanged(const ParameterList& params);
238 
239  virtual void resetLikelihoodArrays(const Node* node);
240 
246  virtual void displayLikelihood(const Node* node);
247 
265  static void computeLikelihoodFromArrays(
266  const std::vector<const VVVdouble*>& iLik,
267  const std::vector<const VVVdouble*>& tProb,
268  VVVdouble& oLik, size_t nbNodes,
269  size_t nbDistinctSites,
270  size_t nbClasses,
271  size_t nbStates,
272  bool reset = true);
273 
294  static void computeLikelihoodFromArrays(
295  const std::vector<const VVVdouble*>& iLik,
296  const std::vector<const VVVdouble*>& tProb,
297  const VVVdouble* iLikR,
298  const VVVdouble* tProbR,
299  VVVdouble& oLik,
300  size_t nbNodes,
301  size_t nbDistinctSites,
302  size_t nbClasses,
303  size_t nbStates,
304  bool reset = true);
305 
307 };
308 
309 } //end of namespace bpp.
310 
311 #endif //_DRHOMOGENEOUSTREELIKELIHOOD_H_
312 
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 all substitution models.
virtual void computeLikelihoodAtNode(int nodeId, VVVdouble &likelihoodArray) const
Compute the likelihood array at a given node.
double getLikelihood() const
Get the likelihood for the whole dataset.
void setParameters(const ParameterList &parameters)
Implements the Function interface.
DRHomogeneousTreeLikelihood(const Tree &tree, SubstitutionModel *model, DiscreteDistribution *rDist, bool checkRooted=true, bool verbose=true)
Build a new DRHomogeneousTreeLikelihood object without data.
virtual void computeTreeD2LikelihoodAtNode(const Node *node)
virtual void computeSubtreeLikelihoodPostfix(const Node *node)
DRASDRTreeLikelihoodData * likelihoodData_
DRHomogeneousTreeLikelihood * clone() const
STL namespace.
virtual void resetLikelihoodArrays(const Node *node)
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).
DRASDRTreeLikelihoodData * getLikelihoodData()
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 init_()
Method called by constructors.
void setData(const SiteContainer &sites)
Set the dataset for which the likelihood must be evaluated.
double getValue() const
Function and NNISearchable interface.
double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the logarithm of the likelihood for a site knowing its rate class.
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site.
virtual void fireParameterChanged(const ParameterList &params)
This class implements the likelihood computation for a tree using the double-recursive algorithm...
double getSecondOrderDerivative(const std::string &variable) const
The phylogenetic node class.
Definition: Node.h:90
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
double getLogLikelihoodForASite(size_t site) const
Get the logarithm of the likelihood for a site.
const DRASDRTreeLikelihoodData * getLikelihoodData() const
double getLogLikelihood() const
Get the logarithm of 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.
virtual void computeSubtreeLikelihoodPrefix(const Node *node)
Interface for double-recursive (DR) implementation of the likelihood computation. ...
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...
virtual void computeLikelihoodAtNode_(const Node *node, VVVdouble &likelihoodArray, const Node *sonNode=0) const
Partial implementation for homogeneous model of the TreeLikelihood interface.
size_t getRootArrayPosition(const size_t site) const
virtual void computeTreeDLikelihoodAtNode(const Node *node)
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the likelihood for a site knowing its rate class.