bpp-phyl3 3.0.0
AbstractBiblioSubstitutionModel.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
6
7using namespace bpp;
8using namespace std;
9
10AbstractBiblioTransitionModel::AbstractBiblioTransitionModel(const std::string& prefix) :
11 // AbstractParameterAliasable(prefix),
12 mapParNamesFromPmodel_(),
13 lParPmodel_()
14{}
15
16/******************************************************************************/
17
19 // AbstractParameterAliasable(model),
20 mapParNamesFromPmodel_(model.mapParNamesFromPmodel_),
21 lParPmodel_(model.lParPmodel_)
22{}
23
24/******************************************************************************/
25
27{
29 mapParNamesFromPmodel_ = model.mapParNamesFromPmodel_;
30 lParPmodel_ = model.lParPmodel_;
31 return *this;
32}
33
34
35/******************************************************************************/
36
37std::string AbstractBiblioTransitionModel::getParNameFromPmodel(const std::string& name) const
38{
39 auto it = mapParNamesFromPmodel_.find(name);
40 if (it == mapParNamesFromPmodel_.end())
41 throw Exception("AbstractBiblioTransitionModel::getParNameFromPmodel : unknown parameter " + name);
42 return it->second;
43}
44
45/******************************************************************************/
46
47std::string AbstractBiblioTransitionModel::getPmodelParName(const std::string& name) const
48{
49 for (auto it : mapParNamesFromPmodel_)
50 {
51 if (it.second == name)
52 return it.first;
53 }
54
55 throw Exception("AbstractBiblioTransitionModel::getPmodelParName: unknown parameter name " + name);
56}
57
58
59/******************************************************************************/
60
62{
63 for (size_t i = 0; i < lParPmodel_.size(); ++i)
64 {
65 if (mapParNamesFromPmodel_.find(lParPmodel_[i].getName()) != mapParNamesFromPmodel_.end())
66 {
68 }
69 }
70
72}
73
74/******************************************************************************/
75
77{
80
81 mapParNamesFromPmodel_[getNamespace() + "rate"] = "rate";
84}
85
86/******************************************************************************/
87
89{
91
92 map<string, string> mapParNamesFromPmodel_new;
93
94 for (const auto& it : mapParNamesFromPmodel_)
95 {
96 mapParNamesFromPmodel_new[name + model().getParameterNameWithoutNamespace(it.first)] = it.second;
97 }
98
100 mapParNamesFromPmodel_ = mapParNamesFromPmodel_new;
101
102 model_().setNamespace(name);
103
106}
107
108
109/******************************************************************************/
110
111void AbstractBiblioTransitionModel::setFreq(std::map<int, double>& frequ)
112{
114
115 ParameterList pl;
116 for (const auto& it : mapParNamesFromPmodel_)
117 {
119 }
120
122}
123
124
126 const SequenceDataInterface& data, double pseudoCount)
127{
128 map<int, double> freqs;
129 SequenceContainerTools::getFrequencies(data, freqs, pseudoCount);
130 setFreq(freqs);
131}
Partial implementation of the SubstitutionModel interface for models that are set for matching the bi...
std::map< std::string, std::string > mapParNamesFromPmodel_
Tools to make the link between the Parameters of the object and those of pmixmodel_.
void setFreq(std::map< int, double > &frequ) override
Set equilibrium frequencies.
std::string getPmodelParName(const std::string &name) const
get the name of a parameter in the submodel from its apparent name
void addRateParameter() override
Methods to supersede TransitionModel methods.
AbstractBiblioTransitionModel & operator=(const AbstractBiblioTransitionModel &model)
void setNamespace(const std::string &name) override
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0) override
Set equilibrium frequencies equal to the frequencies estimated from the data.
std::string getParNameFromPmodel(const std::string &name) const
get the name of a parameter from its name in a submodel
void addParameter_(Parameter *parameter)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
void setNamespace(const std::string &prefix)
const Parameter & parameter(const std::string &name) const override
bool matchParametersValues(const ParameterList &parameters) override
std::string getNamespace() const override
std::string getParameterNameWithoutNamespace(const std::string &name) const override
const ParameterList & getParameters() const override
double getParameterValue(const std::string &name) const override
double getRate() const override
Get the rate.
void setFreq(std::map< int, double > &frequencies) override
Set equilibrium frequencies.
virtual std::string getName() const override
Get the name of the model.
const BranchModelInterface & model() const override
virtual void addRateParameter()=0
virtual void addParameters(const ParameterList &params)
size_t size() const
virtual void addParameter(const Parameter &param)
virtual void reset()
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
virtual std::string getParameterNameWithoutNamespace(const std::string &name) const=0
virtual bool matchParametersValues(const ParameterList &parameters)=0
virtual void setNamespace(const std::string &prefix)=0
static void getFrequencies(const SequenceContainerInterface &sc, std::map< int, double > &f, double pseudoCount=0)
Defines the basic types of data flow nodes.