High-level description
The code defines a class_InferPosteriorTimes in C++ that estimates the posterior distribution of branch lengths in a phylogenetic tree under an infinite-sites model of evolution with an exponential prior on branch lengths. This is done using dynamic programming to efficiently compute the likelihoods of different branch length configurations.
Code Structure
The code defines a single class_InferPosteriorTimes which encapsulates all the logic for inferring posterior times. The class has a public run method that takes the tree data and model parameters as input and computes the posterior distributions. The results can then be accessed through various getter methods. Internally, the class uses dynamic programming tables (down_cache, up_cache) to store intermediate results and avoid redundant computations.
Symbols
_InferPosteriorTimes
Description
This class implements a dynamic programming algorithm to infer the posterior distribution of branch lengths in a phylogenetic tree under an infinite-sites model of evolution with an exponential prior on branch lengths.Inputs
Outputs
The class does not directly return any output. Instead, the results are stored internally and can be accessed through the following getter methods:get_posterior_means_res(): Returns a vector of pairs, where each pair represents a node and its posterior mean branch length.get_posteriors_res(): Returns a vector of pairs, where each pair represents a node and its posterior distribution of branch lengths.get_log_joints_res(): Returns a vector of pairs, where each pair represents a node and its log joint probability for each time point.get_log_likelihood_res(): Returns the log-likelihood of the data given the tree and model parameters.
Internal Logic
The class uses a dynamic programming algorithm to compute the likelihood of the data given the tree and model parameters. The algorithm works by recursively computing the likelihood of subtrees, starting from the leaves and moving towards the root. Two dynamic programming tables are used:down_cache:down_cache[v][t][x]stores the log-probability of generating all data at and below nodev, starting from timetand withxmutations already accumulated on the branch leading tov.up_cache:up_cache[v][t][x]stores the log-probability of generating all data above nodev, with nodevdividing at timetand having accumulatedxmutations on the branch leading to it.
