8 #include "../../PatternTools.h"
26 std::shared_ptr<TransitionModelInterface> model,
27 std::shared_ptr<DiscreteDistributionInterface> rDist,
48 init_(
tree, model, rDist, checkRooted, verbose);
57 brLenParameters_(lik.brLenParameters_),
61 rootFreqs_(lik.rootFreqs_),
63 nbSites_(lik.nbSites_),
64 nbDistinctSites_(lik.nbDistinctSites_),
65 nbClasses_(lik.nbClasses_),
66 nbStates_(lik.nbStates_),
67 nbNodes_(lik.nbNodes_),
68 verbose_(lik.verbose_),
69 minimumBrLen_(lik.minimumBrLen_),
70 maximumBrLen_(lik.maximumBrLen_),
71 brLenConstraint_(lik.brLenConstraint_->clone())
107 std::shared_ptr<TransitionModelInterface> model,
108 std::shared_ptr<DiscreteDistributionInterface> rDist,
113 tree_ = make_unique<TreeTemplate<Node>>(
tree);
114 if (checkRooted &&
tree_->isRooted())
140 if (model->getAlphabet()->getAlphabetType() !=
data_->getAlphabet()->getAlphabetType())
141 throw Exception(
"AbstractHomogeneousTreeLikelihood::setSubstitutionModel(). Model alphabet do not match existing data.");
148 if (model->getNumberOfStates() !=
model_->getNumberOfStates())
155 for (
unsigned int l = 0; l <
nbNodes_; l++)
164 VVdouble* pxy__son_c = &(*pxy__son)[c];
166 for (
unsigned int x = 0; x <
nbStates_; x++)
176 VVdouble* dpxy__son_c = &(*dpxy__son)[c];
178 for (
unsigned int x = 0; x <
nbStates_; x++)
188 VVdouble* d2pxy__son_c = &(*d2pxy__son)[c];
190 for (
unsigned int x = 0; x <
nbStates_; x++)
203 throw Exception(
"AbstractHomogeneousTreeLikelihood::initialize(). Object is already initialized.");
205 throw Exception(
"AbstractHomogeneousTreeLikelihood::initialize(). Data are no set.");
216 throw Exception(
"AbstractHomogeneousTreeLikelihood::getBranchLengthsParameters(). Object is not initialized.");
225 throw Exception(
"AbstractHomogeneousTreeLikelihood::getSubstitutionModelParameters(). Object is not initialized.");
252 throw Exception(
"AbstractHomogeneousTreeLikelihood::applyParameters(). Object not initialized.");
255 for (
unsigned int i = 0; i <
nbNodes_; i++)
273 for (
unsigned int i = 0; i <
nbNodes_; i++)
276 if (!
nodes_[i]->hasDistanceToFather())
284 d =
nodes_[i]->getDistanceToFather();
308 for (
unsigned int l = 0; l <
nbNodes_; l++)
327 VVdouble* pxy__node_c = &(*pxy__node)[c];
330 for (
unsigned int x = 0; x <
nbStates_; x++)
332 Vdouble* pxy__node_c_x = &(*pxy__node_c)[x];
333 for (
unsigned int y = 0; y <
nbStates_; y++)
335 (*pxy__node_c_x)[y] = Q(x, y);
346 VVdouble* dpxy__node_c = &(*dpxy__node)[c];
349 for (
unsigned int x = 0; x <
nbStates_; x++)
351 Vdouble* dpxy__node_c_x = &(*dpxy__node_c)[x];
352 for (
unsigned int y = 0; y <
nbStates_; y++)
354 (*dpxy__node_c_x)[y] = rc * dQ(x, y);
366 VVdouble* d2pxy__node_c = &(*d2pxy__node)[c];
369 for (
unsigned int x = 0; x <
nbStates_; x++)
371 Vdouble* d2pxy__node_c_x = &(*d2pxy__node_c)[x];
372 for (
unsigned int y = 0; y <
nbStates_; y++)
374 (*d2pxy__node_c_x)[y] = rc * rc * d2Q(x, y);
Partial implementation of the DiscreteRatesAcrossSitesTreeLikelihood interface.
AbstractDiscreteRatesAcrossSitesTreeLikelihood & operator=(const AbstractDiscreteRatesAcrossSitesTreeLikelihood &tl)
std::shared_ptr< DiscreteDistributionInterface > rateDistribution_
Partial implementation for homogeneous model of the TreeLikelihood interface.
virtual void initParameters()
This builds the parameters list from all parametrizable objects, i.e. substitution model,...
std::vector< Node * > nodes_
Pointer toward all nodes in the tree.
virtual void initBranchLengthsParameters(bool verbose=true)
void setModel(std::shared_ptr< TransitionModelInterface > model)
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 brLenParameters_
ParameterList getBranchLengthsParameters() const
Get the branch lengths parameters.
virtual void computeTransitionProbabilitiesForNode(const Node *node)
Fill the pxy_, dpxy_ and d2pxy_ arrays for one node.
std::shared_ptr< ConstraintInterface > brLenConstraint_
std::vector< double > rootFreqs_
void init_(const Tree &tree, std::shared_ptr< TransitionModelInterface > model, std::shared_ptr< DiscreteDistributionInterface > rDist, bool checkRooted, bool verbose)
Method called by constructor.
ParameterList getSubstitutionModelParameters() const
Get the parameters associated to substitution model(s).
AbstractHomogeneousTreeLikelihood(const Tree &tree, std::shared_ptr< TransitionModelInterface > model, std::shared_ptr< DiscreteDistributionInterface > rDist, bool checkRooted=true, bool verbose=true)
void initialize()
Init the likelihood object.
std::map< int, VVVdouble > dpxy_
std::map< int, VVVdouble > pxy_
std::map< int, VVVdouble > d2pxy_
virtual void computeAllTransitionProbabilities()
Fill the pxy_, dpxy_ and d2pxy_ arrays for all nodes.
AbstractHomogeneousTreeLikelihood & operator=(const AbstractHomogeneousTreeLikelihood &lik)
Assignation operator.
const Parameter & parameter(const std::string &name) const override
virtual void fireParameterChanged(const ParameterList ¶meters)
virtual void addParameters_(const ParameterList ¶meters)
const ParameterList & getParameters() const override
const Tree & tree() const
Get the tree (topology and branch lengths).
std::unique_ptr< const AlignmentDataInterface > data_
std::shared_ptr< TreeTemplate< Node > > tree_
bool computeFirstOrderDerivatives_
bool computeSecondOrderDerivatives_
The phylogenetic node class.
virtual int getId() const
Get the node's id.
virtual double getDistanceToFather() const
Get the distance to the father node is there is one, otherwise throw a NodeException.
virtual ParameterList getCommonParametersWith(const ParameterList ¶ms) const
virtual void addParameter(const Parameter ¶m)
virtual double getValue() const
virtual void setData(const AlignmentDataInterface &sites)=0
Set the dataset for which the likelihood must be evaluated.
Interface for phylogenetic tree objects.
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble