41 #include "../PatternTools.h"
84 init_(tree, model, rDist, checkRooted, verbose);
93 brLenParameters_(lik.brLenParameters_),
97 rootFreqs_(lik.rootFreqs_),
99 nbSites_(lik.nbSites_),
100 nbDistinctSites_(lik.nbDistinctSites_),
101 nbClasses_(lik.nbClasses_),
102 nbStates_(lik.nbStates_),
103 nbNodes_(lik.nbNodes_),
104 verbose_(lik.verbose_),
105 minimumBrLen_(lik.minimumBrLen_),
106 maximumBrLen_(lik.maximumBrLen_),
107 brLenConstraint_(lik.brLenConstraint_->clone())
151 if (checkRooted && tree_->isRooted())
157 nodes_ = tree_->getNodes();
159 nbNodes_ = nodes_.size();
160 nbClasses_ = rateDistribution_->getNumberOfCategories();
161 setSubstitutionModel(model);
165 minimumBrLen_ = 0.000001;
166 maximumBrLen_ = 10000;
167 brLenConstraint_.reset(
new IntervalConstraint(minimumBrLen_, maximumBrLen_,
true,
true));
177 if (model->getAlphabet()->getAlphabetType() != data_->getAlphabet()->getAlphabetType())
178 throw Exception(
"AbstractHomogeneousTreeLikelihood::setSubstitutionModel(). Model alphabet do not match existing data.");
185 if (model->getNumberOfStates() != model_->getNumberOfStates())
189 nbStates_ = model->getNumberOfStates();
192 for (
unsigned int l = 0; l < nbNodes_; l++)
195 Node* son = nodes_[l];
198 pxy__son->resize(nbClasses_);
199 for (
unsigned int c = 0; c < nbClasses_; c++)
201 VVdouble* pxy__son_c = &(*pxy__son)[c];
202 pxy__son_c->resize(nbStates_);
203 for (
unsigned int x = 0; x < nbStates_; x++)
205 (*pxy__son_c)[x].resize(nbStates_);
210 dpxy__son->resize(nbClasses_);
211 for (
unsigned int c = 0; c < nbClasses_; c++)
213 VVdouble* dpxy__son_c = &(*dpxy__son)[c];
214 dpxy__son_c->resize(nbStates_);
215 for (
unsigned int x = 0; x < nbStates_; x++)
217 (*dpxy__son_c)[x].resize(nbStates_);
222 d2pxy__son->resize(nbClasses_);
223 for (
unsigned int c = 0; c < nbClasses_; c++)
225 VVdouble* d2pxy__son_c = &(*d2pxy__son)[c];
226 d2pxy__son_c->resize(nbStates_);
227 for (
unsigned int x = 0; x < nbStates_; x++)
229 (*d2pxy__son_c)[x].resize(nbStates_);
240 throw Exception(
"AbstractHomogeneousTreeLikelihood::initialize(). Object is already initialized.");
242 throw Exception(
"AbstractHomogeneousTreeLikelihood::initialize(). Data are no set.");
253 throw Exception(
"AbstractHomogeneousTreeLikelihood::getBranchLengthsParameters(). Object is not initialized.");
262 throw Exception(
"AbstractHomogeneousTreeLikelihood::getSubstitutionModelParameters(). Object is not initialized.");
263 return model_->getParameters().getCommonParametersWith(getParameters());
289 throw Exception(
"AbstractHomogeneousTreeLikelihood::applyParameters(). Object not initialized.");
292 for (
unsigned int i = 0; i <
nbNodes_; i++)
296 nodes_[i]->setDistanceToFather(brLen->getValue());
299 model_->matchParametersValues(getParameters());
310 for (
unsigned int i = 0; i <
nbNodes_; i++)
313 if (!
nodes_[i]->hasDistanceToFather())
320 d =
nodes_[i]->getDistanceToFather();
342 for (
unsigned int l = 0; l <
nbNodes_; l++)
361 VVdouble* pxy__node_c = &(*pxy__node)[c];
363 for (
unsigned int x = 0; x <
nbStates_; x++)
365 Vdouble* pxy__node_c_x = &(*pxy__node_c)[x];
366 for (
unsigned int y = 0; y <
nbStates_; y++)
368 (*pxy__node_c_x)[y] = Q(x, y);
379 VVdouble* dpxy__node_c = &(*dpxy__node)[c];
382 for (
unsigned int x = 0; x <
nbStates_; x++)
384 Vdouble* dpxy__node_c_x = &(*dpxy__node_c)[x];
385 for (
unsigned int y = 0; y <
nbStates_; y++)
387 (*dpxy__node_c_x)[y] = rc * dQ(x, y);
399 VVdouble* d2pxy__node_c = &(*d2pxy__node)[c];
402 for (
unsigned int x = 0; x <
nbStates_; x++)
404 Vdouble* d2pxy__node_c_x = &(*d2pxy__node_c)[x];
405 for (
unsigned int y = 0; y <
nbStates_; y++)
407 (*d2pxy__node_c_x)[y] = rc * rc * d2Q(x, y);