|
A library for working with phylogenetic and population genetic data.
v0.27.0
|
|
Go to the documentation of this file.
68 #ifdef GENESIS_PTHREADS
83 #pragma omp parallel for
86 #pragma omp parallel for
95 result += place_i.like_weight_ratio * place_j.like_weight_ratio * dist;
104 auto result = std::vector<double>( sample.
size(), 0 );
107 #pragma omp parallel for
108 for(
size_t qi = 0; qi < sample.
size(); ++qi ) {
109 auto const& pquery = sample.
at( qi );
110 result[qi] =
edpl( pquery, node_distances );
118 return edpl( pquery, node_distances );
124 return edpl( sample, node_distances );
134 bool with_pendant_length
137 throw std::invalid_argument(
"pairwise_distance: Incompatible trees.");
146 std::vector<PqueryPlain>
const pqueries_a =
plain_queries( smp_a );
147 std::vector<PqueryPlain>
const pqueries_b =
plain_queries( smp_b );
157 auto dist =
pquery_distance( pqry_a, pqry_b, node_distances, with_pendant_length );
158 dist *= pqry_a.multiplicity * pqry_b.multiplicity;
180 const std::vector<PqueryPlain>& pqrys_b,
182 bool with_pendant_length
184 double partial = 0.0;
189 if (pqry_a.
index >= pqry_b.index) {
192 double dist =
pquery_distance(pqry_a, pqry_b, node_distances, with_pendant_length);
194 partial += dist * dist;
211 const std::vector<PqueryPlain>* pqrys,
214 bool with_pendant_length
217 assert( partial && *partial == 0.0 );
218 double tmp_partial = 0.0;
221 for (
size_t i =
offset; i < pqrys->size(); i += incr) {
225 tmp_partial +=
variance_partial_(pqry_a, *pqrys, *node_distances, with_pendant_length);
229 *partial = tmp_partial;
234 bool with_pendant_length
248 #ifdef GENESIS_PTHREADS
252 std::vector<double> partials(num_threads, 0.0);
253 std::vector<std::thread> threads;
256 for (
int i = 0; i < num_threads; ++i) {
257 threads.emplace_back(
259 i, num_threads, &vd_pqueries, &node_distances,
267 for (
int i = 0; i < num_threads; ++i) {
286 for (
const auto& pqry : vd_pqueries) {
287 for (
const auto& place : pqry.placements) {
288 mass += place.like_weight_ratio * pqry.multiplicity;
double total_placement_mass_with_multiplicities(Sample const &smp)
Get the mass of all PqueryPlacements of the Sample, using the multiplicities as factors.
PlacementTree & tree()
Get the PlacementTree of this Sample.
static void variance_thread_(const int offset, const int incr, const std::vector< PqueryPlain > *pqrys, const utils::Matrix< double > *node_distances, double *partial, bool with_pendant_length)
Internal function that calculates the sum of distances for the variance that is contributed by a subs...
double sum(const Histogram &h)
static double variance_partial_(const PqueryPlain &pqry_a, const std::vector< PqueryPlain > &pqrys_b, const utils::Matrix< double > &node_distances, bool with_pendant_length)
Internal function that calculates the sum of distances contributed by one pquery for the variance....
size_t size() const
Return the number of Pqueries that are stored in this Sample.
Simple POD struct that stores the information of a Pquery in a simple format for speeding up some cal...
double pquery_distance(PqueryPlain const &pquery_a, PqueryPlain const &pquery_b, utils::Matrix< double > const &node_distances, bool with_pendant_length)
Calculate the weighted distance between two plain pqueries. It is mainly a helper method for distance...
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on.
void offset(Histogram &h, double value)
std::vector< PqueryPlain > plain_queries(Sample const &smp)
Return a plain representation of all pqueries of this map.
Provides functions for working with Placements and Pqueries.
double pairwise_distance(const Sample &smp_a, const Sample &smp_b, bool with_pendant_length)
Calculate the normalized pairwise distance between all placements of the two Samples.
Header of CommonTree distance methods.
PqueryPlacement & placement_at(size_t index)
Return the PqueryPlacement at a certain index.
Header for Placement Measures functions.
Provides easy and fast logging functionality.
A pquery holds a set of PqueryPlacements and a set of PqueryNames.
Pquery & at(size_t index)
Return the Pquery at a certain index.
double placement_distance(PqueryPlacement const &place_a, PqueryPlacement const &place_b, utils::Matrix< double > const &node_distances)
Calculate the distance between two PqueryPlacements, using their positin on the tree::TreeEdges,...
double variance(const Sample &smp, bool with_pendant_length)
Calculate the variance of the placements on a tree.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
size_t placement_size() const
Return the number of PqueryPlacements stored in this Pquery.
unsigned int number_of_threads() const
Returns the number of threads.
Header of PqueryPlain class.
utils::Matrix< double > node_branch_length_distance_matrix(Tree const &tree)
Return a distance matrix containing pairwise distances between all Nodes, using the branch_length of ...
static Options & get()
Returns a single instance of this class.
double edpl(Pquery const &pquery, utils::Matrix< double > const &node_distances)
Calculate the EDPL uncertainty values for a Pquery.
Header of Tree distance methods.
bool compatible_trees(PlacementTree const &lhs, PlacementTree const &rhs)
Return whether two PlacementTrees are compatible.