Position weight matrices
DefinitionScore of a site under a position weight matrix#✓fully proved
The score ∑ᵢ W i (s i) of a site s of width w under a position weight matrix W.
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
Used by 13
DefinitionSite likelihood under a column-independent model#✓fully proved
The likelihood ∏ᵢ p i (s i) of a site under the product (column-independent) site model
p.
Used by 10
DefinitionBackground likelihood of a sequence#✓fully proved
The likelihood ∏ₖ q (x k) of a sequence of length m under the background of independent
letters with law q.
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
Used by 14
DefinitionLog-odds matrix of a site model#✓fully proved
The log-odds matrix log (p i b / q b) of a site model against a background (natural
logarithm).
TheoremThe log-odds score is a log-likelihood ratio#✓fully proved
The log-odds score is a log-likelihood ratio (Staden 1989; Stormo 2000): for positive
site model and background, score (logOdds p q) s = log (siteLik p s / bgLik q s).
theorem score_logOdds {p : Fin w → α → ℝ} {q : α → ℝ} (hp : ∀ i b, 0 < p i b)
(hq : ∀ b, 0 < q b) (s : Fin w → α) :
score (logOdds p q) s = log (siteLik p s / bgLik q s)
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
noncomputable def logOdds (p : Fin w → α → ℝ) (q : α → ℝ) : Fin w → α → ℝ :=
fun i b => log (p i b / q b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:118
def siteLik (p : Fin w → α → ℝ) (s : Fin w → α) : ℝ := ∏ i, p i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:110
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
CSLibExt/Bioinformatics/Motifs/PWM.lean:114
TheoremProduct site likelihoods form a distribution#✓fully proved
A product of column distributions is a distribution on sites.
theorem sum_siteLik {p : Fin w → α → ℝ} (hp : ∀ i, IsDist (p i)) :
∑ s, siteLik p s = 1
def IsDist (q : Z → ℝ) : Prop := (∀ z, 0 ≤ q z) ∧ ∑ z, q z = 1
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:68
def siteLik (p : Fin w → α → ℝ) (s : Fin w → α) : ℝ := ∏ i, p i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:110
TheoremBackground likelihoods form a distribution#✓fully proved
The background law of independent letters is a distribution on sequences.
theorem sum_bgLik {m : ℕ} {q : α → ℝ} (hq : IsDist q) : ∑ x : Fin m → α, bgLik q x = 1
def IsDist (q : Z → ℝ) : Prop := (∀ z, 0 ≤ q z) ∧ ∑ z, q z = 1
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:68
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
CSLibExt/Bioinformatics/Motifs/PWM.lean:114
Uses 2
TheoremThresholding the log-odds score is most powerful#✓fully proved
Thresholding the log-odds score is most powerful (Neyman–Pearson): a test φ of the
background (null) against the site model whose background size is at most that of the
threshold test score > t has at most its power.
theorem sum_mul_siteLik_le_of_sum_mul_bgLik_le {p : Fin w → α → ℝ} {q : α → ℝ}
(hp : ∀ i b, 0 < p i b) (hq : ∀ b, 0 < q b) (t : ℝ) (φ : (Fin w → α) → ℝ)
(hφ0 : ∀ s, 0 ≤ φ s) (hφ1 : ∀ s, φ s ≤ 1)
(hsize : ∑ s, φ s * bgLik q s ≤
∑ s, (if t < score (logOdds p q) s then 1 else 0) * bgLik q s) :
∑ s, φ s * siteLik p s ≤
∑ s, (if t < score (logOdds p q) s then 1 else 0) * siteLik p s
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
CSLibExt/Bioinformatics/Motifs/PWM.lean:114
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
noncomputable def logOdds (p : Fin w → α → ℝ) (q : α → ℝ) : Fin w → α → ℝ :=
fun i b => log (p i b / q b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:118
def siteLik (p : Fin w → α → ℝ) (s : Fin w → α) : ℝ := ∏ i, p i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:110
DefinitionInformation content of a position weight matrix column#✓fully proved
The information content ∑_b p b log₂ (p b / q b) (in bits) of a PWM column p against
the background q (Schneider et al. 1986). Letters with p b = 0 contribute 0.
Used by 6
TheoremInformation content is a Kullback–Leibler divergence#✓fully proved
For laws P ≪ Q, the information
content of P against Q is KL(P ‖ Q) / log 2, Mathlib's klDiv in bits.
theorem infoContent_eq_klDiv [MeasurableSpace α] [MeasurableSingletonClass α] (P Q : PMF α)
(hPQ : ∀ a, Q a = 0 → P a = 0) :
infoContent (fun b => (P b).toReal) (fun b => (Q b).toReal) =
(InformationTheory.klDiv P.toMeasure Q.toMeasure).toReal / log 2
noncomputable def infoContent (p q : α → ℝ) : ℝ := (∑ b, p b * log (p b / q b)) / log 2
CSLibExt/Bioinformatics/Motifs/PWM.lean:188
Uses 2
TheoremInformation content is nonnegative#✓fully proved
Information content is nonnegative (Gibbs' inequality) for a column distribution and a positive background distribution.
theorem infoContent_nonneg {p q : α → ℝ} (hp : IsDist p) (hq : IsDist q)
(hq0 : ∀ b, 0 < q b) : 0 ≤ infoContent p q
def IsDist (q : Z → ℝ) : Prop := (∀ z, 0 ≤ q z) ∧ ∑ z, q z = 1
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:68
noncomputable def infoContent (p q : α → ℝ) : ℝ := (∑ b, p b * log (p b / q b)) / log 2
CSLibExt/Bioinformatics/Motifs/PWM.lean:188
TheoremInformation content against the uniform background#✓fully proved
Information content against the uniform background (Schneider et al. 1986):
log₂ |α| - H(p), the maximal entropy minus the column entropy.
theorem infoContent_uniform [Nonempty α] (P : PMF α) :
infoContent (fun b => (P b).toReal) (fun _ => ((Fintype.card α : ℝ))⁻¹) =
logb 2 (Fintype.card α) - InformationTheory.shannonEntropy P
noncomputable def infoContent (p q : α → ℝ) : ℝ := (∑ b, p b * log (p b / q b)) / log 2
CSLibExt/Bioinformatics/Motifs/PWM.lean:188
noncomputable def shannonEntropy {α : Type*} [Fintype α] (p : PMF α) : ℝ :=
(∑ a, Real.negMulLog (p a).toReal) / Real.log 2
MathlibExt/InformationTheory/FiniteEntropy.lean:44
Uses 2 · Used by 1
TheoremInformation content is at most the log of the alphabet size#✓fully proved
Against the uniform background, a column carries at most log₂ |α| bits.
theorem infoContent_uniform_le [Nonempty α] (P : PMF α) :
infoContent (fun b => (P b).toReal) (fun _ => ((Fintype.card α : ℝ))⁻¹) ≤
logb 2 (Fintype.card α)
noncomputable def infoContent (p q : α → ℝ) : ℝ := (∑ b, p b * log (p b / q b)) / log 2
CSLibExt/Bioinformatics/Motifs/PWM.lean:188
Uses 3 · Used by 1
TheoremA DNA column carries at most two bits#✓fully proved
For a four-letter alphabet (DNA) and the uniform background, a column carries between 0
and 2 bits.
theorem infoContent_uniform_le_two [Nonempty α] (h4 : Fintype.card α = 4) (P : PMF α) :
infoContent (fun b => (P b).toReal) (fun _ => ((Fintype.card α : ℝ))⁻¹) ≤ 2
noncomputable def infoContent (p q : α → ℝ) : ℝ := (∑ b, p b * log (p b / q b)) / log 2
CSLibExt/Bioinformatics/Motifs/PWM.lean:188
Uses 2
TheoremThe expected log-odds score is the total information content#✓fully proved
Under the site model,
E[score] = log 2 · ∑ᵢ IC(pᵢ ‖ q). This is an identity for every q (both sides use the same
logarithms); it is an expected log-likelihood ratio for a positive background.
theorem sum_siteLik_mul_score_logOdds {p : Fin w → α → ℝ} {q : α → ℝ}
(hp : ∀ i, IsDist (p i)) :
∑ s, siteLik p s * score (logOdds p q) s = log 2 * ∑ i, infoContent (p i) q
def IsDist (q : Z → ℝ) : Prop := (∀ z, 0 ≤ q z) ∧ ∑ z, q z = 1
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:68
def siteLik (p : Fin w → α → ℝ) (s : Fin w → α) : ℝ := ∏ i, p i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:110
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
noncomputable def logOdds (p : Fin w → α → ℝ) (q : α → ℝ) : Fin w → α → ℝ :=
fun i b => log (p i b / q b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:118
noncomputable def infoContent (p q : α → ℝ) : ℝ := (∑ b, p b * log (p b / q b)) / log 2
CSLibExt/Bioinformatics/Motifs/PWM.lean:188
DefinitionOne column step of the score-distribution recursion#✓fully proved
One column of the score-distribution recursion: from the distribution d of the score of
the first columns, the distribution after adding a column c with background q,
∑_b q b · (d shifted by c b).
noncomputable def scoreStep (q : α → ℝ) (d : ℤ →₀ ℝ) (c : α → ℤ) : ℤ →₀ ℝ :=
∑ b, q b • d.mapDomain (· + c b)
DefinitionBackground score distribution of an integer matrix#✓fully proved
The background distribution of the score of an integer matrix M, computed column by column
from the point mass at 0 (Staden 1989; Touzet and Varré 2007).
noncomputable def scoreDist (q : α → ℝ) (M : Fin w → α → ℤ) : ℤ →₀ ℝ :=
(List.ofFn M).foldl (scoreStep q) (Finsupp.single 0 1)
noncomputable def scoreStep (q : α → ℝ) (d : ℤ →₀ ℝ) (c : α → ℤ) : ℤ →₀ ℝ :=
∑ b, q b • d.mapDomain (· + c b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:287
Uses 1 · Used by 3
TheoremThe column recursion computes the exact score distribution#✓fully proved
scoreDist q M t is
∑_{s : score M s = t} ∏ᵢ q (s i), for every q. When q is a distribution this is the
background probability of the score t (the weights sum to 1 by sum_bgLik).
theorem scoreDist_apply (q : α → ℝ) (M : Fin w → α → ℤ) (t : ℤ) :
scoreDist q M t = ∑ s with score M s = t, bgLik q s
noncomputable def scoreDist (q : α → ℝ) (M : Fin w → α → ℤ) : ℤ →₀ ℝ :=
(List.ofFn M).foldl (scoreStep q) (Finsupp.single 0 1)
CSLibExt/Bioinformatics/Motifs/PWM.lean:292
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
CSLibExt/Bioinformatics/Motifs/PWM.lean:114
Uses 4 · Used by 1
DefinitionExact p-value of a score threshold#✓fully proved
The exact p-value of the score threshold t, summed over the computed distribution.
noncomputable def pValue (q : α → ℝ) (M : Fin w → α → ℤ) (t : ℤ) : ℝ :=
∑ u ∈ (scoreDist q M).support with t ≤ u, scoreDist q M u
noncomputable def scoreDist (q : α → ℝ) (M : Fin w → α → ℤ) : ℤ →₀ ℝ :=
(List.ofFn M).foldl (scoreStep q) (Finsupp.single 0 1)
CSLibExt/Bioinformatics/Motifs/PWM.lean:292
Uses 1 · Used by 1
TheoremExact p-values#✓fully proved
pValue q M t = ∑_{s : score M s ≥ t} ∏ᵢ q (s i), the background
probability P_q(score M ≥ t) when q is a distribution.
theorem pValue_eq (q : α → ℝ) (M : Fin w → α → ℤ) (t : ℤ) :
pValue q M t = ∑ s with t ≤ score M s, bgLik q s
noncomputable def pValue (q : α → ℝ) (M : Fin w → α → ℤ) (t : ℤ) : ℝ :=
∑ u ∈ (scoreDist q M).support with t ≤ u, scoreDist q M u
CSLibExt/Bioinformatics/Motifs/PWM.lean:331
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
CSLibExt/Bioinformatics/Motifs/PWM.lean:114
TheoremScaling and rounding error#✓fully proved
Rounding c · W to integers changes the rescaled score of
every site by at most w / (2c).
theorem abs_score_sub_score_round_le (W : Fin w → α → ℝ) {c : ℝ} (hc : 0 < c)
(s : Fin w → α) :
|score W s - ((score (fun i b => round (c * W i b)) s : ℤ) : ℝ) / c| ≤ w / (2 * c)
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
Uses 1
DefinitionColumn partition function of an energy matrix#✓fully proved
The column partition function Z = ∑_b q b e^{-λ ε b} of energies ε at inverse
temperature λ.
noncomputable def partitionFn (q ε : α → ℝ) (lam : ℝ) : ℝ := ∑ b, q b * exp (-lam * ε b)
DefinitionBoltzmann position weight matrix#✓fully proved
The Boltzmann PWM q b e^{-λ ε i b} / Zᵢ of an energy matrix ε.
noncomputable def boltzmannPWM (q : α → ℝ) (ε : Fin w → α → ℝ) (lam : ℝ) : Fin w → α → ℝ :=
fun i b => q b * exp (-lam * ε i b) / partitionFn q (ε i) lam
noncomputable def partitionFn (q ε : α → ℝ) (lam : ℝ) : ℝ := ∑ b, q b * exp (-lam * ε b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:388
DefinitionLaw of energy-selected background sites#✓fully proved
The law of background sites selected with weight e^{-λ E(s)} for the additive energy
E s = score ε s = ∑ᵢ ε i (s i): q(s) e^{-λ E(s)} / ∑_{s'} q(s') e^{-λ E(s')}.
noncomputable def selectedLaw (q : α → ℝ) (ε : Fin w → α → ℝ) (lam : ℝ) (s : Fin w → α) : ℝ :=
bgLik q s * exp (-lam * score ε s) / ∑ s', bgLik q s' * exp (-lam * score ε s')
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
CSLibExt/Bioinformatics/Motifs/PWM.lean:114
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
Uses 2 · Used by 1
TheoremPositivity of the column partition function#✓fully proved
The partition function of a positive background is positive.
theorem partitionFn_pos [Nonempty α] {q : α → ℝ} (hq : ∀ b, 0 < q b) (ε : α → ℝ) (lam : ℝ) :
0 < partitionFn q ε lam
noncomputable def partitionFn (q ε : α → ℝ) (lam : ℝ) : ℝ := ∑ b, q b * exp (-lam * ε b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:388
Uses 1 · Used by 2
TheoremColumns of the Boltzmann matrix are distributions#✓fully proved
Each column of the Boltzmann PWM is a distribution.
theorem isDist_boltzmannPWM [Nonempty α] {q : α → ℝ} (hq : ∀ b, 0 < q b)
(ε : Fin w → α → ℝ) (lam : ℝ) (i : Fin w) : IsDist (boltzmannPWM q ε lam i)
def IsDist (q : Z → ℝ) : Prop := (∀ z, 0 ≤ q z) ∧ ∑ z, q z = 1
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:68
noncomputable def boltzmannPWM (q : α → ℝ) (ε : Fin w → α → ℝ) (lam : ℝ) : Fin w → α → ℝ :=
fun i b => q b * exp (-lam * ε i b) / partitionFn q (ε i) lam
CSLibExt/Bioinformatics/Motifs/PWM.lean:391
TheoremBerg–von Hippel#✓fully proved
Boltzmann selection of background sites with an additive energy yields
the product site model with columns boltzmannPWM. This is an identity for every q
(both sides vanish when some Zᵢ = 0); it is a statement about laws for positive q.
theorem selectedLaw_eq_siteLik (q : α → ℝ) (ε : Fin w → α → ℝ) (lam : ℝ) (s : Fin w → α) :
selectedLaw q ε lam s = siteLik (boltzmannPWM q ε lam) s
noncomputable def selectedLaw (q : α → ℝ) (ε : Fin w → α → ℝ) (lam : ℝ) (s : Fin w → α) : ℝ :=
bgLik q s * exp (-lam * score ε s) / ∑ s', bgLik q s' * exp (-lam * score ε s')
CSLibExt/Bioinformatics/Motifs/PWM.lean:396
def siteLik (p : Fin w → α → ℝ) (s : Fin w → α) : ℝ := ∏ i, p i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:110
noncomputable def boltzmannPWM (q : α → ℝ) (ε : Fin w → α → ℝ) (lam : ℝ) : Fin w → α → ℝ :=
fun i b => q b * exp (-lam * ε i b) / partitionFn q (ε i) lam
CSLibExt/Bioinformatics/Motifs/PWM.lean:391
TheoremLog-odds are affine in the energies#✓fully proved
log (p i b / q b) = -λ ε i b - log Zᵢ for the
Boltzmann PWM.
theorem logOdds_boltzmannPWM [Nonempty α] {q : α → ℝ} (hq : ∀ b, 0 < q b)
(ε : Fin w → α → ℝ) (lam : ℝ) (i : Fin w) (b : α) :
logOdds (boltzmannPWM q ε lam) q i b = -lam * ε i b - log (partitionFn q (ε i) lam)
noncomputable def logOdds (p : Fin w → α → ℝ) (q : α → ℝ) : Fin w → α → ℝ :=
fun i b => log (p i b / q b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:118
noncomputable def boltzmannPWM (q : α → ℝ) (ε : Fin w → α → ℝ) (lam : ℝ) : Fin w → α → ℝ :=
fun i b => q b * exp (-lam * ε i b) / partitionFn q (ε i) lam
CSLibExt/Bioinformatics/Motifs/PWM.lean:391
noncomputable def partitionFn (q ε : α → ℝ) (lam : ℝ) : ℝ := ∑ b, q b * exp (-lam * ε b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:388
Uses 4 · Used by 1
TheoremLog-odds score of a selected site is its scaled energy up to a constant#✓fully proved
The log-odds score of a selected site is -λ E(s) up to the constant ∑ᵢ log Zᵢ.
theorem score_logOdds_boltzmannPWM [Nonempty α] {q : α → ℝ} (hq : ∀ b, 0 < q b)
(ε : Fin w → α → ℝ) (lam : ℝ) (s : Fin w → α) :
score (logOdds (boltzmannPWM q ε lam) q) s =
-lam * score ε s - ∑ i, log (partitionFn q (ε i) lam)
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
noncomputable def logOdds (p : Fin w → α → ℝ) (q : α → ℝ) : Fin w → α → ℝ :=
fun i b => log (p i b / q b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:118
noncomputable def boltzmannPWM (q : α → ℝ) (ε : Fin w → α → ℝ) (lam : ℝ) : Fin w → α → ℝ :=
fun i b => q b * exp (-lam * ε i b) / partitionFn q (ε i) lam
CSLibExt/Bioinformatics/Motifs/PWM.lean:391
noncomputable def partitionFn (q ε : α → ℝ) (lam : ℝ) : ℝ := ∑ b, q b * exp (-lam * ε b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:388
DefinitionSequence position of a motif column#✓fully proved
The position j + i of motif column i for a motif starting at j, in a sequence of
length n + w (so n + 1 possible starts).
DefinitionWindow of a sequence at a given start#✓fully proved
The window of width w of x starting at j.
def window (x : Fin (n + w) → α) (j : Fin (n + 1)) : Fin w → α := fun i => x (sitePos j i)
def sitePos (j : Fin (n + 1)) (i : Fin w) : Fin (n + w) := ⟨j + i, by omega⟩
CSLibExt/Bioinformatics/Motifs/PWM.lean:456
Uses 1 · Used by 5
DefinitionLikelihood ratio of a motif window#✓fully proved
The likelihood ratio of the window at j under the site model θ against the background
q, and 1 when there is no motif occurrence.
noncomputable def windowRatio (q : α → ℝ) (θ : Fin w → α → ℝ) (x : Fin (n + w) → α) :
Option (Fin (n + 1)) → ℝ
| none => 1
| some j => siteLik θ (window x j) / bgLik q (window x j)
def siteLik (p : Fin w → α → ℝ) (s : Fin w → α) : ℝ := ∏ i, p i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:110
def window (x : Fin (n + w) → α) (j : Fin (n + 1)) : Fin w → α := fun i => x (sitePos j i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:459
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
CSLibExt/Bioinformatics/Motifs/PWM.lean:114
Uses 3 · Used by 6
DefinitionJoint likelihood of a sequence and a motif occurrence#✓fully proved
The joint likelihood of a sequence x and a latent occurrence z with prior prior z and
start start z (none: no occurrence): background letters outside the window, site-model letters
inside. One occurrence per sequence (OOPS) is Z = Fin (n + 1), start = some, prior uniform;
zero or one (ZOOPS) is Z = Option (Fin (n + 1)), start = id, prior none = 1 - γ and
prior (some j) = γ / (n + 1) for a fixed γ. The background q is a fixed parameter.
noncomputable def motifJoint (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1)))
(θ : Fin w → α → ℝ) (x : Fin (n + w) → α) (z : Z) : ℝ :=
prior z * bgLik q x * windowRatio q θ x (start z)
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
CSLibExt/Bioinformatics/Motifs/PWM.lean:114
noncomputable def windowRatio (q : α → ℝ) (θ : Fin w → α → ℝ) (x : Fin (n + w) → α) :
Option (Fin (n + 1)) → ℝ
| none => 1
| some j => siteLik θ (window x j) / bgLik q (window x j)
CSLibExt/Bioinformatics/Motifs/PWM.lean:463
Uses 2 · Used by 3
TheoremThe joint is the window model#✓fully proved
For a positive background and an occurrence at j, the
joint is the prior times the product of θ (k - j) inside the window and q outside.
theorem motifJoint_of_start_eq_some {q : α → ℝ} (hq : ∀ b, 0 < q b) (prior : Z → ℝ)
(start : Z → Option (Fin (n + 1))) (θ : Fin w → α → ℝ) (x : Fin (n + w) → α) {z : Z}
{j : Fin (n + 1)} (hz : start z = some j) :
motifJoint q prior start θ x z = prior z * ∏ k : Fin (n + w),
if h : (j : ℕ) ≤ k ∧ (k : ℕ) < j + w then θ ⟨k - j, by omega⟩ (x k) else q (x k)
noncomputable def motifJoint (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1)))
(θ : Fin w → α → ℝ) (x : Fin (n + w) → α) (z : Z) : ℝ :=
prior z * bgLik q x * windowRatio q θ x (start z)
CSLibExt/Bioinformatics/Motifs/PWM.lean:473
TheoremJoint likelihood with no motif occurrence#✓fully proved
With no occurrence, the joint is the prior times the background likelihood.
theorem motifJoint_of_start_eq_none (q : α → ℝ) (prior : Z → ℝ)
(start : Z → Option (Fin (n + 1))) (θ : Fin w → α → ℝ) (x : Fin (n + w) → α) {z : Z}
(hz : start z = none) : motifJoint q prior start θ x z = prior z * bgLik q x
noncomputable def motifJoint (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1)))
(θ : Fin w → α → ℝ) (x : Fin (n + w) → α) (z : Z) : ℝ :=
prior z * bgLik q x * windowRatio q θ x (start z)
CSLibExt/Bioinformatics/Motifs/PWM.lean:473
def bgLik {m : ℕ} (q : α → ℝ) (x : Fin m → α) : ℝ := ∏ k, q (x k)
CSLibExt/Bioinformatics/Motifs/PWM.lean:114
AbbreviationPositive position weight matrices#✓fully proved
PWMs with positive entries and columns summing to 1: the EM parameter space.
abbrev PosPWM (w : ℕ) (α : Type*) [Fintype α] : Type _ :=
{θ : Fin w → α → ℝ // (∀ i b, 0 < θ i b) ∧ ∀ i, ∑ b, θ i b = 1}
Used by 8
DefinitionMotif model as an EM model#✓fully proved
The motif model as an EM model on PosPWM.
noncomputable def motifModel (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1))) :
PosPWM w α → (Fin (n + w) → α) → Z → ℝ :=
fun θ => motifJoint q prior start θ.1
abbrev PosPWM (w : ℕ) (α : Type*) [Fintype α] : Type _ :=
{θ : Fin w → α → ℝ // (∀ i b, 0 < θ i b) ∧ ∀ i, ∑ b, θ i b = 1}
CSLibExt/Bioinformatics/Motifs/PWM.lean:526
noncomputable def motifJoint (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1)))
(θ : Fin w → α → ℝ) (x : Fin (n + w) → α) (z : Z) : ℝ :=
prior z * bgLik q x * windowRatio q θ x (start z)
CSLibExt/Bioinformatics/Motifs/PWM.lean:473
Uses 2 · Used by 6
TheoremPositivity of the motif model#✓fully proved
The motif model is positive for a positive background and a positive prior.
theorem motifModel_pos {q : α → ℝ} (hq : ∀ b, 0 < q b) {prior : Z → ℝ} (hprior : ∀ z, 0 < prior z)
(start : Z → Option (Fin (n + 1))) (θ : PosPWM w α) (x : Fin (n + w) → α) (z : Z) :
0 < motifModel q prior start θ x z
abbrev PosPWM (w : ℕ) (α : Type*) [Fintype α] : Type _ :=
{θ : Fin w → α → ℝ // (∀ i b, 0 < θ i b) ∧ ∀ i, ∑ b, θ i b = 1}
CSLibExt/Bioinformatics/Motifs/PWM.lean:526
noncomputable def motifModel (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1))) :
PosPWM w α → (Fin (n + w) → α) → Z → ℝ :=
fun θ => motifJoint q prior start θ.1
CSLibExt/Bioinformatics/Motifs/PWM.lean:530
Uses 6 · Used by 2
TheoremThe E-step in closed form#✓fully proved
The posterior of the occurrence z is proportional to its
prior times the likelihood ratio of its window (Lawrence and Reilly 1990; Bailey and Elkan
1995).
theorem posterior_motifModel {q : α → ℝ} (hq : ∀ b, 0 < q b) (prior : Z → ℝ)
(start : Z → Option (Fin (n + 1))) (θ : PosPWM w α) (x : Fin (n + w) → α) (z : Z) :
posterior (motifModel q prior start) θ x z =
prior z * windowRatio q θ.1 x (start z) /
∑ z', prior z' * windowRatio q θ.1 x (start z')
abbrev PosPWM (w : ℕ) (α : Type*) [Fintype α] : Type _ :=
{θ : Fin w → α → ℝ // (∀ i b, 0 < θ i b) ∧ ∀ i, ∑ b, θ i b = 1}
CSLibExt/Bioinformatics/Motifs/PWM.lean:526
noncomputable def posterior (p : Θ → X → Z → ℝ) (θ : Θ) (x : X) (z : Z) : ℝ :=
p θ x z / marginal p θ x
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:112
noncomputable def motifModel (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1))) :
PosPWM w α → (Fin (n + w) → α) → Z → ℝ :=
fun θ => motifJoint q prior start θ.1
CSLibExt/Bioinformatics/Motifs/PWM.lean:530
noncomputable def windowRatio (q : α → ℝ) (θ : Fin w → α → ℝ) (x : Fin (n + w) → α) :
Option (Fin (n + 1)) → ℝ
| none => 1
| some j => siteLik θ (window x j) / bgLik q (window x j)
CSLibExt/Bioinformatics/Motifs/PWM.lean:463
DefinitionExpected letter counts in motif columns#✓fully proved
The expected count of letter b in motif column i under the posteriors at θ:
∑ₘ ∑_z P(z | xₘ, θ) [start z = some j ∧ xₘ (j + i) = b].
noncomputable def expectedCounts (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1)))
(xs : Fin N → Fin (n + w) → α) (θ : PosPWM w α) (i : Fin w) (b : α) : ℝ :=
∑ m, ∑ z, posterior (motifModel q prior start) θ (xs m) z *
(match start z with
| none => 0
| some j => if xs m (sitePos j i) = b then 1 else 0)
abbrev PosPWM (w : ℕ) (α : Type*) [Fintype α] : Type _ :=
{θ : Fin w → α → ℝ // (∀ i b, 0 < θ i b) ∧ ∀ i, ∑ b, θ i b = 1}
CSLibExt/Bioinformatics/Motifs/PWM.lean:526
noncomputable def posterior (p : Θ → X → Z → ℝ) (θ : Θ) (x : X) (z : Z) : ℝ :=
p θ x z / marginal p θ x
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:112
noncomputable def motifModel (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1))) :
PosPWM w α → (Fin (n + w) → α) → Z → ℝ :=
fun θ => motifJoint q prior start θ.1
CSLibExt/Bioinformatics/Motifs/PWM.lean:530
def sitePos (j : Fin (n + 1)) (i : Fin w) : Fin (n + w) := ⟨j + i, by omega⟩
CSLibExt/Bioinformatics/Motifs/PWM.lean:456
DefinitionCoverage condition for motif columns#✓fully proved
Every letter can occur in every motif column: for each column i and letter b some
sequence has b at offset i of some possible occurrence. This keeps the M-step positive.
TheoremPositivity of expected motif counts#✓fully proved
Under Covers, every expected count is positive.
theorem expectedCounts_pos [Nonempty Z] {q : α → ℝ} (hq : ∀ b, 0 < q b) {prior : Z → ℝ}
(hprior : ∀ z, 0 < prior z) {start : Z → Option (Fin (n + 1))}
{xs : Fin N → Fin (n + w) → α} (hcov : Covers start xs) (θ : PosPWM w α) (i : Fin w)
(b : α) : 0 < expectedCounts q prior start xs θ i b
def Covers (start : Z → Option (Fin (n + 1))) (xs : Fin N → Fin (n + w) → α) : Prop :=
∀ (i : Fin w) (b : α), ∃ m z j, start z = some j ∧ xs m (sitePos j i) = b
CSLibExt/Bioinformatics/Motifs/PWM.lean:576
abbrev PosPWM (w : ℕ) (α : Type*) [Fintype α] : Type _ :=
{θ : Fin w → α → ℝ // (∀ i b, 0 < θ i b) ∧ ∀ i, ∑ b, θ i b = 1}
CSLibExt/Bioinformatics/Motifs/PWM.lean:526
noncomputable def expectedCounts (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1)))
(xs : Fin N → Fin (n + w) → α) (θ : PosPWM w α) (i : Fin w) (b : α) : ℝ :=
∑ m, ∑ z, posterior (motifModel q prior start) θ (xs m) z *
(match start z with
| none => 0
| some j => if xs m (sitePos j i) = b then 1 else 0)
CSLibExt/Bioinformatics/Motifs/PWM.lean:567
Uses 8 · Used by 2
DefinitionM-step for position weight matrices#✓fully proved
The M-step: normalized expected letter counts, θ' i b = c i b / ∑_{b'} c i b'.
noncomputable def mStep [Nonempty α] [Nonempty Z] {q : α → ℝ} (hq : ∀ b, 0 < q b) {prior : Z → ℝ}
(hprior : ∀ z, 0 < prior z) {start : Z → Option (Fin (n + 1))}
{xs : Fin N → Fin (n + w) → α} (hcov : Covers start xs) (θ : PosPWM w α) : PosPWM w α :=
⟨fun i b => expectedCounts q prior start xs θ i b /
∑ b', expectedCounts q prior start xs θ i b',
fun i b => div_pos (expectedCounts_pos hq hprior hcov θ i b)
(Finset.sum_pos (fun b' _ => expectedCounts_pos hq hprior hcov θ i b')
⟨b, Finset.mem_univ b⟩),
fun i => by
rw [← Finset.sum_div, div_self (Finset.sum_pos
(fun b' _ => expectedCounts_pos hq hprior hcov θ i b') ⟨Classical.arbitrary α,
Finset.mem_univ _⟩).ne']⟩
def Covers (start : Z → Option (Fin (n + 1))) (xs : Fin N → Fin (n + w) → α) : Prop :=
∀ (i : Fin w) (b : α), ∃ m z j, start z = some j ∧ xs m (sitePos j i) = b
CSLibExt/Bioinformatics/Motifs/PWM.lean:576
abbrev PosPWM (w : ℕ) (α : Type*) [Fintype α] : Type _ :=
{θ : Fin w → α → ℝ // (∀ i b, 0 < θ i b) ∧ ∀ i, ∑ b, θ i b = 1}
CSLibExt/Bioinformatics/Motifs/PWM.lean:526
noncomputable def expectedCounts (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1)))
(xs : Fin N → Fin (n + w) → α) (θ : PosPWM w α) (i : Fin w) (b : α) : ℝ :=
∑ m, ∑ z, posterior (motifModel q prior start) θ (xs m) z *
(match start z with
| none => 0
| some j => if xs m (sitePos j i) = b then 1 else 0)
CSLibExt/Bioinformatics/Motifs/PWM.lean:567
theorem expectedCounts_pos [Nonempty Z] {q : α → ℝ} (hq : ∀ b, 0 < q b) {prior : Z → ℝ}
(hprior : ∀ z, 0 < prior z) {start : Z → Option (Fin (n + 1))}
{xs : Fin N → Fin (n + w) → α} (hcov : Covers start xs) (θ : PosPWM w α) (i : Fin w)
(b : α) : 0 < expectedCounts q prior start xs θ i b
CSLibExt/Bioinformatics/Motifs/PWM.lean:580
TheoremThe M-step maximizes the EM objective#✓fully proved
The M-step maximizes the EM objective over PWMs with positive entries and normalized
columns: for every θ', Q(θ' | θ) ≤ Q(mStep θ | θ) (Gibbs' inequality per column).
theorem emQ_le_emQ_mStep [Nonempty α] [Nonempty Z] {q : α → ℝ} (hq : ∀ b, 0 < q b) {prior : Z → ℝ}
(hprior : ∀ z, 0 < prior z) {start : Z → Option (Fin (n + 1))} {xs : Fin N → Fin (n + w) → α}
(hcov : Covers start xs) (θ θ' : PosPWM w α) :
emQ (motifModel q prior start) xs θ' θ ≤
emQ (motifModel q prior start) xs (mStep hq hprior hcov θ) θ
def Covers (start : Z → Option (Fin (n + 1))) (xs : Fin N → Fin (n + w) → α) : Prop :=
∀ (i : Fin w) (b : α), ∃ m z j, start z = some j ∧ xs m (sitePos j i) = b
CSLibExt/Bioinformatics/Motifs/PWM.lean:576
abbrev PosPWM (w : ℕ) (α : Type*) [Fintype α] : Type _ :=
{θ : Fin w → α → ℝ // (∀ i b, 0 < θ i b) ∧ ∀ i, ∑ b, θ i b = 1}
CSLibExt/Bioinformatics/Motifs/PWM.lean:526
noncomputable def emQ (p : Θ → X → Z → ℝ) (xs : Fin N → X) (θ' θ : Θ) : ℝ :=
∑ n, ∑ z, posterior p θ (xs n) z * log (p θ' (xs n) z)
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:122
noncomputable def motifModel (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1))) :
PosPWM w α → (Fin (n + w) → α) → Z → ℝ :=
fun θ => motifJoint q prior start θ.1
CSLibExt/Bioinformatics/Motifs/PWM.lean:530
noncomputable def mStep [Nonempty α] [Nonempty Z] {q : α → ℝ} (hq : ∀ b, 0 < q b) {prior : Z → ℝ}
(hprior : ∀ z, 0 < prior z) {start : Z → Option (Fin (n + 1))}
{xs : Fin N → Fin (n + w) → α} (hcov : Covers start xs) (θ : PosPWM w α) : PosPWM w α :=
⟨fun i b => expectedCounts q prior start xs θ i b /
∑ b', expectedCounts q prior start xs θ i b',
fun i b => div_pos (expectedCounts_pos hq hprior hcov θ i b)
(Finset.sum_pos (fun b' _ => expectedCounts_pos hq hprior hcov θ i b')
⟨b, Finset.mem_univ b⟩),
fun i => by
rw [← Finset.sum_div, div_self (Finset.sum_pos
(fun b' _ => expectedCounts_pos hq hprior hcov θ i b') ⟨Classical.arbitrary α,
Finset.mem_univ _⟩).ne']⟩
CSLibExt/Bioinformatics/Motifs/PWM.lean:603
Uses 14 · Used by 1
TheoremThe motif likelihood is nondecreasing along the EM iterates#✓fully proved
The motif likelihood is nondecreasing along the EM iterates.
theorem logLik_iterate_mStep_monotone [Nonempty α] [Nonempty Z] {q : α → ℝ} (hq : ∀ b, 0 < q b)
{prior : Z → ℝ} (hprior : ∀ z, 0 < prior z) {start : Z → Option (Fin (n + 1))}
{xs : Fin N → Fin (n + w) → α} (hcov : Covers start xs) (θ₀ : PosPWM w α) :
Monotone fun k => logLik (motifModel q prior start) xs ((mStep hq hprior hcov)^[k] θ₀)
def Covers (start : Z → Option (Fin (n + 1))) (xs : Fin N → Fin (n + w) → α) : Prop :=
∀ (i : Fin w) (b : α), ∃ m z j, start z = some j ∧ xs m (sitePos j i) = b
CSLibExt/Bioinformatics/Motifs/PWM.lean:576
abbrev PosPWM (w : ℕ) (α : Type*) [Fintype α] : Type _ :=
{θ : Fin w → α → ℝ // (∀ i b, 0 < θ i b) ∧ ∀ i, ∑ b, θ i b = 1}
CSLibExt/Bioinformatics/Motifs/PWM.lean:526
noncomputable def logLik (p : Θ → X → Z → ℝ) (xs : Fin N → X) (θ : Θ) : ℝ :=
∑ n, log (marginal p θ (xs n))
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:108
noncomputable def motifModel (q : α → ℝ) (prior : Z → ℝ) (start : Z → Option (Fin (n + 1))) :
PosPWM w α → (Fin (n + w) → α) → Z → ℝ :=
fun θ => motifJoint q prior start θ.1
CSLibExt/Bioinformatics/Motifs/PWM.lean:530
noncomputable def mStep [Nonempty α] [Nonempty Z] {q : α → ℝ} (hq : ∀ b, 0 < q b) {prior : Z → ℝ}
(hprior : ∀ z, 0 < prior z) {start : Z → Option (Fin (n + 1))}
{xs : Fin N → Fin (n + w) → α} (hcov : Covers start xs) (θ : PosPWM w α) : PosPWM w α :=
⟨fun i b => expectedCounts q prior start xs θ i b /
∑ b', expectedCounts q prior start xs θ i b',
fun i b => div_pos (expectedCounts_pos hq hprior hcov θ i b)
(Finset.sum_pos (fun b' _ => expectedCounts_pos hq hprior hcov θ i b')
⟨b, Finset.mem_univ b⟩),
fun i => by
rw [← Finset.sum_div, div_self (Finset.sum_pos
(fun b' _ => expectedCounts_pos hq hprior hcov θ i b') ⟨Classical.arbitrary α,
Finset.mem_univ _⟩).ne']⟩
CSLibExt/Bioinformatics/Motifs/PWM.lean:603
DefinitionMoment generating function of a pair score#✓fully proved
The moment generating function ∑ₐ ∑_b pₐ p_b e^{λ s_{ab}} of a pair score under independent
letters with law p.
noncomputable def pairMGF (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) : ℝ :=
∑ a, ∑ b, p a * p b * exp (lam * s a b)
TheoremKarlin–Altschul λ#✓fully proved
Karlin–Altschul λ (Karlin and Altschul 1990): if the expected score under a positive
background distribution is negative and some score is positive, there is a unique λ > 0 with
∑ pₐ p_b e^{λ s_{ab}} = 1.
theorem existsUnique_pairMGF_eq_one {p : α → ℝ} {s : α → α → ℝ} (hp : IsDist p)
(hp0 : ∀ a, 0 < p a) (hneg : ∑ a, ∑ b, p a * p b * s a b < 0) (hpos : ∃ a b, 0 < s a b) :
∃! lam, 0 < lam ∧ pairMGF p s lam = 1
def IsDist (q : Z → ℝ) : Prop := (∀ z, 0 ≤ q z) ∧ ∑ z, q z = 1
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:68
noncomputable def pairMGF (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) : ℝ :=
∑ a, ∑ b, p a * p b * exp (lam * s a b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:708
Uses 2
DefinitionImplicit target frequencies of a score matrix#✓fully proved
The implicit target frequencies q_{ab} = pₐ p_b e^{λ s_{ab}} of a score matrix.
noncomputable def targetFreq (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) (ab : α × α) : ℝ :=
p ab.1 * p ab.2 * exp (lam * s ab.1 ab.2)
TheoremTarget frequencies form a distribution on pairs#✓fully proved
At a root of pairMGF p s λ = 1 the target frequencies form a distribution on pairs.
theorem isDist_targetFreq {p : α → ℝ} {s : α → α → ℝ} (hp0 : ∀ a, 0 < p a) {lam : ℝ}
(hlam : pairMGF p s lam = 1) : IsDist (targetFreq p s lam)
noncomputable def pairMGF (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) : ℝ :=
∑ a, ∑ b, p a * p b * exp (lam * s a b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:708
def IsDist (q : Z → ℝ) : Prop := (∀ z, 0 ≤ q z) ∧ ∑ z, q z = 1
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:68
noncomputable def targetFreq (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) (ab : α × α) : ℝ :=
p ab.1 * p ab.2 * exp (lam * s ab.1 ab.2)
CSLibExt/Bioinformatics/Motifs/PWM.lean:820
Uses 3 · Used by 1
TheoremEvery such score matrix is a log-odds matrix#✓fully proved
Every such score matrix is a log-odds matrix (Karlin and Altschul 1990):
s_{ab} = log (q_{ab} / (pₐ p_b)) / λ for every λ > 0; at the Karlin–Altschul root the
q_{ab} form a distribution (isDist_targetFreq), the implicit target frequencies.
theorem score_eq_log_targetFreq {p : α → ℝ} (hp0 : ∀ a, 0 < p a) (s : α → α → ℝ) {lam : ℝ}
(hlam : 0 < lam) (a b : α) : s a b = log (targetFreq p s lam (a, b) / (p a * p b)) / lam
noncomputable def targetFreq (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) (ab : α × α) : ℝ :=
p ab.1 * p ab.2 * exp (lam * s ab.1 ab.2)
CSLibExt/Bioinformatics/Motifs/PWM.lean:820
Uses 1
TheoremThe relative entropy of the target frequencies#✓fully proved
The relative entropy of the target frequencies (Altschul 1991):
λ ∑ q_{ab} s_{ab} = ∑ q_{ab} log (q_{ab} / (pₐ p_b)), which is nonnegative.
theorem relEntropy_eq_and_nonneg {p : α → ℝ} {s : α → α → ℝ} (hp : IsDist p)
(hp0 : ∀ a, 0 < p a) {lam : ℝ} (hlam : pairMGF p s lam = 1) :
lam * ∑ ab, targetFreq p s lam ab * s ab.1 ab.2 =
∑ ab, targetFreq p s lam ab * log (targetFreq p s lam ab / (p ab.1 * p ab.2)) ∧
0 ≤ lam * ∑ ab, targetFreq p s lam ab * s ab.1 ab.2
def IsDist (q : Z → ℝ) : Prop := (∀ z, 0 ≤ q z) ∧ ∑ z, q z = 1
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:68
noncomputable def pairMGF (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) : ℝ :=
∑ a, ∑ b, p a * p b * exp (lam * s a b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:708
noncomputable def targetFreq (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) (ab : α × α) : ℝ :=
p ab.1 * p ab.2 * exp (lam * s ab.1 ab.2)
CSLibExt/Bioinformatics/Motifs/PWM.lean:820
TheoremThe target score is positive#✓fully proved
At the Karlin–Altschul root λ > 0, the expected score
∑ q_{ab} s_{ab} under the target frequencies is positive.
theorem sum_targetFreq_mul_pos {p : α → ℝ} {s : α → α → ℝ} (hp : IsDist p)
(hp0 : ∀ a, 0 < p a) (hpos : ∃ a b, 0 < s a b) {lam : ℝ} (hlam0 : 0 < lam)
(hlam : pairMGF p s lam = 1) : 0 < ∑ ab, targetFreq p s lam ab * s ab.1 ab.2
def IsDist (q : Z → ℝ) : Prop := (∀ z, 0 ≤ q z) ∧ ∑ z, q z = 1
CSLibExt/MachineLearning/LatentVariable/ExpectationMaximization.lean:68
noncomputable def pairMGF (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) : ℝ :=
∑ a, ∑ b, p a * p b * exp (lam * s a b)
CSLibExt/Bioinformatics/Motifs/PWM.lean:708
noncomputable def targetFreq (p : α → ℝ) (s : α → α → ℝ) (lam : ℝ) (ab : α × α) : ℝ :=
p ab.1 * p ab.2 * exp (lam * s ab.1 ab.2)
CSLibExt/Bioinformatics/Motifs/PWM.lean:820
DefinitionOne-hot encoding of a letter#✓fully proved
The one-hot encoding of a letter: oneHot a b = 1 if b = a and 0 otherwise.
def oneHot (a : σ) (b : σ) : ℝ := if a = b then 1 else 0
DefinitionConvolution filter response at a window#✓fully proved
The response of a convolution (cross-correlation) filter W of width w on the one-hot
encoded sequence x at the window starting at i:
∑ k, ∑ b, W k b * oneHot (x (i + k)) b.
def conv (W : Fin w → σ → ℝ) (x : ℕ → σ) (i : ℕ) : ℝ :=
∑ k : Fin w, ∑ b, W k b * oneHot (x (i + k)) b
def oneHot (a : σ) (b : σ) : ℝ := if a = b then 1 else 0
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:64
Uses 1 · Used by 9
W on the reverse complement · Bias and ReLU commute with max poolingDefinitionWindow of a sequence starting at a position#✓fully proved
The window of length w of x starting at i.
def window (x : ℕ → σ) (i : ℕ) : Fin w → σ := fun k => x (i + k)
TheoremThe convolution response is the PWM score of the window#✓fully proved
The convolution response is the PWM score of the window.
theorem conv_eq_pwmScore (W : Fin w → σ → ℝ) (x : ℕ → σ) (i : ℕ) :
conv W x i = Cslib.Bioinformatics.Motifs.PWM.score W (window x i)
def conv (W : Fin w → σ → ℝ) (x : ℕ → σ) (i : ℕ) : ℝ :=
∑ k : Fin w, ∑ b, W k b * oneHot (x (i + k)) b
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:69
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
def window (x : ℕ → σ) (i : ℕ) : Fin w → σ := fun k => x (i + k)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:73
Uses 4 · Used by 3
DefinitionGlobal max pooling#✓fully proved
Global max pooling over the m + 1 windows of a sequence of length m + w.
def maxPool (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) : ℝ :=
(range (m + 1)).sup' nonempty_range_add_one (conv W x)
def conv (W : Fin w → σ → ℝ) (x : ℕ → σ) (i : ℕ) : ℝ :=
∑ k : Fin w, ∑ b, W k b * oneHot (x (i + k)) b
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:69
Uses 1 · Used by 7
W on the reverse complement · Bias and ReLU commute with max poolingTheoremEvery window's PWM score is at most the max-pooled output#✓fully proved
Every window's PWM score is at most the max-pooled output.
theorem le_maxPool (W : Fin w → σ → ℝ) (x : ℕ → σ) {m i : ℕ} (hi : i ≤ m) :
Cslib.Bioinformatics.Motifs.PWM.score W (window x i) ≤ maxPool W x m
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
def window (x : ℕ → σ) (i : ℕ) : Fin w → σ := fun k => x (i + k)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:73
def maxPool (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) : ℝ :=
(range (m + 1)).sup' nonempty_range_add_one (conv W x)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:81
TheoremMax pooling returns the best PWM hit#✓fully proved
Some window attains the max-pooled output.
theorem exists_eq_maxPool (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) :
∃ i ≤ m, Cslib.Bioinformatics.Motifs.PWM.score W (window x i) = maxPool W x m
def score {R : Type*} [AddCommMonoid R] (W : Fin w → α → R) (s : Fin w → α) : R :=
∑ i, W i (s i)
CSLibExt/Bioinformatics/Motifs/PWM.lean:105
def window (x : ℕ → σ) (i : ℕ) : Fin w → σ := fun k => x (i + k)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:73
def maxPool (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) : ℝ :=
(range (m + 1)).sup' nonempty_range_add_one (conv W x)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:81
TheoremBias and ReLU commute with max pooling#✓fully proved
Pooling max (conv + β) 0 over the windows
gives max (maxPool + β) 0.
theorem maxPool_relu (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) (β : ℝ) :
(range (m + 1)).sup' nonempty_range_add_one (fun i => max (conv W x i + β) 0) =
max (maxPool W x m + β) 0
def conv (W : Fin w → σ → ℝ) (x : ℕ → σ) (i : ℕ) : ℝ :=
∑ k : Fin w, ∑ b, W k b * oneHot (x (i + k)) b
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:69
def maxPool (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) : ℝ :=
(range (m + 1)).sup' nonempty_range_add_one (conv W x)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:81
Uses 2
TheoremTranslation equivariance#✓fully proved
Dropping the first letter shifts the responses by one window.
theorem conv_shift (W : Fin w → σ → ℝ) (x : ℕ → σ) (i : ℕ) :
conv W (fun j => x (j + 1)) i = conv W x (i + 1)
def conv (W : Fin w → σ → ℝ) (x : ℕ → σ) (i : ℕ) : ℝ :=
∑ k : Fin w, ∑ b, W k b * oneHot (x (i + k)) b
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:69
Uses 2
DefinitionReverse complement of a sequence prefix#✓fully proved
The reverse complement of the length-L prefix of x: position j < L holds the complement
of x (L - 1 - j).
def rcSeq (L : ℕ) (x : ℕ → σ) (j : ℕ) : σ := comp (x (L - 1 - j))
DefinitionReverse-complement filter#✓fully proved
The reverse-complement filter: rcFilter W k b = W (Fin.rev k) (comp b).
TheoremThe reverse-complement filter scans the other strand#✓fully proved
On a sequence of length m + w,
its response at window i ≤ m is the response of W on the reverse complement at window
m - i.
theorem conv_rcFilter (W : Fin w → σ → ℝ) (x : ℕ → σ) {m i : ℕ} (hi : i ≤ m) :
conv (rcFilter comp W) x i = conv W (rcSeq comp (m + w) x) (m - i)
def conv (W : Fin w → σ → ℝ) (x : ℕ → σ) (i : ℕ) : ℝ :=
∑ k : Fin w, ∑ b, W k b * oneHot (x (i + k)) b
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:69
def rcFilter (W : Fin w → σ → ℝ) (k : Fin w) (b : σ) : ℝ := W k.rev (comp b)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:127
def rcSeq (L : ℕ) (x : ℕ → σ) (j : ℕ) : σ := comp (x (L - 1 - j))
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:124
Uses 6 · Used by 1
TheoremMax pooling the reverse-complement filter equals max pooling W on the reverse complement#✓fully proved
Max pooling the reverse-complement filter equals max pooling W on the reverse
complement.
theorem maxPool_rcFilter (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) :
maxPool (rcFilter comp W) x m = maxPool W (rcSeq comp (m + w) x) m
def maxPool (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) : ℝ :=
(range (m + 1)).sup' nonempty_range_add_one (conv W x)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:81
def rcFilter (W : Fin w → σ → ℝ) (k : Fin w) (b : σ) : ℝ := W k.rev (comp b)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:127
def rcSeq (L : ℕ) (x : ℕ → σ) (j : ℕ) : σ := comp (x (L - 1 - j))
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:124
Uses 5 · Used by 1
TheoremFilter responses read only positions within the sequence length#✓fully proved
The responses only read the positions < m + w of a sequence of length m + w.
theorem maxPool_congr (W : Fin w → σ → ℝ) {x y : ℕ → σ} {m : ℕ}
(hxy : ∀ j < m + w, x j = y j) : maxPool W x m = maxPool W y m
def maxPool (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) : ℝ :=
(range (m + 1)).sup' nonempty_range_add_one (conv W x)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:81
Uses 3 · Used by 1
DefinitionBoth-strand convolution score#✓fully proved
The both-strand score: the larger of the max-pooled responses of W and of its reverse
complement.
def bothStrands (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) : ℝ :=
max (maxPool W x m) (maxPool (rcFilter comp W) x m)
def maxPool (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) : ℝ :=
(range (m + 1)).sup' nonempty_range_add_one (conv W x)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:81
def rcFilter (W : Fin w → σ → ℝ) (k : Fin w) (b : σ) : ℝ := W k.rev (comp b)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:127
Uses 2 · Used by 1
TheoremThe both-strand score is invariant under reverse complementing the sequence#✓fully proved
The both-strand score is invariant under reverse complementing the sequence, for an involutive complement.
theorem bothStrands_rcSeq (hcomp : Function.Involutive comp) (W : Fin w → σ → ℝ)
(x : ℕ → σ) (m : ℕ) :
bothStrands comp W (rcSeq comp (m + w) x) m = bothStrands comp W x m
def bothStrands (W : Fin w → σ → ℝ) (x : ℕ → σ) (m : ℕ) : ℝ :=
max (maxPool W x m) (maxPool (rcFilter comp W) x m)
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:170
def rcSeq (L : ℕ) (x : ℕ → σ) (j : ℕ) : σ := comp (x (L - 1 - j))
CSLibExt/Bioinformatics/Regulatory/ConvolutionPWM.lean:124
Uses 6
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.