bpp-phyl3  3.0.0
SimpleSubstitutionProcess.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_LIKELIHOOD_SIMPLESUBSTITUTIONPROCESS_H
6 #define BPP_PHYL_LIKELIHOOD_SIMPLESUBSTITUTIONPROCESS_H
7 
8 
10 
11 // From the stl:
12 #include <memory>
13 
14 namespace bpp
15 {
21 {
22 protected:
23  std::shared_ptr<BranchModelInterface> model_;
24 
25 public:
27  std::shared_ptr<BranchModelInterface> model,
28  std::shared_ptr<const PhyloTree> tree = nullptr,
29  std::shared_ptr<FrequencySetInterface> rootFrequencies = nullptr);
30 
32  std::shared_ptr<BranchModelInterface> model,
33  std::shared_ptr<ParametrizablePhyloTree> tree,
34  std::shared_ptr<FrequencySetInterface> rootFrequencies = nullptr);
35 
37 
39 
40 public:
41  SimpleSubstitutionProcess* clone() const override { return new SimpleSubstitutionProcess(*this); }
42 
43  const StateMapInterface& stateMap() const override
44  {
45  return model_->stateMap();
46  }
47 
48  std::shared_ptr<const StateMapInterface> getStateMap() const override
49  {
50  return model_->getStateMap();
51  }
52 
53  size_t getNumberOfModels() const override { return 1; }
54 
55  std::vector<size_t> getModelNumbers() const override
56  {
57  return std::vector<size_t>(1, 1);
58  }
59 
60  const BranchModelInterface& model(unsigned int nodeId, size_t classIndex) const override
61  {
62  return *model_;
63  }
64 
65  std::shared_ptr<const BranchModelInterface> getModel(unsigned int nodeId, size_t classIndex) const override
66  {
67  return model_;
68  }
69 
70  const BranchModelInterface& model(size_t n) const override
71  {
72  return *model_;
73  }
74 
75  std::shared_ptr<const BranchModelInterface> getModel(size_t n) const override
76  {
77  return model_;
78  }
79 
80  const std::vector<unsigned int> getNodesWithModel(size_t i) const override
81  {
82  throw Exception("SimpleSubstitutionProcess::getNodesWithModel not finished. Ask developers.");
83  return Vuint(0);
84  }
85 
86  size_t getModelNumberForNode(unsigned int nodeId) const override
87  {
88  return 1;
89  }
90 
91  virtual std::shared_ptr<const BranchModelInterface> getModelForNode(unsigned int nodeId) const override
92  {
93  return model_;
94  }
95 
96  std::shared_ptr<const DiscreteDistributionInterface> getRateDistribution() const override
97  {
98  return nullptr;
99  }
100 
101  std::shared_ptr<DiscreteDistributionInterface> getRateDistribution() override
102  {
103  return nullptr;
104  }
105 
107  {
108  throw NullPointerException("SimpleSubstitutionProcess::rateDistribution. This process does not model a rate distribution.");
109  }
110 
112  {
113  throw NullPointerException("SimpleSubstitutionProcess::rateDistribution. This process does not model a rate distribution.");
114  }
115 
116  ParameterList getSubstitutionModelParameters(bool independent) const override
117  {
118  return independent ? model_->getIndependentParameters() : model_->getParameters();
119  }
120 
121  ParameterList getRateDistributionParameters(bool independent) const override
122  {
123  return ParameterList();
124  }
125 
126  ParameterList getBranchLengthParameters(bool independent) const override
127  {
129  return getParametrizablePhyloTree()->getParameters();
130  else
131  return ParameterList();
132  }
133 
134  const std::vector<double>& getRootFrequencies() const override
135  {
136  if (!hasRootFrequencySet())
137  {
138  if (std::dynamic_pointer_cast<const TransitionModelInterface>(model_))
139  return std::dynamic_pointer_cast<const TransitionModelInterface>(model_)->getFrequencies();
140  else
141  throw Exception("SimpleSubstitutionProcess::getRootFrequencies not possible with a non Transition Model.");
142  }
143  else
144  return getRootFrequencySet()->getFrequencies();
145  }
146 
153  void setModelScenario(std::shared_ptr<ModelScenario> modelpath) override;
154 
155  double getProbabilityForModel(size_t classIndex) const override
156  {
157  if (classIndex != 0)
158  throw IndexOutOfBoundsException("SimpleSubstitutionProcess::getProbabilityForModel.", classIndex, 0, 1);
159  return 1;
160  }
161 
163  {
164  return Vdouble(1, 1);
165  }
166 
167  double getRateForModel(size_t classIndex) const override
168  {
169  if (classIndex != 0)
170  throw IndexOutOfBoundsException("SimpleSubstitutionProcess::getRateForModel.", classIndex, 0, 1);
171  return 1;
172  }
173 
174 protected:
175  void fireParameterChanged(const ParameterList& pl) override; // Forward parameters and updates probabilities if needed.
176 };
177 } // end namespace bpp
178 #endif // BPP_PHYL_LIKELIHOOD_SIMPLESUBSTITUTIONPROCESS_H
A partial implementation of the SubstitutionProcess interface.
std::shared_ptr< const FrequencySetInterface > getRootFrequencySet() const
std::shared_ptr< const ParametrizablePhyloTree > getParametrizablePhyloTree() const
Interface for all Branch models.
Space and time homogeneous substitution process, without mixture.
const StateMapInterface & stateMap() const override
DiscreteDistributionInterface & rateDistribution() override
Get the rate distribution.
std::shared_ptr< BranchModelInterface > model_
const BranchModelInterface & model(unsigned int nodeId, size_t classIndex) const override
Get the substitution model corresponding to a certain branch, site pattern, and model class.
double getProbabilityForModel(size_t classIndex) const override
double getRateForModel(size_t classIndex) const override
const BranchModelInterface & model(size_t n) const override
void fireParameterChanged(const ParameterList &pl) override
AbsractParametrizable interface.
std::vector< size_t > getModelNumbers() const override
SimpleSubstitutionProcess * clone() const override
virtual std::shared_ptr< const BranchModelInterface > getModelForNode(unsigned int nodeId) const override
Get the model associated to a particular node id.
std::shared_ptr< DiscreteDistributionInterface > getRateDistribution() override
Get a pointer to the rate distribution (or null if there is no rate distribution).
const DiscreteDistributionInterface & rateDistribution() const override
Get the rate distribution.
void setModelScenario(std::shared_ptr< ModelScenario > modelpath) override
Set the modelPath, after checking it is valid (ie modelpath has only the model of the process).
ParameterList getBranchLengthParameters(bool independent) const override
size_t getModelNumberForNode(unsigned int nodeId) const override
Get the number of the model associated to a particular node id.
SimpleSubstitutionProcess & operator=(const SimpleSubstitutionProcess &ssp)
std::shared_ptr< const BranchModelInterface > getModel(size_t n) const override
const std::vector< unsigned int > getNodesWithModel(size_t i) const override
Get a list of nodes id for which the given model is associated.
Vdouble getClassProbabilities() const override
const std::vector< double > & getRootFrequencies() const override
Get the values of the frequencies for each state in the alphabet at the root node.
SimpleSubstitutionProcess(std::shared_ptr< BranchModelInterface > model, std::shared_ptr< const PhyloTree > tree=nullptr, std::shared_ptr< FrequencySetInterface > rootFrequencies=nullptr)
ParameterList getRateDistributionParameters(bool independent) const override
size_t getNumberOfModels() const override
std::shared_ptr< const DiscreteDistributionInterface > getRateDistribution() const override
Get a pointer to the rate distribution (or null if there is no rate distribution).
std::shared_ptr< const BranchModelInterface > getModel(unsigned int nodeId, size_t classIndex) const override
Get the substitution model corresponding to a certain branch, site pattern, and model class.
ParameterList getSubstitutionModelParameters(bool independent) const override
Methods to retrieve the parameters of specific objects.
std::shared_ptr< const StateMapInterface > getStateMap() const override
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:25
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< unsigned int > Vuint