2
// File: AbstractNonHomogeneousTreeLikelihood.h
3
// Created by: Julien Dutheil
4
// Created on: Tue Oct 09 16:07 2007
5
// From file: AbstractHomogeneousTreeLikelihood.h
9
Copyright or Ā© or Copr. CNRS, (November 16, 2004)
11
This software is a computer program whose purpose is to provide classes
12
for phylogenetic data analysis.
14
This software is governed by the CeCILL license under French law and
15
abiding by the rules of distribution of free software. You can use,
16
modify and/ or redistribute the software under the terms of the CeCILL
17
license as circulated by CEA, CNRS and INRIA at the following URL
18
"http://www.cecill.info".
20
As a counterpart to the access to the source code and rights to copy,
21
modify and redistribute granted by the license, users are provided only
22
with a limited warranty and the software's author, the holder of the
23
economic rights, and the successive licensors have only limited
26
In this respect, the user's attention is drawn to the risks associated
27
with loading, using, modifying and/or developing or reproducing the
28
software by the user in light of its specific status of free software,
29
that may mean that it is complicated to manipulate, and that also
30
therefore means that it is reserved for developers and experienced
31
professionals having in-depth computer knowledge. Users are therefore
32
encouraged to load and test the software's suitability as regards their
33
requirements in conditions enabling the security of their systems and/or
34
data to be ensured and, more generally, to use and operate it in the
35
same conditions as regards security.
37
The fact that you are presently reading this means that you have had
38
knowledge of the CeCILL license and that you accept its terms.
41
#ifndef _ABSTRACTNONHOMOGENEOUSTREELIKELIHOOD_H_
42
#define _ABSTRACTNONHOMOGENEOUSTREELIKELIHOOD_H_
44
#include "NonHomogeneousTreeLikelihood.h"
45
#include "AbstractDiscreteRatesAcrossSitesTreeLikelihood.h"
54
* @brief Partial implementation for branch non-homogeneous models of the TreeLikelihood interface.
56
* This class provides a pointer toward a single substitution model + several utilitary variables.
58
class AbstractNonHomogeneousTreeLikelihood:
59
public virtual NonHomogeneousTreeLikelihood,
60
public AbstractDiscreteRatesAcrossSitesTreeLikelihood
64
class ConstNonHomogeneousSiteModelIterator :
65
public ConstSiteModelIterator
68
std::vector<ConstNoPartitionSiteModelDescription> siteModelDescriptions_;
70
unsigned int nbModels_;
73
ConstNonHomogeneousSiteModelIterator(const SubstitutionModelSet* modelSet) :
74
siteModelDescriptions_(), index_(0), nbModels_(modelSet->getNumberOfModels())
76
for (unsigned int i = 0; i < nbModels_; ++i)
77
siteModelDescriptions_.push_back(ConstNoPartitionSiteModelDescription(modelSet->getModel(i), modelSet->getNodesWithModel(i)));
81
ConstSiteModelDescription* next() throw (Exception)
84
throw Exception("AbstractNonHomogeneousTreeLikelihood::ConstHomogeneousSiteModelIterator::next(). No more site in the set.");
85
return &siteModelDescriptions_[index_++];
88
bool hasNext() const { return index_ < nbModels_; }
92
SubstitutionModelSet* modelSet_;
93
ParameterList brLenParameters_;
95
mutable std::map<int, VVVdouble> pxy_;
97
mutable std::map<int, VVVdouble> dpxy_;
99
mutable std::map<int, VVVdouble> d2pxy_;
101
std::vector<double> rootFreqs_;
104
* @brief Pointer toward all nodes in the tree.
106
* The position in the array is the number used in the parameter name.
107
* This may be different from the node id, unless you used the resetNodeId method on the input tree.
109
std::vector<Node*> nodes_;
112
* @brief An index linking nodes to their id, for faster access than the getNode() method.
114
mutable std::map<int, const Node*> idToNode_;
116
//some values we'll need:
117
unsigned int nbSites_, //the number of sites in the container
118
nbDistinctSites_, //the number of distinct sites
119
nbClasses_, //the number of rate classes
120
nbStates_, //the number of states in the alphabet
121
nbNodes_; //the number of nodes in the tree
125
double minimumBrLen_;
126
std::auto_ptr<Constraint> brLenConstraint_;
131
AbstractNonHomogeneousTreeLikelihood(
133
SubstitutionModelSet* modelSet,
134
DiscreteDistribution* rDist,
139
* @brief Copy constructor
141
* This constructor is to be called by the derived class copy constructor.
143
AbstractNonHomogeneousTreeLikelihood(const AbstractNonHomogeneousTreeLikelihood& lik);
146
* @brief Assignation operator
148
* This operator is to be called by the derived class operator.
150
AbstractNonHomogeneousTreeLikelihood& operator=(const AbstractNonHomogeneousTreeLikelihood& lik);
152
virtual ~AbstractNonHomogeneousTreeLikelihood() {}
157
* @brief Method called by constructor.
161
SubstitutionModelSet* modelSet,
162
DiscreteDistribution* rDist,
163
bool verbose) throw (Exception);
168
* @name The TreeLikelihood interface.
170
* Other methods are implemented in the AbstractTreeLikelihood class.
174
void initialize() throw(Exception);
176
ParameterList getBranchLengthsParameters() const;
178
ParameterList getSubstitutionModelParameters() const;
180
ParameterList getRateDistributionParameters() const
182
return AbstractDiscreteRatesAcrossSitesTreeLikelihood::getRateDistributionParameters();
185
const SubstitutionModel* getSubstitutionModelForNode(int nodeId) const throw (NodeNotFoundException)
187
return modelSet_->getModelForNode(nodeId);
190
SubstitutionModel* getSubstitutionModelForNode(int nodeId) throw (NodeNotFoundException)
192
return modelSet_->getModelForNode(nodeId);
195
const std::vector<double>& getRootFrequencies(unsigned int siteIndex) const { return rootFreqs_; }
197
VVVdouble getTransitionProbabilitiesPerRateClass(int nodeId, unsigned int siteIndex) const { return pxy_[nodeId]; }
199
ConstBranchModelIterator* getNewBranchModelIterator(int nodeId) const
201
return new ConstNoPartitionBranchModelIterator(modelSet_->getModelForNode(nodeId), nbDistinctSites_);
204
ConstSiteModelIterator* getNewSiteModelIterator(unsigned int siteIndex) const
206
return new ConstNonHomogeneousSiteModelIterator(modelSet_);
212
* @name The NonHomogeneousTreeLikelihood interface.
214
* Other methods are implemented in the AbstractTreeLikelihood class.
218
const SubstitutionModelSet* getSubstitutionModelSet() const { return modelSet_; }
220
SubstitutionModelSet* getSubstitutionModelSet() { return modelSet_; }
222
void setSubstitutionModelSet(SubstitutionModelSet* modelSet) throw (Exception);
224
ParameterList getRootFrequenciesParameters() const
226
return modelSet_->getRootFrequenciesParameters();
230
public: //Specific methods:
233
* @brief This builds the <i>parameters</i> list from all parametrizable objects,
234
* <i>i.e.</i> substitution model, rate distribution and tree.
236
virtual void initParameters();
239
* @brief All parameters are stored in a parameter list.
240
* This function apply these parameters to the substitution model,
241
* to the rate distribution and to the branch lengths.
243
virtual void applyParameters() throw (Exception);
245
virtual void initBranchLengthsParameters();
247
virtual void setMinimumBranchLength(double minimum)
249
minimumBrLen_ = minimum;
250
if (brLenConstraint_.get()) brLenConstraint_.release();
251
brLenConstraint_.reset(new IncludingPositiveReal(minimumBrLen_));
252
initBranchLengthsParameters();
255
virtual double getMinimumBranchLength() const { return minimumBrLen_; }
259
* @brief Fill the pxy_, dpxy_ and d2pxy_ arrays for all nodes.
261
virtual void computeAllTransitionProbabilities();
263
* @brief Fill the pxy_, dpxy_ and d2pxy_ arrays for one node.
265
virtual void computeTransitionProbabilitiesForNode(const Node * node);
269
} //end of namespace bpp.
271
#endif //_ABSTRACTNONHOMOGENEOUSTREELIKELIHOOD_H_