bpp-phyl3 3.0.0
MixedSubstitutionModelSet.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_LEGACY_MODEL_MIXEDSUBSTITUTIONMODELSET_H
6#define BPP_PHYL_LEGACY_MODEL_MIXEDSUBSTITUTIONMODELSET_H
7
8#include <Bpp/Exceptions.h>
10
11#include "../../Model/AbstractSubstitutionModel.h"
13
14// From the STL:
15#include <memory>
16
17namespace bpp
18{
87 public std::enable_shared_from_this<MixedSubstitutionModelSet>
88{
89public:
91 {
92public:
93 class Node
94 {
100
101public:
102 Node() : vNumb_() {}
103 Node(const Node& n) : vNumb_(n.vNumb_){}
104 Node& operator=(const Node& n)
105 {
106 vNumb_ = n.vNumb_;
107 return *this;
108 }
109
110 virtual ~Node(){}
111
113 {
114 vNumb_ = n;
115 return *this;
116 }
117
118 void insertN(const Vuint& vn);
119
120 size_t size() const
121 {
122 return vNumb_.size();
123 }
124
128 Node& operator+=(const Node&);
129
133 bool operator<=(const Node&) const;
134
138 bool operator>=(const Node&) const;
139
143 bool intersects(const Node&) const;
144
145 uint operator[](size_t i) const { return vNumb_[i]; }
146 };
147
148private:
149 std::vector<Node> vNumbers_;
150
155
159 double proba_;
160
161public:
162 HyperNode(std::shared_ptr<const MixedSubstitutionModelSet> );
163 HyperNode(const HyperNode&);
166
175 void setModel(size_t nM, const Vuint& vnS);
176
185 void addToModel(size_t nM, const Vuint& vnS);
191
196 bool operator<=(const HyperNode&) const;
197
202 bool isComplete() const;
207 bool operator>=(const HyperNode&) const;
208
213 bool intersects(const HyperNode&) const;
214
219 double getProbability() const {return proba_; }
220
225 void setProbability(double x) { proba_ = x; }
226
227 const Node& getNode(size_t i) const { return vNumbers_[i]; }
228 };
229
230private:
231 std::vector<HyperNode*> vpHyperNodes_;
232
233public:
239 MixedSubstitutionModelSet(std::shared_ptr<const Alphabet> alpha) :
241 vpHyperNodes_() {}
242
244
246
248
250
252
257 void clear();
258
259 /*
260 *@brief adds a new empty HyperNode to the end of the HyperNodes
261 * list.
262 */
263
264 void addEmptyHyperNode();
265
266 /*
267 *@brief adds the copy of an HyperNode to the end of the
268 * HyperNodes list.
269 */
270
271 void addHyperNode(const HyperNode& hn);
272
273 /*
274 *@brief If necessary, adds a new HyperNode such that all
275 * submodels of the mixture models are at least in an
276 * HyperNode.
277 *
278 * Returns true iff a new path has been built.
279 *
280 */
281
282 bool complete();
283
284 /*
285 *@brief adds a submodel number to the nMth mixed model of the
286 * nHth HyperNode of the list (default nH=0). Checks if all the
287 * numbers are valid.
288 *
289 *@param nM number of the mixed model
290 *@param vnS number of the submodel
291 *@param nH number of the concerned HyperNode (default the last element of
292 * the list)
293 */
294
295 void addToHyperNode(size_t nM, const Vuint& vnS, int nH = -1);
296
297 size_t getNumberOfHyperNodes() const { return vpHyperNodes_.size(); }
298
299 HyperNode& getHyperNode(size_t i) {return *vpHyperNodes_[i]; }
300
301 const HyperNode& getHyperNode(size_t i) const {return *vpHyperNodes_[i]; }
302
303 /*
304 *@brief Checks if all the path (ie hypernodes) are exclusive.
305 *
306 */
307
308 bool hasExclusivePaths() const;
309
310 void fireParameterChanged(const ParameterList& parameters);
311
312 /*
313 *@brief compute the probabilities in all the HyperNodes
314 *
315 */
316
318
319 /*
320 *@brief computes the probability of an HyperNode, given the
321 * conditional probabilities of the submodels computed from the
322 * hypernodes of this MixedSubstitutionModelSet object. If the
323 * HyperNode does not match the structure of allowed by this
324 * MixedSubstitutionModelSet, an Exception is thrown.
325 *
326 * The probability of an HyperNode is the product -- on the set
327 * of the mixed models -- of the sums of the conditional
328 * probabilities of the submodels that belon to this hypernode
329 * for each mixed model.
330 *
331 *@param hn the HyperNode which conditional probability is computed.
332 */
333
334 double getHyperNodeProbability(const HyperNode& hn) const;
335};
336} // end of namespace bpp.
337#endif // BPP_PHYL_LEGACY_MODEL_MIXEDSUBSTITUTIONMODELSET_H
bool intersects(const Node &) const
checks if this Node intersects another one.
bool operator<=(const Node &) const
checks if this Node is included in another one.
bool operator>=(const Node &) const
checks if this HyperNode includes another one.
Node & operator+=(const Node &)
Cumulates the elements of the given Node into this one.
Vuint vNumb_
A vector<int> where all elements are different and in increasing order.
HyperNode & operator+=(const HyperNode &)
Cumulates the Nodes of the given HyperNode into this one.
void addToModel(size_t nM, const Vuint &vnS)
adds submodel numbers to the nMth mixed model. Checks if all the numbers are valid.
bool operator>=(const HyperNode &) const
checks if this HyperNode includes another one.
void setProbability(double x)
sets the probability
bool isComplete() const
checks if this HyperNode includes at least a submodel of each mixed model
HyperNode(std::shared_ptr< const MixedSubstitutionModelSet >)
bool operator<=(const HyperNode &) const
checks if this HyperNode is included in another one.
bool intersects(const HyperNode &) const
checks if this HyperNode intersects another one.
double getProbability() const
returns the probability
void setModel(size_t nM, const Vuint &vnS)
sets submodel numbers in the nMth mixed model. Checks if all the numbers are valid.
Vuint vUnused_
the coordinates of the Nodes that are not used.
double proba_
probability of this HyperNode.
Substitution models manager for Mixed Substitution Models. This class inherits from SubstitutionModel...
void fireParameterChanged(const ParameterList &parameters)
MixedSubstitutionModelSet(std::shared_ptr< const Alphabet > alpha)
Create a model set according to the specified alphabet.
double getHyperNodeProbability(const HyperNode &hn) const
void addToHyperNode(size_t nM, const Vuint &vnS, int nH=-1)
void clear()
Resets the list of the HyperNodes.
const HyperNode & getHyperNode(size_t i) const
std::vector< HyperNode * > vpHyperNodes_
MixedSubstitutionModelSet & operator=(const MixedSubstitutionModelSet &set)
MixedSubstitutionModelSet * clone() const
Substitution models manager for non-homogeneous / non-reversible models of evolution.
Defines the basic types of data flow nodes.
std::vector< unsigned int > Vuint