bpp-phyl3  3.0.0
LaplaceSubstitutionCount.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_PHYL_MAPPING_LAPLACESUBSTITUTIONCOUNT_H
6 #define BPP_PHYL_MAPPING_LAPLACESUBSTITUTIONCOUNT_H
7 
8 
9 #include "../Model/SubstitutionModel.h"
10 #include "SubstitutionCount.h"
11 
12 namespace bpp
13 {
28 {
29 private:
30  std::shared_ptr<const SubstitutionModelInterface> model_;
31  size_t cutOff_;
32  mutable double currentLength_;
34 
35 public:
37  std::shared_ptr<const SubstitutionModelInterface> model,
38  size_t cutOff) :
39  AbstractSubstitutionCount(std::make_shared<TotalSubstitutionRegister>(model->getStateMap())),
40  model_ (model),
41  cutOff_ (cutOff),
42  currentLength_(0),
43  m_ (model->getNumberOfStates(), model->getNumberOfStates())
44  {}
45 
46  LaplaceSubstitutionCount(std::shared_ptr<const StateMapInterface> stateMap, size_t cutOff) :
47  AbstractSubstitutionCount(std::make_shared<TotalSubstitutionRegister>(stateMap)),
48  model_ (0),
49  cutOff_ (cutOff),
50  currentLength_(0),
51  m_ (stateMap->getNumberOfModelStates(), stateMap->getNumberOfModelStates())
52  {}
53 
56  model_ (asc.model_),
57  cutOff_ (asc.cutOff_),
59  m_ (asc.m_)
60  {}
61 
63  {
64  AbstractSubstitutionCount::operator=(asc);
65  model_ = asc.model_;
66  cutOff_ = asc.cutOff_;
68  m_ = asc.m_;
69  return *this;
70  }
71 
73 
74  LaplaceSubstitutionCount* clone() const override { return new LaplaceSubstitutionCount(*this); }
75 
76 public:
77  double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type = 1) const override;
78 
79  std::unique_ptr< Matrix<double>> getAllNumbersOfSubstitutions(double length, size_t type = 1) const override;
80 
81  void storeAllNumbersOfSubstitutions(double length, size_t type, Eigen::MatrixXd& mat) const override;
82 
83  std::vector<double> getNumberOfSubstitutionsPerType(size_t initialState, size_t finalState, double length) const override
84  {
85  std::vector<double> v(0);
86  v[0] = getNumberOfSubstitutions(initialState, finalState, length, 0);
87  return v;
88  }
89 
90  void setSubstitutionModel(std::shared_ptr<const SubstitutionModelInterface> model) override;
91 
92  /*
93  *@param reg pointer to a SubstitutionRegister
94  *
95  */
96  void setSubstitutionRegister(std::shared_ptr<const SubstitutionRegisterInterface> reg) override
97  {
98  throw Exception("LaplaceSubstitutionCount::setSubstitutionRegister. This SubstitutionsCount only works with a TotalSubstitutionRegister.");
99  }
100 
101 protected:
102  void computeCounts(double length) const;
104 };
105 } // end of namespace bpp.
106 #endif // BPP_PHYL_MAPPING_LAPLACESUBSTITUTIONCOUNT_H
Partial implementation of the SubstitutionCount interface.
Laplace estimate of the substitution count.
std::shared_ptr< const SubstitutionModelInterface > model_
std::vector< double > getNumberOfSubstitutionsPerType(size_t initialState, size_t finalState, double length) const override
Get the numbers of susbstitutions on a branch for all types, for an initial and final states,...
void setSubstitutionRegister(std::shared_ptr< const SubstitutionRegisterInterface > reg) override
void storeAllNumbersOfSubstitutions(double length, size_t type, Eigen::MatrixXd &mat) const override
Stores the numbers of susbstitutions on a branch, for each initial and final states,...
void setSubstitutionModel(std::shared_ptr< const SubstitutionModelInterface > model) override
Set the substitution model associated with this count, if relevant.
void computeCounts(double length) const
double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type=1) const override
Get the number of susbstitutions on a branch, given the initial and final states, and the branch leng...
LaplaceSubstitutionCount(const LaplaceSubstitutionCount &asc)
std::unique_ptr< Matrix< double > > getAllNumbersOfSubstitutions(double length, size_t type=1) const override
Get the numbers of susbstitutions on a branch, for each initial and final states, and given the branc...
LaplaceSubstitutionCount & operator=(const LaplaceSubstitutionCount &asc)
LaplaceSubstitutionCount(std::shared_ptr< const StateMapInterface > stateMap, size_t cutOff)
LaplaceSubstitutionCount(std::shared_ptr< const SubstitutionModelInterface > model, size_t cutOff)
LaplaceSubstitutionCount * clone() const override
virtual size_t getNumberOfStates() const
Short cut function, equivalent to getSubstitutionRegister()->getAlphabet()->getSize().
Defines the basic types of data flow nodes.