bpp-phyl3  3.0.0
OneChangeRegisterTransitionModel.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_MODEL_ONECHANGEREGISTERTRANSITIONMODEL_H
6 #define BPP_PHYL_MODEL_ONECHANGEREGISTERTRANSITIONMODEL_H
7 
8 
9 #include "../Mapping/SubstitutionRegister.h"
12 
13 namespace bpp
14 {
26 {
27 private:
33 
38  std::unique_ptr<AnonymousSubstitutionModel> modelChanged_;
39 
43  std::string registerName_;
44 
48  std::vector<size_t> vNumRegs_;
49 
50 public:
51  /*
52  * @brief Constructor
53  *
54  * @param originalModel the substitution model used
55  * @param reg the register in which the considered type of event is
56  * defined.
57  * @param numReg the number of the considered event in the
58  * register.
59  */
61  std::unique_ptr<SubstitutionModelInterface> originalModel,
62  const SubstitutionRegisterInterface& reg, size_t numReg);
63 
74  std::unique_ptr<SubstitutionModelInterface> originalModel,
76  std::vector<size_t> vNumRegs);
77 
86  vNumRegs_(fmsm.vNumRegs_)
87  {}
88 
89 
91  {
96  modelChanged_ = std::unique_ptr<AnonymousSubstitutionModel>(fmsm.modelChanged_->clone());
98  vNumRegs_ = fmsm.vNumRegs_;
99 
100  return *this;
101  }
102 
104 
106  {
107  return new OneChangeRegisterTransitionModel(*this);
108  }
109 
110 public:
111  void fireParameterChanged(const ParameterList& parameters) override
112  {
114  updateMatrices_();
115  }
116 
117  double Pij_t (size_t i, size_t j, double t) const override;
118  double dPij_dt (size_t i, size_t j, double t) const override;
119  double d2Pij_dt2(size_t i, size_t j, double t) const override;
120 
121  const Matrix<double>& getPij_t(double t) const override;
122 
123  const Matrix<double>& getdPij_dt(double t) const override;
124 
125  const Matrix<double>& getd2Pij_dt2(double t) const override;
126 
127  double freq(size_t i) const override
128  {
129  return transitionModel().freq(i);
130  }
131 
132  const Vdouble& getFrequencies() const override
133  {
134  return transitionModel().getFrequencies();
135  }
136 
137  const FrequencySetInterface& frequencySet() const override
138  {
139  return transitionModel().frequencySet();
140  }
141 
142  void setFreqFromData(const SequenceDataInterface& data, double pseudoCount) override
143  {
144  transitionModel_().setFreqFromData(data, pseudoCount);
145  }
146 
147  virtual void setFreq(std::map<int, double>& m) override
148  {
150  }
151 
152  double getRate() const override { return transitionModel().getRate(); }
153 
154  void setRate(double rate) override { return transitionModel_().setRate(rate); }
155 
156  double getInitValue(size_t i, int state) const override
157  {
158  return model().getInitValue(i, state);
159  }
160 
161  std::string getName() const override
162  {
163  return "OneChange";
164  }
165 
166  const std::string& getRegisterName() const
167  {
168  return registerName_;
169  }
170 
171  const std::vector<size_t>& getRegisterNumbers() const
172  {
173  return vNumRegs_;
174  }
175 
176  /*
177  * @}
178  */
179 
180 protected:
181  void updateMatrices_();
182 };
183 } // end of namespace bpp.
184 #endif // BPP_PHYL_MODEL_ONECHANGEREGISTERTRANSITIONMODEL_H
Virtual class of a Transition Model related to a given SubstitutionModel.
const TransitionModelInterface & transitionModel() const override
virtual void fireParameterChanged(const ParameterList &parameters) override
AbstractFromSubstitutionModelTransitionModel & operator=(const AbstractFromSubstitutionModelTransitionModel &fmsm)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
Abstract class of Wrapping model class, where all methods are redirected from model().
virtual const FrequencySetInterface & frequencySet() const =0
virtual void setRate(double rate)=0
Set the rate of the model (must be positive).
virtual double getRate() const =0
Get the rate.
virtual double getInitValue(size_t i, int state) const =0
Parametrize a set of state frequencies.
Definition: FrequencySet.h:29
From a model, compute transition probabilities given there is at least a change of a category (ie a n...
double Pij_t(size_t i, size_t j, double t) const override
const Matrix< double > & getd2Pij_dt2(double t) const override
std::unique_ptr< AnonymousSubstitutionModel > modelChanged_
const Matrix< double > & getPij_t(double t) const override
OneChangeRegisterTransitionModel(std::unique_ptr< SubstitutionModelInterface > originalModel, const SubstitutionRegisterInterface &reg, size_t numReg)
OneChangeRegisterTransitionModel * clone() const override
const Matrix< double > & getdPij_dt(double t) const override
virtual void setFreq(std::map< int, double > &m) override
Set equilibrium frequencies.
double getInitValue(size_t i, int state) const override
double getRate() const override
Get the rate.
void setRate(double rate) override
Set the rate of the model (must be positive).
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount) override
Set equilibrium frequencies equal to the frequencies estimated from the data.
void fireParameterChanged(const ParameterList &parameters) override
const FrequencySetInterface & frequencySet() const override
const std::vector< size_t > & getRegisterNumbers() const
double d2Pij_dt2(size_t i, size_t j, double t) const override
double dPij_dt(size_t i, size_t j, double t) const override
std::string getName() const override
Get the name of the model.
OneChangeRegisterTransitionModel & operator=(const OneChangeRegisterTransitionModel &fmsm)
OneChangeRegisterTransitionModel(const OneChangeRegisterTransitionModel &fmsm)
The SubstitutionRegister interface.
virtual double freq(size_t i) const =0
virtual const Vdouble & getFrequencies() const =0
virtual void setFreq(std::map< int, double > &frequencies)=0
Set equilibrium frequencies.
virtual void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0)=0
Set equilibrium frequencies equal to the frequencies estimated from the data.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble