A toolkit for working with phylogenetic data.
v0.24.0
balances.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_MASS_TREE_BALANCES_H_
2 #define GENESIS_TREE_MASS_TREE_BALANCES_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2019 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include "genesis/tree/tree.hpp"
36 
37 #include <vector>
38 #include <unordered_set>
39 
40 namespace genesis {
41 namespace tree {
42 
43 // =================================================================================================
44 // Forward Declarations
45 // =================================================================================================
46 
47 using MassTree = Tree;
48 
49 // =================================================================================================
50 // Balance Settings
51 // =================================================================================================
52 
77 {
78  enum class WeightTendency
79  {
83  kNone,
84 
89  kMedian,
90 
96 
102  };
103 
104  enum class WeightNorm
105  {
109  kNone,
110 
115  kManhattan,
116 
121  kEuclidean,
122 
127  kMaximum,
128 
133  kAitchison
134  };
135 
141 
146 
151 
156 };
157 
158 // =================================================================================================
159 // Balance Data
160 // =================================================================================================
161 
171 {
180 
198 
214 
229  std::vector<double> taxon_weights;
230 };
231 
232 // =================================================================================================
233 // Balances and Weights Calculations
234 // =================================================================================================
235 
249  std::vector<MassTree> const& trees,
250  BalanceSettings settings = {}
251 );
252 
263  MassTree const& tree,
264  BalanceSettings settings = {}
265 );
266 
275 std::vector<double> mass_balance(
276  BalanceData const& data,
277  std::unordered_set<size_t> const& numerator_edge_indices,
278  std::unordered_set<size_t> const& denominator_edge_indices
279 );
280 
292 double mass_balance(
293  BalanceData const& data,
294  std::unordered_set<size_t> const& numerator_edge_indices,
295  std::unordered_set<size_t> const& denominator_edge_indices,
296  size_t tree_index
297 );
298 
299 } // namespace tree
300 } // namespace genesis
301 
302 #endif // include guard
Use the geometric mean of the taxon masses.
Use the Euclidean norm of the relative abundances of the taxon.
WeightTendency tendency
Set the term for asssing the central tendency of taxon masses for calculating the taxon weights...
Definition: balances.hpp:140
WeightNorm norm
Set the term for the norm of relative abundances for calculating the taxon weights.
Definition: balances.hpp:145
BalanceData mass_balance_data(std::vector< MassTree > const &trees, BalanceSettings settings)
Calculate the data needed to calculate balances on MassTrees.
Definition: balances.cpp:64
utils::Matrix< double > raw_edge_masses
The absolute raw per-edge masses per original input Tree.
Definition: balances.hpp:213
double pseudo_count_summand_zeros
Set the constant that is added to taxon masses that are zero, to avoid zero counts.
Definition: balances.hpp:155
Data needed to calculate balances.
Definition: balances.hpp:170
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
Use no tendency, that is, use 1.0 for this term.
Tree MassTree
Alias for a Tree that stores masses on its TreeEdges.
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
Settings to calculate balances and the Phylogenetic ILR Transform.
Definition: balances.hpp:76
double pseudo_count_summand_all
Set the constant that is added to all taxon masses to avoid zero counts.
Definition: balances.hpp:150
std::vector< double > mass_balance(BalanceData const &data, std::unordered_set< size_t > const &numerator_edge_indices, std::unordered_set< size_t > const &denominator_edge_indices)
Calculate the balance of edge masses between two sets of edges.
Definition: balances.cpp:357
Use the arithmetic mean of the taxon masses.
Tree tree
The Tree on which to calculate balances.
Definition: balances.hpp:179
std::vector< double > taxon_weights
The taxon/edge weights calculated from mulitple trees.
Definition: balances.hpp:229
Header of Tree class.
utils::Matrix< double > edge_masses
The relative per-edge masses per original input Tree.
Definition: balances.hpp:197