bpp-phyl  2.2.0
DRHomogeneousMixedTreeLikelihood.h
Go to the documentation of this file.
1 //
2 // File: DRHomogeneousMixedTreeLikelihood.h
3 // Created by: Laurent Gueguen
4 //
5 
6 /*
7  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
8 
9  This software is a computer program whose purpose is to provide classes
10  for phylogenetic data analysis.
11 
12  This software is governed by the CeCILL license under French law and
13  abiding by the rules of distribution of free software. You can use,
14  modify and/ or redistribute the software under the terms of the CeCILL
15  license as circulated by CEA, CNRS and INRIA at the following URL
16  "http://www.cecill.info".
17 
18  As a counterpart to the access to the source code and rights to copy,
19  modify and redistribute granted by the license, users are provided only
20  with a limited warranty and the software's author, the holder of the
21  economic rights, and the successive licensors have only limited
22  liability.
23 
24  In this respect, the user's attention is drawn to the risks associated
25  with loading, using, modifying and/or developing or reproducing the
26  software by the user in light of its specific status of free software,
27  that may mean that it is complicated to manipulate, and that also
28  therefore means that it is reserved for developers and experienced
29  professionals having in-depth computer knowledge. Users are therefore
30  encouraged to load and test the software's suitability as regards their
31  requirements in conditions enabling the security of their systems and/or
32  data to be ensured and, more generally, to use and operate it in the
33  same conditions as regards security.
34 
35  The fact that you are presently reading this means that you have had
36  knowledge of the CeCILL license and that you accept its terms.
37  */
38 
39 #ifndef _DRHOMOGENEOUSMIXEDTREELIKELIHOOD_H_
40 #define _DRHOMOGENEOUSMIXEDTREELIKELIHOOD_H_
41 
43 #include "../Model/SubstitutionModel.h"
44 #include "../Model/MixedSubstitutionModel.h"
45 
46 #include <Bpp/Numeric/VectorTools.h>
47 #include <Bpp/Numeric/Prob/DiscreteDistribution.h>
48 
49 namespace bpp
50 {
51 
62 {
63 private:
64  std::vector<DRHomogeneousTreeLikelihood*> treeLikelihoodsContainer_;
65  std::vector<double> probas_;
66 
67  // true if the root Array should be computed (for ancestral
68  // reconstruction)
69 
70  bool rootArray_;
71 
72 public:
92  const Tree& tree,
93  SubstitutionModel* model,
94  DiscreteDistribution* rDist,
95  bool checkRooted = true,
96  bool verbose = true,
97  bool rootArray = false)
98  throw (Exception);
99 
117  const Tree& tree,
118  const SiteContainer& data,
119  SubstitutionModel* model,
120  DiscreteDistribution* rDist,
121  bool checkRooted = true,
122  bool verbose = true,
123  bool rootArray = false)
124  throw (Exception);
125 
127 
129 
131 
133 
134 public:
142  double getLikelihood() const;
143  double getLogLikelihood() const;
144 
145  void setData(const SiteContainer& sites) throw (Exception);
146  double getLikelihoodForASite (size_t site) const;
147  double getLogLikelihoodForASite(size_t site) const;
156  double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
157  double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const;
158  double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
159  double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const;
167  double getFirstOrderDerivative(const std::string& variable) const throw (Exception);
175  double getSecondOrderDerivative(const std::string& variable) const throw (Exception);
176  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const throw (Exception) { return 0; } // Not implemented for now.
179 public:
180  // Specific methods:
181  void initialize() throw (Exception);
182 
183  void fireParameterChanged(const ParameterList& params);
184 
185  void computeTreeLikelihood();
186 
187  virtual void computeTreeDLikelihoods();
188 
189 protected:
190  virtual void computeLikelihoodAtNode_(const Node* node, VVVdouble& likelihoodArray, const Node* sonNode = 0) const;
191 
197  virtual void computeSubtreeLikelihoodPostfix(const Node* node);
198 
199  virtual void computeSubtreeLikelihoodPrefix(const Node* node);
200 
201  virtual void computeRootLikelihood();
202 
203  virtual void computeTreeD2LikelihoodAtNode(const Node*);
204  virtual void computeTreeD2Likelihoods();
205 
206  void resetLikelihoodArrays(const Node* node);
207 
213  virtual void displayLikelihood(const Node* node);
214 };
215 } // end of namespace bpp.
216 
217 #endif // _DRHOMOGENEOUSMIXEDTREELIKELIHOOD_H_
218 
double getFirstOrderDerivative(const std::string &variable) const
Interface for all substitution models.
virtual void computeLikelihoodAtNode_(const Node *node, VVVdouble &likelihoodArray, const Node *sonNode=0) const
double getSecondOrderDerivative(const std::string &variable1, const std::string &variable2) const
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site.
virtual void computeSubtreeLikelihoodPostfix(const Node *node)
Compute the likelihood for a subtree defined by the Tree::Node node.
std::vector< DRHomogeneousTreeLikelihood * > treeLikelihoodsContainer_
DRHomogeneousMixedTreeLikelihood * clone() const
Interface for phylogenetic tree objects.
Definition: Tree.h:148
double getLogLikelihoodForASite(size_t site) const
Get the logarithm of the likelihood for a site.
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
DRHomogeneousMixedTreeLikelihood(const Tree &tree, SubstitutionModel *model, DiscreteDistribution *rDist, bool checkRooted=true, bool verbose=true, bool rootArray=false)
Build a new DRHomogeneousMixedTreeLikelihood object without data.
virtual void computeSubtreeLikelihoodPrefix(const Node *node)
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the likelihood for a site knowing its rate class.
This class implements the likelihood computation for a tree using the double-recursive algorithm...
double getLikelihood() const
Get the likelihood for the whole dataset.
void fireParameterChanged(const ParameterList &params)
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
The phylogenetic node class.
Definition: Node.h:90
void setData(const SiteContainer &sites)
Set the dataset for which the likelihood must be evaluated.
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.
A class to compute the average of several DRHomogeneousTreeLikelihood defined from a Mixed Substituti...
double getLogLikelihood() const
Get the logarithm of the likelihood for the whole dataset.
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...