bpp-phyl  2.2.0
MixedSubstitutionModelSet.h
Go to the documentation of this file.
1 //
2 // File: MixedSubstitutionModelSet.h
3 // Created by: Laurent Guéguen
4 // Created on: mercredi 25 mai 2011, à 22h 04
5 //
6 
7 /*
8  Copyright or (c) or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
40 #ifndef _MIXEDSUBSTITUTIONMODELSET_H_
41 #define _MIXEDSUBSTITUTIONMODELSET_H_
42 
43 
44 #include "SubstitutionModelSet.h"
46 
47 #include <Bpp/Exceptions.h>
48 #include <Bpp/Numeric/VectorTools.h>
49 
50 namespace bpp
51 {
122  public SubstitutionModelSet
123 {
124 public:
125  class HyperNode
126  {
127 public:
128  class Node
129  {
134  Vint vNumb_;
135 
136 public:
137  Node() : vNumb_() {}
138  Node(const Node& n) : vNumb_(n.vNumb_){}
139  Node& operator=(const Node& n)
140  {
141  vNumb_ = n.vNumb_;
142  return *this;
143  }
144 
145  ~Node(){}
146 
147  Node& operator=(const Vint& n)
148  {
149  vNumb_ = n;
150  return *this;
151  }
152 
153  void insertN(const Vint& vn);
154 
155  size_t size() const
156  {
157  return vNumb_.size();
158  }
159 
165  Node& operator+=(const Node&);
166 
172  bool operator<=(const Node&) const;
173 
179  bool operator>=(const Node&) const;
180 
186  bool intersects(const Node&) const;
187 
188  int operator[](size_t i) const { return vNumb_[i]; }
189  };
190 
191 private:
192  std::vector<Node> vNumbers_;
193 
199  Vint vUnused_;
200 
206  double proba_;
207 
208 public:
210  HyperNode(const HyperNode&);
211  HyperNode& operator=(const HyperNode&);
213 
222  void setModel(size_t nM, const Vint& vnS);
223 
232  void addToModel(size_t nM, const Vint& vnS);
237  HyperNode& operator+=(const HyperNode&);
238 
243  bool operator<=(const HyperNode&) const;
244 
249  bool isComplete() const;
254  bool operator>=(const HyperNode&) const;
255 
260  bool intersects(const HyperNode&) const;
261 
266  double getProbability() const {return proba_; }
267 
272  void setProbability(double x) { proba_ = x; }
273 
274  const Node& getNode(size_t i) const { return vNumbers_[i]; }
275  };
276 
277 private:
278  std::vector<HyperNode*> vpHyperNodes_;
279 
280 public:
286  MixedSubstitutionModelSet(const Alphabet* alpha) :
287  SubstitutionModelSet(alpha),
288  vpHyperNodes_() {}
289 
291 
293 
295 
297 
298 #ifndef NO_VIRTUAL_COV
300 #else
301  Clonable*
302 #endif
303  clone() const { return new MixedSubstitutionModelSet(*this); }
304 
309  void clear();
310 
311  /*
312  *@brief adds a new empty HyperNode to the end of the HyperNodes
313  * list.
314  */
315 
316  void addEmptyHyperNode();
317 
318  /*
319  *@brief adds the copy of an HyperNode to the end of the
320  * HyperNodes list.
321  */
322 
323  void addHyperNode(const HyperNode& hn);
324 
325  /*
326  *@brief If necessary, adds a new HyperNode such that all
327  * submodels of the mixture models are at least in an
328  * HyperNode.
329  *
330  * Returns true iff a new path has been built.
331  *
332  */
333 
334  bool complete();
335 
336  /*
337  *@brief adds a submodel number to the nMth mixed model of the
338  * nHth HyperNode of the list (default nH=0). Checks if all the
339  * numbers are valid.
340  *
341  ***@param nM number of the mixed model
342  ***@param vnS number of the submodel
343  ***@param nH number of the concerned HyperNode (default the last element of
344  * the list)
345  */
346 
347  void addToHyperNode(size_t nM, const Vint& vnS, int nH = -1);
348 
349  size_t getNumberOfHyperNodes() const { return vpHyperNodes_.size(); }
350 
351  HyperNode& getHyperNode(size_t i) {return *vpHyperNodes_[i]; }
352 
353  const HyperNode& getHyperNode(size_t i) const {return *vpHyperNodes_[i]; }
354 
355  /*
356  *@brief Checks if all the path (ie hypernodes) are exclusive.
357  *
358  */
359 
360  bool hasExclusivePaths() const;
361 
362  void fireParameterChanged(const ParameterList& parameters);
363 
364  /*
365  *@brief compute the probabilities in all the HyperNodes
366  *
367  */
368 
370 
371  /*
372  *@brief computes the probability of an HyperNode, given
373  * the conditional probabilities of the submodels computed
374  * from the hypernodes of this MixedSubstitutionModelSet
375  * object. If the HyperNode does not match the structure of
376  * allowed by this MixedSubstitutionModelSet, an Exception
377  * is thrown.
378  *
379  * The probability of an HyperNode is the product -- on the
380  * set of the mixed models -- of the sums of the
381  * conditional probabilities of the submodels that belon to
382  * this hypernode for each mixed model.
383  *
384  ***@param hn the HyperNode which conditional probability is computed.
385  */
386 
387  double getHyperNodeProbability(const HyperNode& hn) const;
388 };
389 } // end of namespace bpp.
390 
391 #endif // _MIXEDSUBSTITUTIONMODELSET_H_
392 
Vint vNumb_
A vector<int> where all elements are different and in increasing order.
Substitution models manager for non-homogeneous / non-reversible models of evolution.
void setModel(size_t nM, const Vint &vnS)
sets submodel numbers in the nMth mixed model. Checks if all the numbers are valid.
const HyperNode & getHyperNode(size_t i) const
bool operator>=(const Node &) const
checks if this HyperNode includes another one.
MixedSubstitutionModelSet(const Alphabet *alpha)
Create a model set according to the specified alphabet.
MixedSubstitutionModelSet & operator=(const MixedSubstitutionModelSet &set)
double getHyperNodeProbability(const HyperNode &hn) const
bool operator>=(const HyperNode &) const
checks if this HyperNode includes another one.
void setProbability(double x)
sets the probability
MixedSubstitutionModelSet * clone() const
bool isComplete() const
checks if this HyperNode includes at least a submodel of each mixed model
bool operator<=(const Node &) const
checks if this Node is included in another one.
void clear()
Resets the list of the HyperNodes.
double proba_
probability of this HyperNode.
Vint vUnused_
the coordinates of the Nodes that are not used.
void addToHyperNode(size_t nM, const Vint &vnS, int nH=-1)
double getProbability() const
returns the probability
Substitution models manager for Mixed Substitution Models. This class inherits from SubstitutionModel...
HyperNode & operator+=(const HyperNode &)
Cumulates the Nodes of the given HyperNode into this one.
void addToModel(size_t nM, const Vint &vnS)
adds submodel numbers to the nMth mixed model. Checks if all the numbers are valid.
bool intersects(const HyperNode &) const
checks if this HyperNode intersects another one.
void fireParameterChanged(const ParameterList &parameters)
bool operator<=(const HyperNode &) const
checks if this HyperNode is included in another one.
bool intersects(const Node &) const
checks if this Node intersects another one.
std::vector< HyperNode * > vpHyperNodes_
Node & operator+=(const Node &)
Cumulates the elements of the given Node into this one.