11 #include "../../PatternTools.h"
21 std::shared_ptr<TransitionModelInterface> model,
22 std::shared_ptr<DiscreteDistributionInterface> rDist,
27 treeLikelihoodsContainer_(),
31 shared_ptr<MixedTransitionModelInterface> mixedmodel;
33 if ((mixedmodel = dynamic_pointer_cast<MixedTransitionModelInterface>(
model_)) ==
nullptr)
34 throw Exception(
"Bad model: DRHomogeneousMixedTreeLikelihood needs a MixedTransitionModel.");
36 size_t s = mixedmodel->getNumberOfModels();
37 for (
size_t i = 0; i < s; ++i)
41 probas_.push_back(mixedmodel->getNProbability(i));
48 std::shared_ptr<TransitionModelInterface> model,
49 std::shared_ptr<DiscreteDistributionInterface> rDist,
54 treeLikelihoodsContainer_(),
58 shared_ptr<MixedTransitionModelInterface> mixedmodel;
60 if ((mixedmodel = dynamic_pointer_cast<MixedTransitionModelInterface>(
model_)) ==
nullptr)
61 throw Exception(
"Bad model: DRHomogeneousMixedTreeLikelihood needs a MixedTransitionModel.");
63 size_t s = mixedmodel->getNumberOfModels();
65 for (
size_t i = 0; i < s; i++)
69 probas_.push_back(mixedmodel->getNProbability(i));
95 treeLikelihoodsContainer_(lik.treeLikelihoodsContainer_.size()),
96 probas_(lik.probas_.size()),
97 rootArray_(lik.rootArray_)
141 auto mixedmodel = dynamic_pointer_cast<MixedTransitionModelInterface>(
model_);
143 size_t s = mixedmodel->getNumberOfModels();
145 for (
size_t i = 0; i < s; ++i)
153 probas_ = mixedmodel->getProbabilities();
182 vector<Vdouble*> llik;
195 x += (*llik[j])[i] *
probas_[j];
206 vector<Vdouble*> llik;
220 x += (*llik[j])[i] *
probas_[j];
222 la[i] = (*w)[i] *
log(x);
224 sort(la.begin(), la.end());
322 VVdouble* likelihoodArray_i = &likelihoodArray[i];
326 Vdouble* likelihoodArray_i_c = &(*likelihoodArray_i)[c];
330 (*likelihoodArray_i_c)[x] = 0;
342 VVdouble* likelihoodArray_i = &likelihoodArray[i];
347 Vdouble* likelihoodArray_i_c = &(*likelihoodArray_i)[c];
348 Vdouble* lArray_i_c = &(*lArray_i)[c];
351 (*likelihoodArray_i_c)[x] += (*lArray_i_c)[x] *
probas_[nm];
375 throw Exception(
"Derivatives respective to rate distribution parameters are not implemented.");
379 throw Exception(
"Derivatives respective to substitution model parameters are not implemented.");
387 unsigned int brI = TextTools::to<unsigned int>(variable.substr(5));
389 vector< Vdouble*> _vdLikelihoods_branch;
403 x += (*_vdLikelihoods_branch[j])[i] *
probas_[j];
437 throw Exception(
"Derivatives respective to rate distribution parameters are not implemented.");
441 throw Exception(
"Derivatives respective to substitution model parameters are not implemented.");
449 unsigned int brI = TextTools::to<unsigned int>(variable.substr(5));
451 vector< Vdouble*> _vdLikelihoods_branch, _vd2Likelihoods_branch;
467 x += (*_vdLikelihoods_branch[j])[i] *
probas_[j];
471 x2 += (*_vd2Likelihoods_branch[j])[i] *
probas_[j];
474 d += (*w)[i] * (x2 -
pow(x, 2));
std::vector< Node * > nodes_
Pointer toward all nodes in the tree.
virtual void applyParameters()
All parameters are stored in a parameter list. This function apply these parameters to the substituti...
std::shared_ptr< TransitionModelInterface > model_
ParameterList getRateDistributionParameters() const
Get the parameters associated to the rate distribution.
ParameterList getSubstitutionModelParameters() const
Get the parameters associated to substitution model(s).
void initialize()
Init the likelihood object.
bool hasParameter(const std::string &name) const override
const ParameterList & getParameters() const override
const AlignmentDataInterface & data() const
Get the dataset for which the likelihood must be evaluated.
const Tree & tree() const
Get the tree (topology and branch lengths).
A class to compute the average of several DRHomogeneousTreeLikelihood defined from a Mixed Substituti...
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
double getSecondOrderDerivative(const std::string &variable) const
double getLogLikelihoodForASite(size_t site) const
Get the logarithm of the likelihood for a site.
virtual void computeTreeD2Likelihoods()
virtual ~DRHomogeneousMixedTreeLikelihood()
std::vector< double > probas_
double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the logarithm of the likelihood for a site knowing its rate class.
double getFirstOrderDerivative(const std::string &variable) const
double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const
Get the likelihood for a site knowing its rate class and its ancestral state.
std::vector< DRHomogeneousTreeLikelihood * > treeLikelihoodsContainer_
double getLikelihood() const
Get the likelihood for the whole dataset.
double getLogLikelihood() const
Get the logarithm of the likelihood for the whole dataset.
virtual void computeTreeDLikelihoods()
virtual void computeLikelihoodAtNode_(const Node *node, VVVdouble &likelihoodArray, const Node *sonNode=0) const
void computeTreeLikelihood()
double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const
Get the logarithm of the likelihood for a site knowing its rate class and its ancestral state.
void fireParameterChanged(const ParameterList ¶ms)
void resetLikelihoodArrays(const Node *node)
DRHomogeneousMixedTreeLikelihood & operator=(const DRHomogeneousMixedTreeLikelihood &lik)
virtual void computeRootLikelihood()
void setData(const AlignmentDataInterface &sites)
Set the dataset for which the likelihood must be evaluated.
virtual void computeSubtreeLikelihoodPrefix(const Node *node)
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the likelihood for a site knowing its rate class.
virtual void computeTreeD2LikelihoodAtNode(const Node *)
virtual void computeSubtreeLikelihoodPostfix(const Node *node)
Compute the likelihood for a subtree defined by the Tree::Node node.
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site.
void initialize()
Init the likelihood object.
This class implements the likelihood computation for a tree using the double-recursive algorithm.
friend class DRHomogeneousMixedTreeLikelihood
DRHomogeneousTreeLikelihood(const Tree &tree, std::shared_ptr< TransitionModelInterface > model, std::shared_ptr< DiscreteDistributionInterface > rDist, bool checkRooted=true, bool verbose=true)
Build a new DRHomogeneousTreeLikelihood object without data.
void setData(const AlignmentDataInterface &sites) override
Set the dataset for which the likelihood must be evaluated.
std::unique_ptr< DRASDRTreeLikelihoodData > likelihoodData_
DRHomogeneousTreeLikelihood & operator=(const DRHomogeneousTreeLikelihood &lik)
The phylogenetic node class.
virtual int getId() const
Get the node's id.
virtual void addParameters(const ParameterList ¶ms)
virtual void includeParameters(const ParameterList ¶ms)
virtual const ParameterList & getParameters() const=0
Interface for all transition models.
Interface for phylogenetic tree objects.
Defines the basic types of data flow nodes.
double log(const ExtendedFloat &ef)
std::vector< double > Vdouble
ExtendedFloat pow(const ExtendedFloat &ef, double exp)
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble