40 #include "../PatternTools.h"
63 bool reparametrizeRoot)
83 reparametrizeRoot_(reparametrizeRoot),
87 init_(tree, modelSet, rDist, verbose);
95 modelSet_(lik.modelSet_),
96 brLenParameters_(lik.brLenParameters_),
100 rootFreqs_(lik.rootFreqs_),
103 nbSites_(lik.nbSites_),
104 nbDistinctSites_(lik.nbDistinctSites_),
105 nbClasses_(lik.nbClasses_),
106 nbStates_(lik.nbStates_),
107 nbNodes_(lik.nbNodes_),
108 verbose_(lik.verbose_),
109 minimumBrLen_(lik.minimumBrLen_),
110 maximumBrLen_(lik.maximumBrLen_),
111 brLenConstraint_(dynamic_cast<
Constraint*>(lik.brLenConstraint_->clone())),
112 reparametrizeRoot_(lik.reparametrizeRoot_),
119 for (
unsigned int i = 0; i <
nodes_.size(); i++)
154 for(
unsigned int i = 0; i <
nodes_.size(); i++)
173 root2_ = tree_->getRootNode()->getSon(1)->getId();
174 nodes_ = tree_->getNodes();
176 nbNodes_ = nodes_.size();
178 for (
unsigned int i = 0; i < nodes_.size(); i++)
180 const Node * node = nodes_[i];
181 idToNode_[node->
getId()] = node;
183 nbClasses_ = rateDistribution_->getNumberOfCategories();
187 minimumBrLen_ = 0.000001;
188 maximumBrLen_ = 10000;
189 brLenConstraint_.reset(
new IntervalConstraint(minimumBrLen_, maximumBrLen_,
true,
true));
190 setSubstitutionModelSet(modelSet);
200 if (modelSet->getAlphabet()->getAlphabetType() != data_->getAlphabet()->getAlphabetType())
201 throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::setSubstitutionModelSet(). Model alphabet do not match existing data.");
204 modelSet_ = modelSet;
208 if (modelSet->getNumberOfStates() != modelSet_->getNumberOfStates())
212 nbStates_ = modelSet->getNumberOfStates();
215 for (
unsigned int l = 0; l < nbNodes_; l++)
218 Node* son = nodes_[l];
221 pxy__son->resize(nbClasses_);
222 for (
unsigned int c = 0; c < nbClasses_; c++)
224 VVdouble * pxy__son_c = & (* pxy__son)[c];
225 pxy__son_c->resize(nbStates_);
226 for(
unsigned int x = 0; x < nbStates_; x++)
228 (*pxy__son_c)[x].resize(nbStates_);
233 dpxy__son->resize(nbClasses_);
234 for (
unsigned int c = 0; c < nbClasses_; c++)
236 VVdouble * dpxy__son_c = & (* dpxy__son)[c];
237 dpxy__son_c->resize(nbStates_);
238 for(
unsigned int x = 0; x < nbStates_; x++)
240 (* dpxy__son_c)[x].resize(nbStates_);
245 d2pxy__son->resize(nbClasses_);
246 for (
unsigned int c = 0; c < nbClasses_; c++)
248 VVdouble * d2pxy__son_c = & (* d2pxy__son)[c];
249 d2pxy__son_c->resize(nbStates_);
250 for(
unsigned int x = 0; x < nbStates_; x++)
252 (* d2pxy__son_c)[x].resize(nbStates_);
261 computeAllTransitionProbabilities();
262 fireParameterChanged(getParameters());
270 if (
initialized_)
throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::initialize(). Object is already initialized.");
271 if (!
data_)
throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::initialize(). Data are no set.");
282 if (!
initialized_)
throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::getBranchLengthsParameters(). Object is not initialized.");
290 if(!
initialized_)
throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::getSubstitutionModelParameters(). Object is not initialized.");
316 if (!
initialized_)
throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::applyParameters(). Object not initialized.");
318 for (
unsigned int i = 0; i <
nbNodes_; i++)
320 int id =
nodes_[i]->getId();
323 const Parameter* rootBrLen = &getParameter(
"BrLenRoot");
324 const Parameter* rootPos = &getParameter(
"RootPosition");
325 nodes_[i]->setDistanceToFather(rootBrLen->getValue() * rootPos->getValue());
329 const Parameter* rootBrLen = &getParameter(
"BrLenRoot");
330 const Parameter* rootPos = &getParameter(
"RootPosition");
331 nodes_[i]->setDistanceToFather(rootBrLen->getValue() * (1. - rootPos->getValue()));
336 if (brLen)
nodes_[i]->setDistanceToFather(brLen->getValue());
350 double l1 = 0, l2 = 0;
351 for (
unsigned int i = 0; i <
nbNodes_; i++)
354 if (!
nodes_[i]->hasDistanceToFather())
361 d =
nodes_[i]->getDistanceToFather();
394 for(
unsigned int l = 0; l <
nbNodes_; l++)
414 VVdouble * pxy__node_c = & (* pxy__node)[c];
416 for(
unsigned int x = 0; x <
nbStates_; x++)
418 Vdouble * pxy__node_c_x = & (* pxy__node_c)[x];
419 for(
unsigned int y = 0; y <
nbStates_; y++)
421 (* pxy__node_c_x)[y] = Q(x, y);
433 VVdouble * dpxy__node_c = & (* dpxy__node)[c];
438 for(
unsigned int x = 0; x <
nbStates_; x++)
440 Vdouble * dpxy__node_c_x = & (* dpxy__node_c)[x];
441 for(
unsigned int y = 0; y <
nbStates_; y++)
442 (* dpxy__node_c_x)[y] = rc * dQ(x, y);
453 VVdouble * d2pxy__node_c = & (* d2pxy__node)[c];
456 for(
unsigned int x = 0; x <
nbStates_; x++)
458 Vdouble * d2pxy__node_c_x = & (* d2pxy__node_c)[x];
459 for(
unsigned int y = 0; y <
nbStates_; y++)
461 (* d2pxy__node_c_x)[y] = rc * rc * d2Q(x, y);