bpp-phyl  2.2.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 
48 #include <Bpp/Numeric/ParameterList.h>
49 #include <Bpp/Numeric/Parametrizable.h>
50 #include <Bpp/Numeric/Function/Functions.h>
51 #include <Bpp/Numeric/VectorTools.h>
52 
53 // From SeqLib:
54 #include <Bpp/Seq/Alphabet/Alphabet.h>
55 #include <Bpp/Seq/Container/SiteContainer.h>
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() throw (Exception) = 0;
86  virtual bool hasNext() const = 0;
87  };
88 
95  {
96  public:
97  virtual ~SiteIterator() {}
98 
99  public:
103  virtual size_t next() throw (Exception) = 0;
107  virtual bool hasNext() const = 0;
108  };
109 
114  {
115  public:
117 
118  public:
119  virtual const SubstitutionModel* getModel() const = 0;
120  virtual SiteIterator* getNewSiteIterator() const = 0;
121  };
122 
127  {
128  public:
130 
131  public:
132  virtual ConstBranchModelDescription* next() throw (Exception) = 0;
133  virtual bool hasNext() const = 0;
134  };
135 
140  {
141  public:
143 
144  public:
145  virtual const SubstitutionModel* getModel() const = 0;
146  virtual BranchIterator* getNewBranchIterator() const = 0;
147  };
148 
153  {
154  public:
156 
157  public:
158  virtual ConstSiteModelDescription* next() throw (Exception) = 0;
159  virtual bool hasNext() const = 0;
160  };
161 
162  public:
164  virtual ~TreeLikelihood() {}
165 
166 #ifndef NO_VIRTUAL_COV
167  TreeLikelihood* clone() const = 0;
168 #endif
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() throw (Exception) = 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 
264  virtual VVdouble getLikelihoodForEachSiteForEachState() const = 0;
265 
271  virtual VVdouble getLogLikelihoodForEachSiteForEachState() const = 0;
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 
357  virtual const SubstitutionModel* getSubstitutionModel(int nodeId, size_t siteIndex) const throw (NodeNotFoundException) = 0;
358 
368  virtual SubstitutionModel* getSubstitutionModel(int nodeId, size_t siteIndex) throw (NodeNotFoundException) = 0;
369 
380  virtual VVdouble getTransitionProbabilities(int nodeId, size_t siteIndex) const = 0;
381 
382  virtual ConstBranchModelIterator* getNewBranchModelIterator(int nodeId) const = 0;
383 
384  virtual ConstSiteModelIterator* getNewSiteModelIterator(size_t siteIndex) const = 0;
385 
392  virtual size_t getSiteIndex(size_t site) const throw (IndexOutOfBoundsException) = 0;
393 
407  virtual const std::vector<double>& getRootFrequencies(size_t siteIndex) const = 0;
408 
418  virtual void enableDerivatives(bool yn) = 0;
419 
427  virtual ParameterList getDerivableParameters() const = 0;
428 
436  virtual ParameterList getNonDerivableParameters() const = 0;
437 
438 };
439 
440 } //end of namespace bpp.
441 
442 #endif //_TREELIKELIHOOD_H_
443 
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 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.
STL namespace.
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.
virtual const SubstitutionModel * getSubstitutionModel(int nodeId, size_t siteIndex) const =0
Get the substitution model associated to a given node and alignment column.
virtual VVdouble getLogLikelihoodForEachSiteForEachState() const =0
Get the logarithm of the likelihood for each site and for each state.
Exception thrown when something is wrong with a particular node.
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.
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).