bpp-phyl  2.2.0
DecompositionSubstitutionCount.h
Go to the documentation of this file.
1 //
2 // File: DecompositionSubstitutionCount.h
3 // Created by: Julien Dutheil
4 // Created on: Thu Mar 17 16:08 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 _DECOMPOSITIONSUBSTITUTIONCOUNT_H_
41 #define _DECOMPOSITIONSUBSTITUTIONCOUNT_H_
42 
44 
45 #include <Bpp/Numeric/Matrix/Matrix.h>
46 
47 namespace bpp
48 {
49 
61 {
62  private:
64  size_t nbStates_;
65  mutable RowMatrix<double> jMat_, v_, vInv_;
66  mutable std::vector<double> lambda_;
67  std::vector< RowMatrix<double> > bMatrices_, insideProducts_;
68  mutable std::vector< RowMatrix<double> > counts_;
69  mutable double currentLength_;
70 
71  public:
72  DecompositionSubstitutionCount(const ReversibleSubstitutionModel* model, SubstitutionRegister* reg, const AlphabetIndex2* weights = 0);
73 
77  model_(dsc.model_),
78  nbStates_(dsc.nbStates_),
79  jMat_(dsc.jMat_),
80  v_(dsc.v_),
81  vInv_(dsc.vInv_),
82  lambda_(dsc.lambda_),
85  counts_(dsc.counts_),
87  {}
88 
90  {
93  model_ = dsc.model_;
94  nbStates_ = dsc.nbStates_;
95  jMat_ = dsc.jMat_;
96  v_ = dsc.v_;
97  vInv_ = dsc.vInv_;
98  lambda_ = dsc.lambda_;
99  bMatrices_ = dsc.bMatrices_;
101  counts_ = dsc.counts_;
103  return *this;
104  }
105 
107 
109 
110  public:
111  double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type = 1) const;
112 
113  Matrix<double>* getAllNumbersOfSubstitutions(double length, size_t type = 1) const;
114 
115  std::vector<double> getNumberOfSubstitutionsForEachType(size_t initialState, size_t finalState, double length) const;
116 
122  void setSubstitutionModel(const SubstitutionModel* model);
123 
124  protected:
125  void computeCounts_(double length) const;
126  void jFunction_(const std::vector<double>& lambda, double t, RowMatrix<double>& result) const;
127  void substitutionRegisterHasChanged() throw (Exception);
128  void weightsHaveChanged() throw (Exception);
129 
130  private:
131  void resetStates_();
132  void resetBMatrices_();
133  void initBMatrices_();
134  void fillBMatrices_();
135  void computeEigen_();
136  void computeProducts_();
137 };
138 
139 } //end of namespace bpp.
140 
141 #endif // _DECOMPOSITIONSUBSTITUTIONCOUNT_H_
142 
DecompositionSubstitutionCount * clone() const
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...
Interface for all substitution models.
AbstractSubstitutionCount & operator=(const AbstractSubstitutionCount &asc)
const ReversibleSubstitutionModel * model_
Analytical substitution count using the eigen decomposition method.
Basic implementation of the the SubstitutionCount interface.
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...
The SubstitutionRegister interface.
DecompositionSubstitutionCount & operator=(const DecompositionSubstitutionCount &dsc)
std::vector< RowMatrix< double > > counts_
Interface for reversible substitution models.
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...
DecompositionSubstitutionCount(const DecompositionSubstitutionCount &dsc)
void setSubstitutionModel(const SubstitutionModel *model)
Set the substitution model.
DecompositionSubstitutionCount(const ReversibleSubstitutionModel *model, SubstitutionRegister *reg, const AlphabetIndex2 *weights=0)
AbstractWeightedSubstitutionCount & operator=(const AbstractWeightedSubstitutionCount &index)
std::vector< RowMatrix< double > > insideProducts_
Partial implementation of the WeightedSubstitutionCount interface.
void jFunction_(const std::vector< double > &lambda, double t, RowMatrix< double > &result) const
std::vector< RowMatrix< double > > bMatrices_