19 std::shared_ptr<DiscreteDistributionInterface> rDist,
21 rateDistribution_(rDist)
31 throw Exception(
"AbstractDiscreteRatesAcrossSitesTreeLikelihood::getRateDistributionParameters(). Object is not initialized.");
40 throw Exception(
"AbstractDiscreteRatesAcrossSitesTreeLikelihood::getDerivableParameters(). Object is not initialized.");
49 throw Exception(
"AbstractDiscreteRatesAcrossSitesTreeLikelihood::getNonDerivableParameters(). Object is not initialized.");
62 for (
size_t i = 0; i < nbSites; i++)
64 l[i].resize(nbClasses);
65 for (
size_t j = 0; j < nbClasses; j++)
79 for (
size_t i = 0; i < nbClasses; i++)
92 for (
size_t i = 0; i < nbClasses; i++)
107 for (
size_t i = 0; i < nbSites; i++)
110 for (
size_t j = 0; j < nbClasses; j++)
126 for (
size_t i = 0; i < nbSites; i++)
128 l[i].resize(nbClasses);
129 for (
size_t j = 0; j < nbClasses; j++)
131 l[i][j].resize(nbStates);
132 for (
size_t x = 0; x < nbStates; x++)
149 for (
size_t i = 0; i < nbSites; i++)
151 l[i].resize(nbClasses);
152 for (
size_t j = 0; j < nbClasses; j++)
154 l[i][j].resize(nbStates);
155 for (
size_t x = 0; x < nbStates; x++)
172 for (
size_t i = 0; i < nbSites; i++)
174 for (
size_t j = 0; j < nbClasses; j++)
191 for (
size_t i = 0; i < nbSites; i++)
193 for (
size_t j = 0; j < nbClasses; j++)
207 vector<size_t> classes(nbSites);
208 for (
size_t i = 0; i < nbSites; i++)
210 classes[i] = VectorTools::whichMax<double>(l[i]);
222 for (
size_t i = 0; i < nbSites; i++)
234 size_t nbSites = likelihoodArray.size();
235 size_t nbClasses = likelihoodArray[0].size();
236 size_t nbStates = likelihoodArray[0][0].size();
237 for (
size_t i = 0; i < nbSites; i++)
239 for (
size_t c = 0; c < nbClasses; c++)
241 for (
size_t s = 0; s < nbStates; s++)
243 likelihoodArray[i][c][s] = 1.;
254 size_t nbSites = likelihoodArray.size();
255 size_t nbClasses = likelihoodArray[0].size();
256 size_t nbStates = likelihoodArray[0][0].size();
257 for (
size_t i = 0; i < nbSites; i++)
259 cout <<
"Site " << i <<
":" << endl;
260 for (
size_t c = 0; c < nbClasses; c++)
262 cout <<
"Rate class " << c;
263 for (
size_t s = 0; s < nbStates; s++)
265 cout <<
"\t" << likelihoodArray[i][c][s];
281 for (
size_t i = 0; i < p2.size(); i++)
284 for (
size_t j = 0; j < p2.size(); j++)
288 p2[i][j] += p3[k][i][j] * probs[k];
Vdouble getPosteriorRatePerSite() const
Get the posterior rate, i.e. averaged over all classes and weighted with posterior probabilities,...
ParameterList getRateDistributionParameters() const
Get the parameters associated to the rate distribution.
size_t getNumberOfClasses() const
Get the number of classes.
Vdouble getRateWithMaxPostProbPerSite() const
Get the posterior rate (the one with maximum posterior probability) for each site.
VVdouble getLogLikelihoodPerSitePerRateClass() const
Get the logarithm of the likelihood for each site and each rate class.
VVdouble getTransitionProbabilities(int nodeId, size_t siteIndex) const
Retrieves all Pij(t) for a particular branch, defined by the upper node and site.
double getLikelihoodForASiteForAState(size_t site, int state) const
Get the likelihood for a site and for a state.
AbstractDiscreteRatesAcrossSitesTreeLikelihood(std::shared_ptr< DiscreteDistributionInterface > rDist, bool verbose=true)
ParameterList getNonDerivableParameters() const
All non derivable parameters.
VVdouble getPosteriorProbabilitiesPerRate() const
Get the posterior probability for each site of belonging to a particular rate class.
ParameterList getDerivableParameters() const
All derivable parameters.
VVVdouble getLogLikelihoodPerSitePerRateClassPerState() const
Get the logarithm of the likelihood for each site and each rate class and each state.
double getLogLikelihoodForASiteForAState(size_t site, int state) const
Get the logarithm of the likelihood for a site and for a state.
std::shared_ptr< DiscreteDistributionInterface > rateDistribution_
static void displayLikelihoodArray(const VVVdouble &likelihoodArray)
Print the likelihood array to terminal (debugging tool).
static void resetLikelihoodArray(VVVdouble &likelihoodArray)
Set all conditional likelihoods to 1.
VVdouble getLikelihoodPerSitePerRateClass() const
Get the likelihood for each site and each rate class.
std::vector< size_t > getRateClassWithMaxPostProbPerSite() const
Get the posterior rate class (the one with maximum posterior probability) for each site.
VVVdouble getLikelihoodPerSitePerRateClassPerState() const
Get the likelihood for each site and each rate class and each state.
const ParameterList & getParameters() const override
void enableDerivatives(bool yn)
Tell if derivatives must be computed.
Vdouble getLikelihoodPerSite() const
Get the likelihood for each site.
size_t getNumberOfSites() const
Get the number of sites in the dataset.
virtual double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const =0
Get the logarithm of the likelihood for a site knowing its rate class.
virtual double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const =0
Get the likelihood for a site knowing its rate class.
virtual VVVdouble getTransitionProbabilitiesPerRateClass(int nodeId, size_t siteIndex) const =0
Retrieves all Pij(t) for a particular branch, defined by the upper node.
virtual double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const =0
Get the logarithm of the likelihood for a site knowing its rate class and its ancestral state.
virtual double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const =0
Get the likelihood for a site knowing its rate class and its ancestral state.
virtual void addParameters(const ParameterList ¶ms)
virtual size_t getNumberOfStates() const =0
virtual ParameterList getSubstitutionModelParameters() const =0
Get the parameters associated to substitution model(s).
virtual ParameterList getBranchLengthsParameters() const =0
Get the branch lengths parameters.
Defines the basic types of data flow nodes.
double log(const ExtendedFloat &ef)
std::vector< double > Vdouble
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble