bpp-phyl3  3.0.0
TransitionFromTransitionModel.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_TRANSITIONFROMTRANSITIONMODEL_H
6 #define BPP_PHYL_MODEL_TRANSITIONFROMTRANSITIONMODEL_H
7 
8 
9 #include "AbstractWrappedModel.h"
10 
11 namespace bpp
12 {
23 {
24 private:
28  std::shared_ptr<TransitionModelInterface> subModel_;
29 
33  size_t size_;
34 
41  mutable double tref_;
42 
50  mutable const Matrix<double>* Pij_t, * dPij_dt, * d2Pij_dt2;
51 
55  mutable Eigen::VectorXd Pi_, dPi_, d2Pi_;
56 
57 public:
58  TransitionFromTransitionModel(std::shared_ptr<TransitionModelInterface> originalModel) :
59  AbstractParameterAliasable("TransitionFrom." + originalModel->getNamespace()),
60  AbstractWrappedModel("TransitionFrom." + originalModel->getNamespace()),
61  subModel_(originalModel),
62  size_(originalModel->getNumberOfStates()),
63  tref_(-1), Pij_t(0), dPij_dt(0), d2Pij_dt2(0), Pi_(size_), dPi_(size_), d2Pi_(size_)
64  {
65  subModel_->setNamespace(getNamespace());
66  addParameters_(subModel_->getParameters());
67  }
68 
72  subModel_(fmsm.subModel_->clone()),
73  size_(fmsm.size_),
74  tref_(-1), Pij_t(0), dPij_dt(0), d2Pij_dt2(0), Pi_(size_), dPi_(size_), d2Pi_(size_)
75  {}
76 
78  {
80 
81  subModel_ = std::shared_ptr<TransitionModelInterface>(fmsm.subModel_->clone());
82  size_ = fmsm.size_;
83  Pi_.resize(Eigen::Index(size_));
84  dPi_.resize(Eigen::Index(size_));
85  d2Pi_.resize(Eigen::Index(size_));
86 
87  tref_ = -1;
88 
89  return *this;
90  }
91 
93 
94  TransitionFromTransitionModel* clone() const override { return new TransitionFromTransitionModel(*this); }
95 
96 public:
97  void fireParameterChanged(const ParameterList& parameters) override
98  {
100  if (model_().matchParametersValues(parameters))
101  tref_ = -1;
102  }
103 
104  const BranchModelInterface& model() const override
105  {
106  return *subModel_;
107  }
108 
110  {
111  return *subModel_;
112  }
113 
114  const Eigen::VectorXd& Lik_t (const Eigen::VectorXd& from, double t) const override;
115  const Eigen::VectorXd& dLik_dt (const Eigen::VectorXd& from, double t) const override;
116  const Eigen::VectorXd& d2Lik_dt2(const Eigen::VectorXd& from, double t) const override;
117 
118  void setFreqFromData(const SequenceDataInterface& data, double pseudoCount)
119  {
120  transitionModel_().setFreqFromData(data, pseudoCount);
121  }
122 
123  virtual void setFreq(std::map<int, double>& m)
124  {
126  }
127 
128  double getRate() const override { return transitionModel().getRate(); }
129 
130  void setRate(double rate) override { return transitionModel_().setRate(rate); }
131 
132  double getInitValue(size_t i, int state) const override
133  {
134  return transitionModel().getInitValue(i, state);
135  }
136 
137  std::string getName() const override
138  {
139  return "TransitionFrom";
140  }
141 
142  void addRateParameter() override
143  {
146  }
147 
148 protected:
150  {
151  return *subModel_;
152  }
153 
155  {
156  return *subModel_;
157  }
158 };
159 } // end of namespace bpp.
160 #endif // BPP_PHYL_MODEL_TRANSITIONFROMTRANSITIONMODEL_H
void addParameters_(const ParameterList &parameters)
void addParameter_(Parameter *parameter)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
virtual void fireParameterChanged(const ParameterList &parameters)
bool matchParametersValues(const ParameterList &parameters) override
std::string getNamespace() const override
Abstract class of Wrapping model class, where all methods are redirected from model().
size_t getNumberOfStates() const override
Get the number of states.
Interface for all Branch models.
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
virtual void addRateParameter()=0
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
From a transition model, compute the transition function probabilities.
double tref_
Reference time to avoid recomuputation of transition matrix when time has not changed....
const TransitionModelInterface & transitionModel() const
double getInitValue(size_t i, int state) const override
const Eigen::VectorXd & d2Lik_dt2(const Eigen::VectorXd &from, double t) const override
std::string getName() const override
Get the name of the model.
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount)
TransitionFromTransitionModel(const TransitionFromTransitionModel &fmsm)
const Eigen::VectorXd & dLik_dt(const Eigen::VectorXd &from, double t) const override
double getRate() const override
Get the rate.
TransitionFromTransitionModel(std::shared_ptr< TransitionModelInterface > originalModel)
const BranchModelInterface & model() const override
TransitionFromTransitionModel & operator=(const TransitionFromTransitionModel &fmsm)
const Matrix< double > * Pij_t
Transition Matrices owned by the submodel.
Eigen::VectorXd Pi_
Used return vectors.
TransitionFromTransitionModel * clone() const override
const Eigen::VectorXd & Lik_t(const Eigen::VectorXd &from, double t) const override
void fireParameterChanged(const ParameterList &parameters) override
std::shared_ptr< TransitionModelInterface > subModel_
The related model.
void setRate(double rate) override
Set the rate of the model (must be positive).
virtual void setFreq(std::map< int, double > &m)
Interface for all transition models.
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.