|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
61 out <<
"Weight of each edge: ";
68 out <<
"Extra placement weights:\n";
72 out <<
"Path length weights:\n";
82 throw std::logic_error(
"Invalid SimulatorLikeWeightRatioDistribution." );
85 out <<
"Like weight ratio intervals and weights:\n";
86 for(
size_t i = 0; i < distrib.
intervals.size(); ++i ) {
143 std::uniform_real_distribution<double> distrib( 0.0, 1.0 );
172 std::bernoulli_distribution distrib;
220 std::vector<double>
const& depth_weights,
229 edge_distrib.
edge_weights = std::vector<double>(num_edges, 0.0);
235 for(
auto const& edge : sample.
tree().
edges() ) {
237 auto dp = depths[ edge.primary_node().index() ].second;
238 auto ds = depths[ edge.secondary_node().index() ].second;
239 auto ld = std::min(dp, ds);
242 assert( edge.index() < num_edges );
247 if (ld < depth_weights.size()) {
248 edge_distrib.
edge_weights[ edge.index() ] = depth_weights[ld];
268 throw std::runtime_error(
"Cannot set weights using an empty Tree.");
276 std::uniform_int_distribution<size_t> edge_selection( 0,
edge_count - 1 );
282 std::bernoulli_distribution dir_distrib;
292 auto cur_link = &start_link->
next();
293 cur_link != start_link;
296 edge_distrib.
edge_weights[ cur_link->edge().index() ] = 1.0;
319 throw std::runtime_error(
"Invalid link index for subtree." );
322 throw std::runtime_error(
"Cannot use a leaf node as subtree." );
332 auto cur_link = &start_link->
next();
333 cur_link != start_link;
336 edge_distrib.
edge_weights[ cur_link->edge().index() ] = 1.0;
368 auto weights = std::vector<double>();
369 for(
auto const& pquery : sample.
pqueries() ) {
370 size_t extra_placements = pquery.placement_size() - 1;
371 if( weights.size() < extra_placements + 1 ) {
372 weights.resize( extra_placements + 1 );
374 ++weights[ extra_placements ];
389 auto weights = std::vector<double>();
390 for(
auto const& pquery : sample.
pqueries() ) {
391 for(
auto const& place_from : pquery.placements() ) {
392 for(
auto const& place_to : pquery.placements() ) {
393 size_t dist = edge_dist_matrix(
394 place_from.edge().index(), place_to.edge().index()
400 if( place_from.edge().index() == place_to.edge().index() ) {
409 if( weights.size() < dist + 1 ) {
410 weights.resize( dist + 1 );
412 weights[ dist ] += 1.0;
426 size_t number_of_intervals
429 auto intervals = std::vector<double>( number_of_intervals + 1, 0.0 );
430 auto weights = std::vector<double>( number_of_intervals + 1, 0.0 );
431 for(
size_t i = 0; i < number_of_intervals + 1; ++i ) {
432 intervals[i] =
static_cast<double>( i ) /
static_cast<double>( number_of_intervals );
437 for(
auto const& pquery : sample.
pqueries() ) {
438 for(
auto const& placement : pquery.placements() ) {
440 double rounded_lwr = std::round( placement.like_weight_ratio * number_of_intervals )
441 / number_of_intervals;
443 if( 0.0 > rounded_lwr || rounded_lwr > 1.0 ) {
444 throw std::runtime_error(
"Invalid like_weight_ratio in Sample." );
446 size_t pos =
static_cast<size_t>( rounded_lwr * number_of_intervals );
447 assert( pos < weights.size() );
448 weights[ pos ] += 1.0;
TreeLink & primary_link()
Return the TreeLink of this TreeEdge that points towards the root.
PlacementTree & tree()
Get the PlacementTree of this Sample.
std::vector< double > edge_weights
size_t link_count() const
Return the number of TreeLinks of the Tree.
void set_random_edges(Sample const &sample, SimulatorEdgeDistribution &edge_distrib)
Set the weights of a SimulatorEdgeDistribution randomly to either 0.0 or 1.0, so that a random subset...
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on.
TreeLink & next()
Return the next TreeLink within the TreeNode of this link.
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
Provides some valuable additions to STD.
void learn_per_edge_weights(Sample const &sample, SimulatorEdgeDistribution &edge_distrib)
Sets the weights of an SimulatorEdgeDistributionso that they follow the same distribution of placemen...
Provides functions for working with Placements and Pqueries.
utils::Matrix< size_t > edge_path_length_matrix(Tree const &tree)
size_t set_random_subtree_weights(Sample const &sample, SimulatorEdgeDistribution &edge_distrib)
Sets the weights of an SimulatorEdgeDistribution to 1.0 for a randomly chosen subtree,...
Provides some commonly used string utility functions.
void set_uniform_weights(Sample const &sample, SimulatorEdgeDistribution &edge_distrib)
Sets the weights of an SimulatorEdgeDistribution to 1.0 for all edges, so that each edge has the same...
bool empty() const
Return whether the Tree is empty (i.e., has no nodes, edges and links).
std::vector< double > intervals
Interval< DataType, NumericalType, IntervalKind > join(Interval< DataType, NumericalType, IntervalKind > const &a, Interval< DataType, NumericalType, IntervalKind > const &b)
Creates a new Interval that contains both intervals and whatever is between.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
void learn_like_weight_ratio_distribution(Sample const &sample, SimulatorLikeWeightRatioDistribution &lwr_distib, size_t number_of_intervals)
std::vector< double > weights
utils::Range< IteratorEdges > edges()
void set_subtree_weights(Sample const &sample, size_t link_index, SimulatorEdgeDistribution &edge_distrib)
Set the weights of a subtree to 1.0 and all other weights to 0.0.
void learn_placement_path_length_weights(Sample const &sample, SimulatorExtraPlacementDistribution &p_distib)
std::vector< double > closest_leaf_weight_distribution(Sample const &sample)
void set_depths_distributed_weights(Sample const &sample, SimulatorEdgeDistribution &edge_distrib)
Set the weights of an SimulatorEdgeDistribution so that they follow the depth distribution of the edg...
std::vector< double > placement_mass_per_edges_with_multiplicities(Sample const &sample)
Return a vector that contains the sum of the masses of the PqueryPlacements per edge of the tree of t...
TreeLink & link_at(size_t index)
Return the TreeLink at a certain index.
TreeLink & outer()
Return the TreeLink of the adjacent TreeNode.
void set_random_weights(Sample const &sample, SimulatorEdgeDistribution &edge_distrib)
Set the weights of an SimulatorEdgeDistribution for the edges randomly to a value between 0....
static Options & get()
Returns a single instance of this class.
bool is_leaf(TreeLink const &link)
Return true iff the node of the given link is a leaf node.
Header of Tree distance methods.
utils::Range< iterator_pqueries > pqueries()
Return a Range iterator to the Pqueries .
TreeLink & secondary_link()
Return the TreeLink of this TreeEdge that points away from the root.
std::ostream & operator<<(std::ostream &out, Sample const &smp)
Print a table of all Pqueries with their Placements and Names to the stream.
void learn_placement_number_weights(Sample const &sample, SimulatorExtraPlacementDistribution &p_distib)
size_t edge_count(Tree const &tree)
Return the number of Edges of a Tree. Same as Tree::edge_count().
std::vector< std::pair< TreeNode const *, size_t > > closest_leaf_depth_vector(const Tree &tree)
Returns a vector containing the closest leaf node for each node, measured in number of edges between ...
size_t edge_count() const
Return the number of TreeEdges of the Tree.