56 PairedSiteLikelihoods::PairedSiteLikelihoods() :
62 const vector<vector<double> >& siteLogLikelihoods,
63 const vector<string>& modelNames)
throw (Exception) :
64 logLikelihoods_(siteLogLikelihoods),
65 modelNames_(modelNames)
67 if (modelNames_.size() != getNumberOfModels())
69 if (modelNames_.size() == 0)
70 modelNames_.assign(getNumberOfModels(),
string());
72 throw Exception(
"PairedSiteLikelihoods: There should be as many model names as model site-loglikelihoods records.");
75 if (this->getNumberOfModels() > 0)
77 for (vector<vector<double> >::const_iterator siteLLiks = siteLogLikelihoods.begin();
78 siteLLiks != siteLogLikelihoods.end();
81 if (siteLLiks->size() != getNumberOfSites())
82 throw Exception(
"PairedSiteLikelihoods: Models site-loglikelihoods records do not have the same number of elements.");
88 const vector<double>& siteLogLikelihoods,
89 const string& modelName
92 if (getNumberOfModels() > 0 && siteLogLikelihoods.size() != getNumberOfSites())
93 throw Exception(
"PairedSiteLikelihoods::appendModel: Model site-loglikelihoods record does not have the correct number of elements");
95 logLikelihoods_.push_back(siteLogLikelihoods);
96 modelNames_.push_back(modelName);
101 const vector<double>& siteLogLikelihoods = treeLikelihood.getLogLikelihoodForEachSite();
102 const string& modelName = treeLikelihood.getTree().getName();
109 if (getNumberOfModels() > 0 && psl.getNumberOfModels() > 0 && psl.getNumberOfSites() != getNumberOfSites())
110 throw Exception(
"PairedSiteLikelihoods::appendModels: The two PairedSiteLikelihood objects have different number of sites.");
112 logLikelihoods_.insert(logLikelihoods_.end(),
113 psl.logLikelihoods_.begin(),
114 psl.logLikelihoods_.end()
117 modelNames_.insert(modelNames_.end(),
118 psl.modelNames_.begin(),
119 psl.modelNames_.end()
130 for (
int r = 0; r < replicates; ++r)
143 Y += modelSiteLLiks.at(s) * siteCounts.at(s);
145 models_logliks.at(m) = Y;
149 double Ymax = *max_element(models_logliks.begin(), models_logliks.end());
156 exp_logliks_diffs.at(m) = exp(models_logliks.at(m) - Ymax);
159 double sumELLD = accumulate(exp_logliks_diffs.begin(), exp_logliks_diffs.end(), 0.0);
164 double w = exp_logliks_diffs.at(m) / sumELLD;
170 for (vector<double>::iterator w = weights.begin(); w != weights.end(); ++w)
180 vector<int> v(length, 0);
182 for (
size_t i = 0; i < static_cast<size_t>(
static_cast<double>(length) * scaling + 0.5); ++i)
184 ++v[RandomTools::giveIntRandomNumberBetweenZeroAndEntry<size_t>(length)];
A container for paired-site likelihoods (likelihoods over the same sites for different models...
static std::vector< int > bootstrap(std::size_t length, double scaling=1)
Draw a nonparametric pseudoreplicate.
void appendModels(const PairedSiteLikelihoods &psl)
Append models by concatenation.
The TreeLikelihood interface.
void appendModel(const std::vector< double > &siteLogLikelihoods, const std::string &modelName="")
Append a model.
std::pair< std::vector< std::string >, std::vector< double > > computeExpectedLikelihoodWeights(int replicates=10000) const
Compute the Expected Likelihood Weights of the models.
std::vector< std::vector< double > > logLikelihoods_
std::size_t getNumberOfSites() const
size_t getNumberOfModels() const
Get the number of models in the container.
std::vector< std::string > modelNames_