bpp-phyl  2.2.0
DecompositionReward.h
Go to the documentation of this file.
1 //
2 // File: DecompositionReward.h
3 // Created by: Laurent Guéguen
4 // Created on: mercredi 27 mars 2013, à 12h 29
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 _DECOMPOSITIONREWARD_H_
41 #define _DECOMPOSITIONREWARD_H_
42 
43 #include "Reward.h"
44 
45 #include <Bpp/Numeric/Matrix/Matrix.h>
46 
47 namespace bpp
48 {
49 
66  public AbstractReward
67 {
68 private:
70  size_t nbStates_;
71  mutable RowMatrix<double> jMat_, v_, vInv_;
72  mutable std::vector<double> lambda_;
73  RowMatrix<double> bMatrice_, insideProduct_;
74  mutable RowMatrix<double> rewards_;
75  mutable double currentLength_;
76 
77 public:
78  DecompositionReward(const SubstitutionModel* model, AlphabetIndex1* alphIndex);
79 
81  AbstractReward(dr),
82  model_(dr.model_),
83  nbStates_(dr.nbStates_),
84  jMat_(dr.jMat_),
85  v_(dr.v_),
86  vInv_(dr.vInv_),
87  lambda_(dr.lambda_),
88  bMatrice_(dr.bMatrice_),
90  rewards_(dr.rewards_),
92  {}
93 
95  {
97  model_ = dr.model_;
98  nbStates_ = dr.nbStates_;
99  jMat_ = dr.jMat_;
100  v_ = dr.v_;
101  vInv_ = dr.vInv_;
102  lambda_ = dr.lambda_;
103  bMatrice_ = dr.bMatrice_;
105  rewards_ = dr.rewards_;
107  return *this;
108  }
109 
110  virtual ~DecompositionReward() {}
111 
112  DecompositionReward* clone() const { return new DecompositionReward(*this); }
113 
114 public:
115  double getReward(size_t initialState, size_t finalState, double length) const;
116 
117  Matrix<double>* getAllRewards(double length) const;
118 
127  void setSubstitutionModel(const SubstitutionModel* model);
128 
129 protected:
130  void computeRewards_(double length) const;
131  void jFunction_(const std::vector<double>& lambda, double t, RowMatrix<double>& result) const;
132  void alphabetIndexHasChanged() throw (Exception);
133 
134 private:
135  void resetStates_();
136  void computeBMatrice_();
137  void computeEigen_();
138  void computeProducts_();
139 };
140 
141 } //end of namespace bpp.
142 
143 #endif // _DECOMPOSITIONREWARD_H_
144 
RowMatrix< double > bMatrice_
RowMatrix< double > jMat_
Interface for all substitution models.
RowMatrix< double > rewards_
DecompositionReward & operator=(const DecompositionReward &dr)
AbstractReward & operator=(const AbstractReward &ar)
Definition: Reward.h:166
Analytical reward using the eigen decomposition method.
Basic implementation of the the Reward interface.
Definition: Reward.h:151
DecompositionReward(const SubstitutionModel *model, AlphabetIndex1 *alphIndex)
Interface for reversible substitution models.
double getReward(size_t initialState, size_t finalState, double length) const
Get the reward of susbstitutions on a branch, given the initial and final states, and the branch leng...
const ReversibleSubstitutionModel * model_
void computeRewards_(double length) const
RowMatrix< double > insideProduct_
DecompositionReward(const DecompositionReward &dr)
void jFunction_(const std::vector< double > &lambda, double t, RowMatrix< double > &result) const
std::vector< double > lambda_
DecompositionReward * clone() const
Matrix< double > * getAllRewards(double length) const
Get the rewards on a branch, for each initial and final states, and given the branch length...
void setSubstitutionModel(const SubstitutionModel *model)
Set the substitution model.
RowMatrix< double > vInv_