21 PairedSiteLikelihoods::PairedSiteLikelihoods() :
27 const vector<vector<double>>& siteLogLikelihoods,
28 const vector<string>& modelNames) :
29 logLikelihoods_(siteLogLikelihoods),
30 modelNames_(modelNames)
37 throw Exception(
"PairedSiteLikelihoods: There should be as many model names as model site-loglikelihoods records.");
42 for (vector<vector<double>>::const_iterator siteLLiks = siteLogLikelihoods.begin();
43 siteLLiks != siteLogLikelihoods.end();
47 throw Exception(
"PairedSiteLikelihoods: Models site-loglikelihoods records do not have the same number of elements.");
53 const vector<double>& siteLogLikelihoods,
54 const string& modelName
58 throw Exception(
"PairedSiteLikelihoods::appendModel: Model site-loglikelihoods record does not have the correct number of elements");
67 const string& modelName = treeLikelihood.
tree().
getName();
75 throw Exception(
"PairedSiteLikelihoods::appendModels: The two PairedSiteLikelihood objects have different number of sites.");
95 for (
int r = 0; r < replicates; ++r)
108 Y += modelSiteLLiks.at(s) * siteCounts.at(s);
110 models_logliks.at(m) = Y;
114 double Ymax = *max_element(models_logliks.begin(), models_logliks.end());
121 exp_logliks_diffs.at(m) =
exp(models_logliks.at(m) - Ymax);
124 double sumELLD = accumulate(exp_logliks_diffs.begin(), exp_logliks_diffs.end(), 0.0);
129 double w = exp_logliks_diffs.at(m) / sumELLD;
135 for (vector<double>::iterator w = weights.begin(); w != weights.end(); ++w)
145 vector<int> v(length, 0);
147 for (
size_t i = 0; i < static_cast<size_t>(
static_cast < double > (length) * scaling + 0.5); ++i)
149 ++v[RandomTools::giveIntRandomNumberBetweenZeroAndEntry<size_t>(length)];
A container for paired-site likelihoods (likelihoods over the same sites for different models,...
size_t getNumberOfModels() const
Get the number of models in the container.
std::vector< std::vector< double > > logLikelihoods_
std::size_t getNumberOfSites() const
void appendModels(const PairedSiteLikelihoods &psl)
Append models by concatenation.
std::vector< std::string > modelNames_
std::pair< std::vector< std::string >, std::vector< double > > computeExpectedLikelihoodWeights(int replicates=10000) const
Compute the Expected Likelihood Weights of the models.
void appendModel(const std::vector< double > &siteLogLikelihoods, const std::string &modelName="")
Append a model.
static std::vector< int > bootstrap(std::size_t length, double scaling=1)
Draw a nonparametric pseudoreplicate.
The TreeLikelihood interface.
virtual const Tree & tree() const =0
Get the tree (topology and branch lengths).
virtual Vdouble getLogLikelihoodPerSite() const =0
Get the logarithm of the likelihood for each site.
virtual std::string getName() const =0
Tree name.
Defines the basic types of data flow nodes.
ExtendedFloat exp(const ExtendedFloat &ef)