Skip to main content

tree_inference_pruning_gtr_gamma.tppl

function build_forest​

Create initial set of leaves - the "forest"

function build_forest(data: Int[][], forest: MsgTree[], index: Int, data_len: Int, seq_len: Int, pi: Real[]) => MsgTree[]

function cluster​

KEY FUNCTION: CLUSTER

function cluster(q: Matrix[Real], trees: MsgTree[], maxAge: Real, seq_len: Int, pi: Real[], rates_cat: Real[], weights: Real[]) => MsgTree[]

function combine_msgs_allcats​

Merge two subtrees without mixing categories. Returns [cat][site]

function combine_msgs_allcats(lmsg: Matrix[Real][][], rmsg: Matrix[Real][][],t1L: Matrix[Real], t2L: Matrix[Real],
t3L: Matrix[Real], t4L: Matrix[Real],t1R: Matrix[Real], t2R: Matrix[Real], t3R: Matrix[Real], t4R: Matrix[Real]) => Matrix[Real][][]

function combine_site_onecat​

Combine one site for one category (left/right, then elementwise multiply)

function combine_site_onecat(left_row: Matrix[Real], right_row: Matrix[Real], tL: Matrix[Real], tR: Matrix[Real]) => Matrix[Real]

function get_leaf_row​

One site → row-vector; keeps leaf logWeight(pi[state])

function get_leaf_row(seq: Int, pi: Real[]) => Matrix[Real]

function get_log_likes​

Compute log likelihood for each site

function get_log_likes(msg: Matrix[Real], pi: Real[]) => Real

function gtr​

A help function to compute the scaled rate matrix for GTR

function gtr(pi: Real[], r: Real[]) => Matrix[Real]

function loglikes_from_msg4​

Map over all sites recursively

function loglikes_from_msg4(
msg4: Matrix[Real][][], pi: Real[], w: Real[]) => Real[]

type MsgTree​

type MsgTree =
| Leaf {age: Real, index: Int, msg: Matrix[Real][][]} // [cat][site]
| Node {age: Real, msg: Matrix[Real][][], left: MsgTree, right: MsgTree}

function myModel​

model function myModel(data: Int[][]) => MsgTree[]

function pickpair​

Randomly sample two indices in the trees vector, to be combined. Avoiding mirror cases.

function pickpair(n: Int) => Int[]

function pi_col​

function pi_col(pi: Real[]) => Matrix[Real]

function replicate4​

Replicate per-site rows across the 4 categories

function replicate4(rows: Matrix[Real][]) => Matrix[Real][][]

function site_log_marginal_from_msg4​

One site's log-marginal for a subtree

function site_log_marginal_from_msg4(msg4_site: Matrix[Real][], pi: Real[], w: Real[]) => Real

function zip_apply_onecat​

Zip/apply over all sites for one category, recursively

function zip_apply_onecat(xs: Matrix[Real][], ys: Matrix[Real][], tL: Matrix[Real], tR: Matrix[Real]) => Matrix[Real][]