~ubuntu-branches/ubuntu/raring/libbpp-phyl/raring

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/Likelihood/RHomogeneousMixedTreeLikelihood.h

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-yvx78svv6w7xxgph
Tags: upstream-2.0.2
Import upstream version 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// File: RHomogeneousMixedTreeLikelihood.h
 
3
// Created by: Davud Fournier, Laurent Gueguen
 
4
//
 
5
 
 
6
/*
 
7
   Copyright or � or Copr. CNRS, (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 _RHOMOGENEOUSMIXEDTREELIKELIHOOD_H_
 
40
#define _RHOMOGENEOUSMIXEDTREELIKELIHOOD_H_
 
41
 
 
42
#include "RHomogeneousTreeLikelihood.h"
 
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
/**
 
52
 *@ brief A class to compute the average of several
 
53
 *RHomogeneousTreeLikelihood defined from a Mixed Substitution
 
54
 *Model.
 
55
 *
 
56
 * In all the calculs, the average of the likelihoods, probabilities
 
57
 * are computed.
 
58
 **/
 
59
 
 
60
class RHomogeneousMixedTreeLikelihood :
 
61
  public RHomogeneousTreeLikelihood
 
62
{
 
63
private:
 
64
  std::vector<RHomogeneousTreeLikelihood*> treeLikelihoodsContainer_;
 
65
  std::vector<double> probas_;
 
66
  
 
67
public:
 
68
  /**
 
69
   * @brief Build a new RHomogeneousMixedTreeLikelihood object without
 
70
   * data.
 
71
   *
 
72
   * This constructor only initialize the parameters. To compute a
 
73
   * likelihood, you will need to call the setData() and the
 
74
   * computeTreeLikelihood() methods.
 
75
   *
 
76
   * @param tree The tree to use.
 
77
   * @param model The mixed substitution model to use.
 
78
   * @param rDist The rate across sites distribution to use.
 
79
   * @param checkRooted Tell if we have to check for the tree to be unrooted.
 
80
   * If true, any rooted tree will be unrooted before likelihood computation.
 
81
   * @param verbose Should I display some info?
 
82
   * @param usePatterns Tell if recursive site compression should be performed.
 
83
   * @throw Exception in an error occured.
 
84
   */
 
85
  RHomogeneousMixedTreeLikelihood(
 
86
    const Tree& tree,
 
87
    SubstitutionModel* model,
 
88
    DiscreteDistribution* rDist,
 
89
    bool checkRooted = true,
 
90
    bool verbose = true,
 
91
    bool usePatterns = true)
 
92
  throw (Exception);
 
93
 
 
94
  /**
 
95
   * @brief Build a new RHomogeneousMixedTreeLikelihood object with data.
 
96
   *
 
97
   * This constructor initializes all parameters, data, and likelihood arrays.
 
98
   *
 
99
   * @param tree The tree to use.
 
100
   * @param data Sequences to use.
 
101
   * @param model The mixed substitution model to use.
 
102
   * @param rDist The rate across sites distribution to use.
 
103
   * @param checkRooted Tell if we have to check for the tree to be unrooted.
 
104
   * If true, any rooted tree will be unrooted before likelihood computation.
 
105
   * @param verbose Should I display some info?
 
106
   * @param usePatterns Tell if recursive site compression should be performed.
 
107
   * @throw Exception in an error occured.
 
108
   */
 
109
  RHomogeneousMixedTreeLikelihood(
 
110
    const Tree& tree,
 
111
    const SiteContainer& data,
 
112
    SubstitutionModel* model,
 
113
    DiscreteDistribution* rDist,
 
114
    bool checkRooted = true,
 
115
    bool verbose = true,
 
116
    bool usePatterns = true)
 
117
  throw (Exception);
 
118
 
 
119
  RHomogeneousMixedTreeLikelihood(const RHomogeneousMixedTreeLikelihood& lik);
 
120
 
 
121
  RHomogeneousMixedTreeLikelihood& operator=(const RHomogeneousMixedTreeLikelihood& lik);
 
122
 
 
123
  virtual ~RHomogeneousMixedTreeLikelihood();
 
124
 
 
125
  RHomogeneousMixedTreeLikelihood* clone() const { return new RHomogeneousMixedTreeLikelihood(*this); }
 
126
 
 
127
public:
 
128
  /**
 
129
   * @name The TreeLikelihood interface.
 
130
   *
 
131
   * Other methods are implemented in the RHomogeneousTreeLikelihood class.
 
132
   *
 
133
   * @{
 
134
   */
 
135
  void setData(const SiteContainer& sites) throw (Exception);
 
136
 
 
137
  /** @} */
 
138
 
 
139
 
 
140
  /**
 
141
   * @name The DiscreteRatesAcrossSites interface implementation:
 
142
   *
 
143
   * @{
 
144
   */
 
145
  double getLikelihoodForASiteForARateClass(unsigned int site, unsigned int rateClass) const;
 
146
  double getLogLikelihoodForASiteForARateClass(unsigned int site, unsigned int rateClass) const;
 
147
  double getLikelihoodForASiteForARateClassForAState(unsigned int site, unsigned int rateClass, int state) const;
 
148
  double getLogLikelihoodForASiteForARateClassForAState(unsigned int site, unsigned int rateClass, int state) const;
 
149
  /** @} */
 
150
 
 
151
public:
 
152
  // Specific methods:
 
153
  void initialize() throw (Exception);
 
154
 
 
155
  void fireParameterChanged(const ParameterList& params);
 
156
 
 
157
  void computeTreeLikelihood();
 
158
 
 
159
  virtual double getDLikelihoodForASiteForARateClass(unsigned int site, unsigned int rateClass) const;
 
160
 
 
161
  virtual void computeTreeDLikelihood(const std::string& variable);
 
162
 
 
163
  virtual double getD2LikelihoodForASiteForARateClass(unsigned int site, unsigned int rateClass) const;
 
164
 
 
165
  virtual void computeTreeD2Likelihood(const std::string& variable);
 
166
 
 
167
protected:
 
168
  /**
 
169
   * @brief Compute the likelihood for a subtree defined by the Tree::Node <i>node</i>.
 
170
   *
 
171
   * @param node The root of the subtree.
 
172
   */
 
173
  virtual void computeSubtreeLikelihood(const Node* node); // Recursive method.
 
174
 
 
175
  virtual void computeDownSubtreeDLikelihood(const Node*);
 
176
 
 
177
  virtual void computeDownSubtreeD2Likelihood(const Node*);
 
178
 
 
179
  /**
 
180
   * @brief This method is used by fireParameterChanged method.
 
181
   *
 
182
   */
 
183
  void computeAllTransitionProbabilities();
 
184
  /**
 
185
   * @brief This method is used by fireParameterChanged method.
 
186
   *
 
187
   */
 
188
  void computeTransitionProbabilitiesForNode(const Node* node);
 
189
 
 
190
  /**
 
191
   * @brief This method is mainly for debugging purpose.
 
192
   *
 
193
   * @param node The node at which likelihood values must be displayed.
 
194
   */
 
195
  virtual void displayLikelihood(const Node* node);
 
196
};
 
197
} // end of namespace bpp.
 
198
 
 
199
#endif  // _RHOMOGENEOUSMIXEDTREELIKELIHOOD_H_
 
200