5 #include "../../PatternTools.h"
26 std::shared_ptr<SubstitutionModelSet> modelSet,
27 std::shared_ptr<DiscreteDistributionInterface> rDist,
29 bool reparametrizeRoot) :
48 reparametrizeRoot_(reparametrizeRoot),
60 modelSet_(lik.modelSet_),
61 brLenParameters_(lik.brLenParameters_),
65 rootFreqs_(lik.rootFreqs_),
68 nbSites_(lik.nbSites_),
69 nbDistinctSites_(lik.nbDistinctSites_),
70 nbClasses_(lik.nbClasses_),
71 nbStates_(lik.nbStates_),
72 nbNodes_(lik.nbNodes_),
73 verbose_(lik.verbose_),
74 minimumBrLen_(lik.minimumBrLen_),
75 maximumBrLen_(lik.maximumBrLen_),
76 brLenConstraint_(lik.brLenConstraint_->clone()),
77 reparametrizeRoot_(lik.reparametrizeRoot_),
84 for (
unsigned int i = 0; i <
nodes_.size(); i++)
118 for (
unsigned int i = 0; i <
nodes_.size(); i++)
130 std::shared_ptr<SubstitutionModelSet> modelSet,
131 std::shared_ptr<DiscreteDistributionInterface> rDist,
135 tree_ = make_unique< TreeTemplate<Node>>(
tree);
142 for (
size_t i = 0; i <
nodes_.size(); ++i)
160 std::shared_ptr<SubstitutionModelSet> modelSet
166 if (modelSet->getAlphabet()->getAlphabetType() !=
data_->getAlphabet()->getAlphabetType())
167 throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::setSubstitutionModelSet(). Model alphabet do not match existing data.");
174 if (modelSet->getNumberOfStates() !=
modelSet_->getNumberOfStates())
178 nbStates_ = modelSet->getNumberOfStates();
181 for (
unsigned int l = 0; l <
nbNodes_; l++)
190 VVdouble* pxy__son_c = &(*pxy__son)[c];
192 for (
unsigned int x = 0; x <
nbStates_; x++)
202 VVdouble* dpxy__son_c = &(*dpxy__son)[c];
204 for (
unsigned int x = 0; x <
nbStates_; x++)
214 VVdouble* d2pxy__son_c = &(*d2pxy__son)[c];
216 for (
unsigned int x = 0; x <
nbStates_; x++)
237 throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::initialize(). Object is already initialized.");
239 throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::initialize(). Data are no set.");
252 throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::getBranchLengthsParameters(). Object is not initialized.");
261 throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::getSubstitutionModelParameters(). Object is not initialized.");
288 throw Exception(
"AbstractBranchNonHomogeneousTreeLikelihood::applyParameters(). Object not initialized.");
290 for (
unsigned int i = 0; i <
nbNodes_; i++)
292 int id =
nodes_[i]->getId();
324 double l1 = 0, l2 = 0;
325 for (
unsigned int i = 0; i <
nbNodes_; i++)
328 if (!
nodes_[i]->hasDistanceToFather())
336 d =
nodes_[i]->getDistanceToFather();
372 for (
unsigned int l = 0; l <
nbNodes_; l++)
392 VVdouble* pxy__node_c = &(*pxy__node)[c];
394 for (
unsigned int x = 0; x <
nbStates_; x++)
396 Vdouble* pxy__node_c_x = &(*pxy__node_c)[x];
397 for (
unsigned int y = 0; y <
nbStates_; y++)
399 (*pxy__node_c_x)[y] = Q(x, y);
411 VVdouble* dpxy__node_c = &(*dpxy__node)[c];
416 for (
unsigned int x = 0; x <
nbStates_; x++)
418 Vdouble* dpxy__node_c_x = &(*dpxy__node_c)[x];
419 for (
unsigned int y = 0; y <
nbStates_; y++)
421 (*dpxy__node_c_x)[y] = rc * dQ(x, y);
433 VVdouble* d2pxy__node_c = &(*d2pxy__node)[c];
436 for (
unsigned int x = 0; x <
nbStates_; x++)
438 Vdouble* d2pxy__node_c_x = &(*d2pxy__node_c)[x];
439 for (
unsigned int y = 0; y <
nbStates_; y++)
441 (*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 branch non-homogeneous models of the TreeLikelihood interface.
std::map< int, VVVdouble > d2pxy_
virtual void initParameters()
This builds the parameters list from all parametrizable objects, i.e. substitution model,...
std::shared_ptr< SubstitutionModelSet > modelSet_
ParameterList getBranchLengthsParameters() const override
Get the branch lengths parameters.
AbstractNonHomogeneousTreeLikelihood & operator=(const AbstractNonHomogeneousTreeLikelihood &lik)
Assignation operator.
virtual void initBranchLengthsParameters(bool verbose=true)
void initialize() override
Init the likelihood object.
virtual void computeAllTransitionProbabilities()
Fill the pxy_, dpxy_ and d2pxy_ arrays for all nodes.
void setSubstitutionModelSet(std::shared_ptr< SubstitutionModelSet > modelSet) override
std::shared_ptr< ConstraintInterface > brLenConstraint_
std::map< int, VVVdouble > dpxy_
void init_(const Tree &tree, std::shared_ptr< SubstitutionModelSet > modelSet, std::shared_ptr< DiscreteDistributionInterface > rDist, bool verbose)
Method called by constructor.
ParameterList getSubstitutionModelParameters() const override
Get the parameters associated to substitution model(s).
virtual void computeTransitionProbabilitiesForNode(const Node *node)
Fill the pxy_, dpxy_ and d2pxy_ arrays for one node.
std::map< int, const Node * > idToNode_
An index linking nodes to their id, for faster access than the getNode() method.
AbstractNonHomogeneousTreeLikelihood(const Tree &tree, std::shared_ptr< SubstitutionModelSet > modelSet, std::shared_ptr< DiscreteDistributionInterface > rDist, bool verbose=true, bool reparametrizeRoot=true)
std::vector< Node * > nodes_
Pointer toward all nodes in the tree.
ParameterList brLenParameters_
virtual void applyParameters()
All parameters are stored in a parameter list. This function apply these parameters to the substituti...
std::map< int, VVVdouble > pxy_
std::vector< double > rootFreqs_
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
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_EX
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