bpp-phyl  2.4.0
TreeLikelihood.h
Go to the documentation of this file.
1 //
2 // File: TreeLikelihood.h
3 // Created by: Julien Dutheil
4 // Created on: Fri Oct 17 17:36:44 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 _TREELIKELIHOOD_H_
41 #define _TREELIKELIHOOD_H_
42 
43 #include "../Node.h"
44 #include "../Tree.h"
45 #include "../Model/SubstitutionModel.h"
46 #include "TreeLikelihoodData.h"
47 
52 
53 // From SeqLib:
56 
57 namespace bpp
58 {
59 
67  public virtual DerivableSecondOrder
68  {
69  public:
74  {
75  public:
76  virtual ~BranchIterator() {}
77 
78  public:
82  virtual int next() = 0;
86  virtual bool hasNext() const = 0;
87  };
88 
95  {
96  public:
97  virtual ~SiteIterator() {}
98 
99  public:
103  virtual size_t next() = 0;
107  virtual bool hasNext() const = 0;
108  };
109 
114  {
115  public:
117 
118  public:
119  virtual const TransitionModel* getModel() const = 0;
120  virtual const SubstitutionModel* getSubstitutionModel() const = 0;
121  virtual SiteIterator* getNewSiteIterator() const = 0;
122  };
123 
128  {
129  public:
131 
132  public:
133  virtual ConstBranchModelDescription* next() = 0;
134  virtual bool hasNext() const = 0;
135  };
136 
141  {
142  public:
144 
145  public:
146  virtual const TransitionModel* getModel() const = 0;
147  virtual const SubstitutionModel* getSubstitutionModel() const = 0;
148  virtual BranchIterator* getNewBranchIterator() const = 0;
149  };
150 
155  {
156  public:
158 
159  public:
160  virtual ConstSiteModelDescription* next() = 0;
161  virtual bool hasNext() const = 0;
162  };
163 
164  public:
166  virtual ~TreeLikelihood() {}
167 
168  TreeLikelihood* clone() const = 0;
169 
170  public:
171 
177  virtual void setData(const SiteContainer& sites) = 0;
178 
184  virtual const SiteContainer* getData() const = 0;
185 
194  virtual void initialize() = 0;
195 
199  virtual bool isInitialized() const = 0;
200 
204  virtual TreeLikelihoodData* getLikelihoodData() = 0;
205 
209  virtual const TreeLikelihoodData* getLikelihoodData() const = 0;
210 
217  virtual double getLikelihoodForASite(size_t site) const = 0;
218 
225  virtual double getLogLikelihoodForASite(size_t site) const = 0;
226 
234  virtual double getLikelihoodForASiteForAState(size_t site, int state) const = 0;
235 
243  virtual double getLogLikelihoodForASiteForAState(size_t site, int state) const = 0;
244 
250  virtual Vdouble getLikelihoodForEachSite() const = 0;
251 
257  virtual Vdouble getLogLikelihoodForEachSite() const = 0;
258 
265 
272 
278  virtual double getLikelihood() const = 0;
279 
285  virtual double getLogLikelihood() const = 0;
286 
292  virtual const Tree& getTree() const = 0;
293 
299  virtual size_t getNumberOfSites() const = 0;
300 
304  virtual size_t getNumberOfStates() const = 0;
305 
309  virtual int getAlphabetStateAsInt(size_t i) const = 0;
310 
314  virtual std::string getAlphabetStateAsChar(size_t i) const = 0;
315 
319  virtual const std::vector<int>& getAlphabetStates() const = 0;
320 
326  virtual const Alphabet* getAlphabet() const = 0;
327 
339  virtual ParameterList getBranchLengthsParameters() const = 0;
340 
346  virtual ParameterList getSubstitutionModelParameters() const = 0;
347 
356  virtual const TransitionModel* getModelForSite(int nodeId, size_t siteIndex) const = 0;
357 
367  virtual TransitionModel* getModelForSite(int nodeId, size_t siteIndex) = 0;
368 
379  virtual VVdouble getTransitionProbabilities(int nodeId, size_t siteIndex) const = 0;
380 
381  virtual ConstBranchModelIterator* getNewBranchModelIterator(int nodeId) const = 0;
382 
383  virtual ConstSiteModelIterator* getNewSiteModelIterator(size_t siteIndex) const = 0;
384 
391  virtual size_t getSiteIndex(size_t site) const = 0;
392 
406  virtual const std::vector<double>& getRootFrequencies(size_t siteIndex) const = 0;
407 
417  virtual void enableDerivatives(bool yn) = 0;
418 
426  virtual ParameterList getDerivableParameters() const = 0;
427 
435  virtual ParameterList getNonDerivableParameters() const = 0;
436 
437  };
438 
439 } //end of namespace bpp.
440 
441 #endif //_TREELIKELIHOOD_H_
442 
virtual const Alphabet * getAlphabet() const =0
Get the alphabet associated to the dataset.
A pair of SubstitutionModel / SiteIterator.
virtual void setData(const SiteContainer &sites)=0
Set the dataset for which the likelihood must be evaluated.
Interface for all substitution models.
virtual const TransitionModel * getModelForSite(int nodeId, size_t siteIndex) const =0
Get the substitution model associated to a given node and alignment column.
virtual const SiteContainer * getData() const =0
Get the dataset for which the likelihood must be evaluated.
virtual ParameterList getBranchLengthsParameters() const =0
Get the branch lengths parameters.
TreeLikelihood * clone() const =0
An iterator over a set of sites, speicfied by their position.
Iterates through all models used for all sites on a given branch.
virtual Vdouble getLikelihoodForEachSite() const =0
Get the likelihood for each site.
The TreeLikelihood interface.
virtual size_t getNumberOfStates() const =0
TreeLikelihood data structure.
virtual std::string getAlphabetStateAsChar(size_t i) const =0
virtual int getAlphabetStateAsInt(size_t i) const =0
virtual const std::vector< double > & getRootFrequencies(size_t siteIndex) const =0
Get the values of the frequencies for each state in the alphabet at the root node.
virtual VVdouble getTransitionProbabilities(int nodeId, size_t siteIndex) const =0
Retrieves all Pij(t) for a particular branch, defined by the upper node and site. ...
virtual double getLikelihoodForASiteForAState(size_t site, int state) const =0
Get the likelihood for a site and for a state.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
virtual const std::vector< int > & getAlphabetStates() const =0
virtual double getLogLikelihoodForASite(size_t site) const =0
Get the logarithm of the likelihood for a site.
virtual ConstSiteModelIterator * getNewSiteModelIterator(size_t siteIndex) const =0
virtual double getLogLikelihoodForASiteForAState(size_t site, int state) const =0
Get the logarithm of the likelihood for a site and for a state.
virtual ConstBranchModelIterator * getNewBranchModelIterator(int nodeId) const =0
virtual size_t getNumberOfSites() const =0
Get the number of sites in the dataset.
Iterates through all models used for all branches on a given site.
virtual TreeLikelihoodData * getLikelihoodData()=0
virtual ParameterList getNonDerivableParameters() const =0
All non derivable parameters.
virtual const Tree & getTree() const =0
Get the tree (topology and branch lengths).
virtual double getLikelihoodForASite(size_t site) const =0
Get the likelihood for a site.
std::vector< double > Vdouble
virtual VVdouble getLogLikelihoodForEachSiteForEachState() const =0
Get the logarithm of the likelihood for each site and for each state.
virtual size_t getSiteIndex(size_t site) const =0
Get the index (used for inner computations) of a given site (original alignment column).
virtual bool isInitialized() const =0
virtual ParameterList getDerivableParameters() const =0
All derivable parameters.
virtual void enableDerivatives(bool yn)=0
Tell if derivatives must be computed.
An iterator over a set of branches, specified by their node ids.
virtual double getLikelihood() const =0
Get the likelihood for the whole dataset.
virtual double getLogLikelihood() const =0
Get the logarithm of the likelihood for the whole dataset.
A pair of SubstitutionModel / BranchIterator.
virtual void initialize()=0
Init the likelihood object.
std::vector< Vdouble > VVdouble
virtual bool hasNext() const =0
virtual Vdouble getLogLikelihoodForEachSite() const =0
Get the logarithm of the likelihood for each site.
virtual VVdouble getLikelihoodForEachSiteForEachState() const =0
Get the likelihood for each site and for each state.
virtual ParameterList getSubstitutionModelParameters() const =0
Get the parameters associated to substitution model(s).