5 #include "../../Model/MixedTransitionModel.h"
6 #include "../../Model/MixtureOfASubstitutionModel.h"
82 for (i = 0; i < nbm; i++)
87 if (nhn.
getNode(i).
size() != pSM.getNumberOfModels())
98 for (i = 0; i < nbm; i++)
104 auto snd = nd.
size();
105 auto vs = pSM.getNumberOfModels();
111 while ((k < snd) && ((uint)nd[k] < j))
113 if ((k >= snd) || ((uint)nd[k] > j))
129 throw BadIntegerException(
"MixedSubstitutionModelSet::addToHyperNode. Bad HyperNode number", nH);
144 for (
size_t i = 0; i < nhn; i++)
173 for (fmM = 0; fmM < nbm; fmM++)
187 for (
size_t nh = 0; nh < nbh; nh++)
193 for (
size_t i = 0; i < fnd.
size(); i++)
202 for (
size_t iM = fmM + 1; iM < nbm; iM++)
207 for (
size_t nh = 0; nh < nbh; nh++)
212 for (
size_t j = 0; j < fnd.
size(); j++)
217 for (
size_t j = 0; j < fnd.
size(); j++)
229 for (
size_t nh = 0; nh < nbh; nh++)
233 for (
size_t j = 0; j < fnd.
size(); j++)
247 for (
size_t fmM = 0; fmM < nbm; fmM++)
255 for (
size_t i = 0; i < fnd.
size(); ++i)
275 vNumbers_(pMSMS->getNumberOfModels()),
279 for (
size_t i = 0; i < pMSMS->getNumberOfModels(); i++)
288 vUnused_(hn.vUnused_),
297 for (
size_t i = 0; i < hn.
vNumbers_.size(); i++)
302 vUnused_.resize(hn.
vUnused_.size());
303 for (
size_t i = 0; i < hn.
vUnused_.size(); i++)
315 if (nM >= vNumbers_.size())
316 throw IndexOutOfBoundsException(
"MixedSubstitutionModelSet::HyperNode::addToModel. Bad Mixed model Number", nM, 0, vNumbers_.size());
318 vNumbers_[nM].insertN(vnS);
323 if (nM >= vNumbers_.size())
324 throw IndexOutOfBoundsException(
"MixedSubstitutionModelSet::HyperNode::setModel. Bad Mixed model Number", nM, 0, vNumbers_.size());
332 size_t vUs = vUnused_.size();
333 for (
size_t i = 0; i < vNumbers_.size(); ++i)
335 for (k = 0; k < vUs; k++)
337 if (vUnused_[k] == i)
340 if ((k == vUs) && vNumbers_[i].size() == 0)
348 for (
size_t i = 0; i < vNumbers_.size(); i++)
359 for (
size_t i = 0; i < vNumbers_.size(); i++)
361 if (vNumbers_[i].intersects(hn.
vNumbers_[i]))
375 for (
size_t i = 0; i < vNumbers_.size(); i++)
389 vector<uint>::iterator it;
390 vector<uint>::const_iterator it2;
392 for (it2 = vn.begin(); it2 != vn.end(); it2++)
394 for (it = vNumb_.begin(); it != vNumb_.end(); it++)
399 if (it == vNumb_.end())
400 vNumb_.push_back(*it2);
401 else if (*it != *it2)
402 vNumb_.insert(it, *it2);
415 vector<uint>::const_iterator it2(n.
vNumb_.begin());
417 for (
const auto& it : vNumb_)
419 while (it2 != n.
vNumb_.end() && (*it2 < it))
421 if (it2 == n.
vNumb_.end() || (*it2 > it))
434 vector<uint>::const_iterator it2(n.
vNumb_.begin());
436 for (
const auto& it : vNumb_)
438 while (it2 != n.
vNumb_.end() && (*it2 < it))
441 if (it2 == n.
vNumb_.end())
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.
void insertN(const Vuint &vn)
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.
HyperNode & operator=(const HyperNode &)
void setProbability(double x)
sets the probability
bool isComplete() const
checks if this HyperNode includes at least a submodel of each mixed model
std::vector< Node > vNumbers_
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.
const Node & getNode(size_t i) const
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...
~MixedSubstitutionModelSet()
void fireParameterChanged(const ParameterList ¶meters)
MixedSubstitutionModelSet(std::shared_ptr< const Alphabet > alpha)
Create a model set according to the specified alphabet.
double getHyperNodeProbability(const HyperNode &hn) const
void computeHyperNodesProbabilities()
void addToHyperNode(size_t nM, const Vuint &vnS, int nH=-1)
size_t getNumberOfHyperNodes() const
void clear()
Resets the list of the HyperNodes.
std::vector< HyperNode * > vpHyperNodes_
bool hasExclusivePaths() const
HyperNode & getHyperNode(size_t i)
MixedSubstitutionModelSet & operator=(const MixedSubstitutionModelSet &set)
void addHyperNode(const HyperNode &hn)
Interface for Transition models, defined as a mixture of "simple" transition models.
virtual double getNProbability(size_t i) const =0
Returns the probability of a specific model from the mixture.
virtual void setNProbability(size_t i, double prob)=0
Sets the probability of a specific model from the mixture.
virtual void normalizeVRates()=0
Normalizes the rates of the submodels so that the mean rate of the mixture equals rate_.
Substitution models manager for non-homogeneous / non-reversible models of evolution.
virtual void fireParameterChanged(const ParameterList ¶meters)
size_t getNumberOfModels() const
const TransitionModelInterface & model(size_t i) const
SubstitutionModelSet & operator=(const SubstitutionModelSet &set)
void clear()
Resets all the information contained in this object.
Defines the basic types of data flow nodes.
std::vector< unsigned int > Vuint