42 #include "../TreeTemplateTools.h" 48 #include <Bpp/App/ApplicationTools.h> 54 RHomogeneousClockTreeLikelihood::RHomogeneousClockTreeLikelihood(
57 DiscreteDistribution * rDist,
68 RHomogeneousClockTreeLikelihood::RHomogeneousClockTreeLikelihood(
70 const SiteContainer & data,
72 DiscreteDistribution * rDist,
83 void RHomogeneousClockTreeLikelihood::init_()
86 if (!tree_->isRooted())
throw Exception(
"RHomogeneousClockTreeLikelihood::init_(). Tree is unrooted!");
87 if (TreeTemplateTools::isMultifurcating(*tree_->getRootNode()))
throw Exception(
"HomogeneousClockTreeLikelihood::init_(). Tree is multifurcating.");
88 setMinimumBranchLength(0.);
93 void RHomogeneousClockTreeLikelihood::applyParameters() throw (Exception)
95 if (!initialized_)
throw Exception(
"RHomogeneousClockTreeLikelihood::applyParameters(). Object not initialized.");
97 brLenParameters_.matchParametersValues(getParameters());
98 computeBranchLengthsFromHeights(tree_->getRootNode(), brLenParameters_.getParameter(
"TotalHeight").getValue());
101 model_->matchParametersValues(getParameters());
103 rateDistribution_->matchParametersValues(getParameters());
108 void RHomogeneousClockTreeLikelihood::fireParameterChanged(
const ParameterList& params)
112 computeAllTransitionProbabilities();
114 computeTreeLikelihood();
116 minusLogLik_ = - getLogLikelihood();
121 void RHomogeneousClockTreeLikelihood::initBranchLengthsParameters()
124 for(
unsigned int i = 0; i < nbNodes_; i++)
126 double d = minimumBrLen_;
127 if(!nodes_[i]->hasDistanceToFather())
129 ApplicationTools::displayWarning(
"Missing branch length " + TextTools::toString(i) +
". Value is set to " + TextTools::toString(minimumBrLen_));
130 nodes_[i]->setDistanceToFather(minimumBrLen_);
134 d = nodes_[i]->getDistanceToFather();
135 if (d < minimumBrLen_)
137 ApplicationTools::displayWarning(
"Branch length " + TextTools::toString(i) +
" is too small: " + TextTools::toString(d) +
". Value is set to " + TextTools::toString(minimumBrLen_));
138 nodes_[i]->setDistanceToFather(minimumBrLen_);
143 brLenParameters_.reset();
145 map<const Node*, double> heights;
146 TreeTemplateTools::getHeights(*tree_->getRootNode(), heights);
147 double totalHeight = heights[tree_->getRootNode()];
148 brLenParameters_.addParameter(Parameter(
"TotalHeight", totalHeight, brLenConstraint_->clone(),
true));
149 for (map<const Node *, double>::iterator it = heights.begin(); it != heights.end(); it++)
151 if (!it->first->isLeaf() && it->first->hasFather())
153 double fatherHeight = heights[it->first->getFather()];
154 brLenParameters_.addParameter(Parameter(
"HeightP" + TextTools::toString(it->first->getId()), it->second / fatherHeight, &Parameter::PROP_CONSTRAINT_IN));
161 void RHomogeneousClockTreeLikelihood::computeBranchLengthsFromHeights(
Node* node,
double height)
throw (Exception)
163 for (
unsigned int i = 0; i < node->getNumberOfSons(); i++)
172 Parameter* p = &brLenParameters_.getParameter(
string(
"HeightP") + TextTools::toString(son->
getId()));
173 double sonHeightP = p->getValue();
174 double sonHeight = sonHeightP * height;
176 computeBranchLengthsFromHeights(son, sonHeight);
183 ParameterList RHomogeneousClockTreeLikelihood::getDerivableParameters()
const throw (Exception)
185 if (!initialized_)
throw Exception(
"RHomogeneousClockTreeLikelihood::getDerivableParameters(). Object is not initialized.");
186 return ParameterList();
191 ParameterList RHomogeneousClockTreeLikelihood::getNonDerivableParameters()
const throw (Exception)
193 if (!initialized_)
throw Exception(
"RHomogeneousClockTreeLikelihood::getNonDerivableParameters(). Object is not initialized.");
194 return getParameters();
201 double RHomogeneousClockTreeLikelihood::getFirstOrderDerivative(
const std::string& variable)
const 204 throw Exception(
"No first order derivative is implemented for this function.");
211 double RHomogeneousClockTreeLikelihood::getSecondOrderDerivative(
const std::string& variable)
const 214 throw Exception(
"No second order derivative is implemented for this function.");
Interface for all substitution models.
virtual const Node * getSon(size_t pos) const
Interface for phylogenetic tree objects.
This class implement the 'traditional' way of computing likelihood for a tree.
virtual bool isLeaf() const
virtual int getId() const
Get the node's id.
The phylogenetic node class.
virtual void setDistanceToFather(double distance)
Set or update the distance toward the father node.