bpp-phyl  2.2.0
UniformizationSubstitutionCount.h
Go to the documentation of this file.
1 //
2 // File: UniformizationSubstitutionCount.h
3 // Created by: Julien Dutheil
4 // Created on: Sat Mar 19 13:54 2011
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 16, 2004, 2005, 2006)
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 _UNIFORMIZATIONSUBSTITUTIONCOUNT_H_
41 #define _UNIFORMIZATIONSUBSTITUTIONCOUNT_H_
42 
44 
45 #include <Bpp/Numeric/Matrix/Matrix.h>
46 
47 namespace bpp
48 {
49 
60 {
61  private:
63  size_t nbStates_;
64  std::vector< RowMatrix<double> > bMatrices_;
65  mutable std::vector< RowMatrix<double> > power_;
66  mutable std::vector < std::vector< RowMatrix<double> > > s_;
67  double miu_;
68  mutable std::vector< RowMatrix<double> > counts_;
69  mutable double currentLength_;
70 
71  public:
72  UniformizationSubstitutionCount(const SubstitutionModel* model, SubstitutionRegister* reg, const AlphabetIndex2* weights = 0);
73 
77  model_(usc.model_),
78  nbStates_(usc.nbStates_),
80  power_(usc.power_),
81  s_(usc.s_),
82  miu_(usc.miu_),
83  counts_(usc.counts_),
85  {}
86 
88  {
91  model_ = usc.model_;
92  nbStates_ = usc.nbStates_;
93  bMatrices_ = usc.bMatrices_;
94  power_ = usc.power_;
95  s_ = usc.s_;
96  miu_ = usc.miu_;
97  counts_ = usc.counts_;
99  return *this;
100  }
101 
103 
105 
106 public:
107  double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type = 1) const;
108 
109  Matrix<double>* getAllNumbersOfSubstitutions(double length, size_t type = 1) const;
110 
111  std::vector<double> getNumberOfSubstitutionsForEachType(size_t initialState, size_t finalState, double length) const;
112 
113  void setSubstitutionModel(const SubstitutionModel* model);
114 
115  protected:
116  void computeCounts_(double length) const;
117  void substitutionRegisterHasChanged() throw (Exception);
118  void weightsHaveChanged() throw (Exception);
119 
120  private:
121  void resetBMatrices_();
122  void initBMatrices_();
123  void fillBMatrices_();
124 
125 };
126 
127 } //end of namespace bpp.
128 
129 #endif // _UNIFORMIZATIONSUBSTITUTIONCOUNT_H_
130 
std::vector< std::vector< RowMatrix< double > > > s_
Interface for all substitution models.
AbstractSubstitutionCount & operator=(const AbstractSubstitutionCount &asc)
UniformizationSubstitutionCount & operator=(const UniformizationSubstitutionCount &usc)
Basic implementation of the the SubstitutionCount interface.
std::vector< RowMatrix< double > > counts_
The SubstitutionRegister interface.
Matrix< double > * getAllNumbersOfSubstitutions(double length, size_t type=1) const
Get the numbers of susbstitutions on a branch, for each initial and final states, and given the branc...
UniformizationSubstitutionCount(const SubstitutionModel *model, SubstitutionRegister *reg, const AlphabetIndex2 *weights=0)
std::vector< RowMatrix< double > > bMatrices_
UniformizationSubstitutionCount * clone() const
UniformizationSubstitutionCount(const UniformizationSubstitutionCount &usc)
std::vector< double > getNumberOfSubstitutionsForEachType(size_t initialState, size_t finalState, double length) const
Get the numbers of susbstitutions on a branch for all types, for an initial and final states...
Analytical (weighted) substitution count using the uniformization method.
double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type=1) const
Get the number of susbstitutions on a branch, given the initial and final states, and the branch leng...
AbstractWeightedSubstitutionCount & operator=(const AbstractWeightedSubstitutionCount &index)
void setSubstitutionModel(const SubstitutionModel *model)
Set the substitution model associated with this count, if relevent.
Partial implementation of the WeightedSubstitutionCount interface.