bpp-phyl3  3.0.0
OneJumpSubstitutionCount.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_ONEJUMPSUBSTITUTIONCOUNT_H
6 #define BPP_PHYL_MAPPING_ONEJUMPSUBSTITUTIONCOUNT_H
7 
8 
9 #include "../Model/SubstitutionModel.h"
10 #include "SubstitutionCount.h"
11 
12 namespace bpp
13 {
26 {
27 private:
28  std::shared_ptr<const SubstitutionModelInterface> model_;
30 
31 public:
32  OneJumpSubstitutionCount(std::shared_ptr<const SubstitutionModelInterface> model) :
33  AbstractSubstitutionCount(std::make_shared<const TotalSubstitutionRegister>(model->getStateMap())),
34  model_(model), tmp_() {}
35 
36  OneJumpSubstitutionCount(std::shared_ptr<const StateMapInterface> statemap) :
37  AbstractSubstitutionCount(std::make_shared<const TotalSubstitutionRegister>(statemap)),
38  model_(nullptr), tmp_() {}
39 
42  model_(ojsc.model_), tmp_(ojsc.tmp_) {}
43 
45  {
46  AbstractSubstitutionCount::operator=(ojsc);
47  model_ = ojsc.model_;
48  tmp_ = ojsc.tmp_;
49  return *this;
50  }
51 
53 
54  virtual OneJumpSubstitutionCount* clone() const override { return new OneJumpSubstitutionCount(*this); }
55 
56 public:
57  double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type = 1) const override
58  {
59  if (!model_)
60  throw Exception("OneJumpSubstitutionCount::getNumberOfSubstitutions: model not defined.");
61 
62  if (finalState != initialState) return 1.;
63  else return 1. - model_->Pij_t(initialState, finalState, length);
64  }
65 
66  std::unique_ptr< Matrix<double>> getAllNumbersOfSubstitutions(double length, size_t type = 1) const override;
67 
68  void storeAllNumbersOfSubstitutions(double length, size_t type, Eigen::MatrixXd& mat) const override;
69 
70  std::vector<double> getNumberOfSubstitutionsPerType(size_t initialState, size_t finalState, double length) const override
71  {
72  std::vector<double> v(0);
73  v[0] = getNumberOfSubstitutions(initialState, finalState, length, 0);
74  return v;
75  }
76 
77  void setSubstitutionModel(std::shared_ptr<const SubstitutionModelInterface> model) override { model_ = model; }
78 
79  /*
80  *@param reg pointer to a SubstitutionRegister
81  *
82  */
83  void setSubstitutionRegister(std::shared_ptr<const SubstitutionRegisterInterface> reg) override
84  {
85  throw Exception("OneJumpSubstitutionCount::setSubstitutionRegister. This SubstitutionsCount only works with a TotalSubstitutionRegister.");
86  }
87 
88 private:
89  void substitutionRegisterHasChanged() override {}
90 };
91 } // end of namespace bpp.
92 #endif // BPP_PHYL_MAPPING_ONEJUMPSUBSTITUTIONCOUNT_H
Partial implementation of the SubstitutionCount interface.
Computes the probability that at least one jump occurred on a branch, given the initial and final sta...
OneJumpSubstitutionCount(const OneJumpSubstitutionCount &ojsc)
void setSubstitutionRegister(std::shared_ptr< const SubstitutionRegisterInterface > reg) override
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...
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,...
OneJumpSubstitutionCount(std::shared_ptr< const SubstitutionModelInterface > model)
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...
virtual OneJumpSubstitutionCount * clone() const override
std::shared_ptr< const SubstitutionModelInterface > model_
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.
OneJumpSubstitutionCount & operator=(const OneJumpSubstitutionCount &ojsc)
OneJumpSubstitutionCount(std::shared_ptr< const StateMapInterface > statemap)
Defines the basic types of data flow nodes.