Felsenstein's pruning algorithm
InductiveRooted binary tree with transition weights#✓fully proved
A rooted binary tree with leaf labels L; an internal node node P l Q r carries the
transition weights P and Q (from the node's state to the child's state) on the edges to its
left child l and right child r.
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
Used by 62
maxPrune bounds the weight of every labeling · Nonnegativity of labeling weights · The traced labeling attains maxPrune · Likelihood of an alignment of independent columns · The PhyloCSF score · The published PhyloCSF score in decibans · Deciban score as a rescaled natural-log score · The score is the log-likelihood ratio of the alignment · Score threshold test for calling an alignment coding · Likelihood of one alignment column · Site likelihood by Felsenstein's pruning algorithm · PhyloCSF's score threshold test is most powerful for unnormalized weights · Likelihood is invariant under swapping root subtrees · The root can be pushed to the end of its edge · Pulley principle, rerooting · Pulley principle, sliding · Nonnegativity of site pattern probabilities · Partial likelihoods are invariant under swapping subtrees · Four-taxon quartet tree model · Rooted quartet with unit costs · True split against third split frequency difference · Wrong split against third split frequency difference · Felsenstein (1978), the exact comparison · Site pattern probabilities sum to one · Labeling agrees with the observed leaf states · Total substitution cost of a labeling · Sankoff's cost is attained · Fitch's algorithm · Fitch's algorithm computes the small-parsimony score · Fitch's root set is the set of optimal root states · Tree with unit costs on every edge · Sankoff's algorithm · Sankoff's algorithm computes the small-parsimony cost · Sankoff's cost is a lower bound · Sankoff's recursion at a leaf · Sankoff's recursion at an internal vertex · Tropical weight of a labeling equals its edge costDefinitionNumber of internal nodes of a tree#✓fully proved
The number of internal nodes.
def numInternal : Tree L S R → ℕ
| leaf _ => 0
| node _ l _ r => numInternal l + numInternal r + 1
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
Uses 1 · Used by 1
DefinitionNumber of leaves of a tree#✓fully proved
The number of leaves.
def numLeaves : Tree L S R → ℕ
| leaf _ => 1
| node _ l _ r => numLeaves l + numLeaves r
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
Uses 1
DefinitionLabeling of the non-root nodes of a tree#✓fully proved
A labeling of the non-root nodes of a tree by states: at every internal node, the states of its two children and labelings of the two subtrees.
def Labeling : Tree L S R → Type v
| leaf _ => PUnit
| node _ l _ r => (S × Labeling l) × (S × Labeling r)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
Uses 1 · Used by 20
maxPrune bounds the weight of every labeling · Nonnegativity of labeling weights · The traced labeling attains maxPrune · Labeling agrees with the observed leaf states · Total substitution cost of a labeling · Sankoff's cost is attained · Sankoff's algorithm computes the small-parsimony cost · Sankoff's cost is a lower bound · Tropical weight of a labeling equals its edge costTheoremNumber of labelings of a tree#✓fully proved
There are |S| ^ (2 · #internal nodes) labelings (one state for each non-root node), so the
brute-force sum bruteLik has exponentially many terms.
theorem card_labeling [Fintype S] :
∀ t : Tree L S R, Fintype.card (Labeling t) = Fintype.card S ^ (2 * t.numInternal)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def Labeling : Tree L S R → Type v
| leaf _ => PUnit
| node _ l _ r => (S × Labeling l) × (S × Labeling r)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:101
DefinitionWeight of a tree labeling#✓fully proved
The weight of a labeling given root state s: the product over all edges of the transition
weight from the parent's state to the child's state, times the leaf weight obs l at the state
of every leaf l.
def weight : (t : Tree L S R) → S → Labeling t → R
| leaf l, s, _ => obs l s
| node P l Q r, s, z =>
(P s z.1.1 * weight l z.1.1 z.1.2) * (Q s z.2.1 * weight r z.2.1 z.2.2)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def Labeling : Tree L S R → Type v
| leaf _ => PUnit
| node _ l _ r => (S × Labeling l) × (S × Labeling r)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:101
Uses 2 · Used by 11
maxPrune bounds the weight of every labeling · Nonnegativity of labeling weights · The traced labeling attains maxPrune · Sankoff's algorithm computes the small-parsimony cost · Tropical weight of a labeling equals its edge costDefinitionBrute-force likelihood given the root state#✓fully proved
The likelihood of the leaf data conditioned on root state s, by brute force: the sum of
the weights of all labelings of the non-root nodes.
def bruteLik (t : Tree L S R) (s : S) : R :=
∑ x : Labeling t, weight obs t s x
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def Labeling : Tree L S R → Type v
| leaf _ => PUnit
| node _ l _ r => (S × Labeling l) × (S × Labeling r)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:101
def weight : (t : Tree L S R) → S → Labeling t → R
| leaf l, s, _ => obs l s
| node P l Q r, s, z =>
(P s z.1.1 * weight l z.1.1 z.1.2) * (Q s z.2.1 * weight r z.2.1 z.2.2)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:134
Uses 3 · Used by 7
DefinitionSite likelihood of a phylogenetic tree#✓fully proved
The site likelihood with root distribution π: ∑ s, π s * bruteLik obs t s.
def likelihood (t : Tree L S R) (π : S → R) : R :=
∑ s, π s * bruteLik obs t s
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def bruteLik (t : Tree L S R) (s : S) : R :=
∑ x : Labeling t, weight obs t s x
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:143
Uses 2 · Used by 14
DefinitionFelsenstein's pruning recursion#✓fully proved
Felsenstein's pruning recursion: the partial likelihood of the subtree t given state s
at its root.
def prune : Tree L S R → S → R
| leaf l, s => obs l s
| node P l Q r, s => (∑ a, P s a * prune l a) * (∑ b, Q s b * prune r b)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
Uses 1 · Used by 21
TheoremBrute-force likelihood at a leaf#✓fully proved
At a leaf, the brute-force likelihood is the leaf weight.
theorem bruteLik_leaf (l : L) (s : S) : bruteLik obs (leaf l) s = obs l s
def bruteLik (t : Tree L S R) (s : S) : R :=
∑ x : Labeling t, weight obs t s x
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:143
Uses 3 · Used by 1
TheoremBrute-force likelihood factors over subtrees#✓fully proved
The brute-force likelihood factors over the two subtrees of the root (the distributive law behind pruning).
theorem bruteLik_node (P Q : S → S → R) (l r : Tree L S R) (s : S) :
bruteLik obs (node P l Q r) s =
(∑ a, P s a * bruteLik obs l a) * (∑ b, Q s b * bruteLik obs r b)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def bruteLik (t : Tree L S R) (s : S) : R :=
∑ x : Labeling t, weight obs t s x
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:143
TheoremFelsenstein's pruning algorithm computes the likelihood conditioned on the root state#✓fully proved
Felsenstein's pruning algorithm computes the likelihood conditioned on the root state.
theorem prune_eq_bruteLik : ∀ (t : Tree L S R) (s : S), prune obs t s = bruteLik obs t s
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def prune : Tree L S R → S → R
| leaf l, s => obs l s
| node P l Q r, s => (∑ a, P s a * prune l a) * (∑ b, Q s b * prune r b)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:152
def bruteLik (t : Tree L S R) (s : S) : R :=
∑ x : Labeling t, weight obs t s x
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:143
Uses 5 · Used by 2
TheoremThe site likelihood by pruning#✓fully proved
likelihood obs t π = ∑ s, π s * prune obs t s.
theorem likelihood_eq_sum_prune (t : Tree L S R) (π : S → R) :
likelihood obs t π = ∑ s, π s * prune obs t s
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def likelihood (t : Tree L S R) (π : S → R) : R :=
∑ s, π s * bruteLik obs t s
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:147
def prune : Tree L S R → S → R
| leaf l, s => obs l s
| node P l Q r, s => (∑ a, P s a * prune l a) * (∑ b, Q s b * prune r b)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:152
Uses 5 · Used by 9
The tabulated algorithm
DefinitionTabulated Felsenstein pruning algorithm#✓fully proved
Felsenstein's pruning algorithm, tabulated on the states Fin n: the vector of partial
likelihoods of each subtree is computed once, with O(n²) operations per internal node.
def pruneTab : Tree L (Fin n) R → Vector R n
| leaf l => Vector.ofFn (obs l)
| node P l Q r =>
let u := pruneTab l
let v := pruneTab r
Vector.ofFn fun s => (∑ a, P s a * u[a]) * (∑ b, Q s b * v[b])
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
Uses 1 · Used by 2
TheoremTabulated pruning computes the pruning recursion#✓fully proved
The tabulated algorithm computes the pruning recursion.
theorem pruneTab_get : ∀ (t : Tree L (Fin n) R) (s : Fin n),
(pruneTab obs t)[s] = prune obs t s
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def pruneTab : Tree L (Fin n) R → Vector R n
| leaf l => Vector.ofFn (obs l)
| node P l Q r =>
let u := pruneTab l
let v := pruneTab r
Vector.ofFn fun s => (∑ a, P s a * u[a]) * (∑ b, Q s b * v[b])
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:195
def prune : Tree L S R → S → R
| leaf l, s => obs l s
| node P l Q r, s => (∑ a, P s a * prune l a) * (∑ b, Q s b * prune r b)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:152
Uses 3 · Used by 1
TheoremSite likelihood from tabulated partial likelihoods#✓fully proved
The site likelihood from the tabulated partial likelihoods at the root.
theorem likelihood_eq_sum_pruneTab (t : Tree L (Fin n) R) (π : Fin n → R) :
likelihood obs t π = ∑ s, π s * (pruneTab obs t)[s]
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def likelihood (t : Tree L S R) (π : S → R) : R :=
∑ s, π s * bruteLik obs t s
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:147
def pruneTab : Tree L (Fin n) R → Vector R n
| leaf l => Vector.ofFn (obs l)
| node P l Q r =>
let u := pruneTab l
let v := pruneTab r
Vector.ofFn fun s => (∑ a, P s a * u[a]) * (∑ b, Q s b * v[b])
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:195
Independent sites
TheoremIndependent sites#✓fully proved
For an alignment whose sites k : ι evolve independently along the
same tree with leaf data obs k, the joint likelihood (the sum over all choices of a root state
and a labeling at every site of the product of the per-site weights) is the product of the
per-site likelihoods.
theorem sum_prod_siteWeight_eq_prod_likelihood (obs : ι → L → S → R) (t : Tree L S R)
(π : S → R) :
∑ σ : ι → S × Labeling t, ∏ k, π (σ k).1 * weight (obs k) t (σ k).1 (σ k).2 =
∏ k, likelihood (obs k) t π
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def Labeling : Tree L S R → Type v
| leaf _ => PUnit
| node _ l _ r => (S × Labeling l) × (S × Labeling r)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:101
def weight : (t : Tree L S R) → S → Labeling t → R
| leaf l, s, _ => obs l s
| node P l Q r, s, z =>
(P s z.1.1 * weight l z.1.1 z.1.2) * (Q s z.2.1 * weight r z.2.1 z.2.2)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:134
def likelihood (t : Tree L S R) (π : S → R) : R :=
∑ s, π s * bruteLik obs t s
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:147
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.