Documentation

CslibFrontier.DataStructure.NearNeighbor.LSH

Probabilistic LSH candidate-collision and query-failure step #

This module formalizes the probabilistic candidate-collision and query-failure step on unbucketed point-set filtering toward the static (c, r)-approximate near-neighbour data structure of Indyk and Motwani (after [IM98] and [HPIM12], Theorem 3.4). It is not a bucketed sublinear approximate near-neighbour data structure: candidates filters the entire point list P across all L tables rather than looking up hash buckets in a dictionary, and Word-RAM hash tables, seed storage, dynamic updates, and sublinear O(n ^ ρ) query running time remain open in #3361.

Unbucketed query model. Each of L tables is keyed by a hash g (s j) drawn independently from a seed law ν (in the amplified step, the AND of k hashes of an (r, c r, p₁, p₂)-sensitive family, Cslib.Probability.andHash). Cslib.DataStructure.NearNeighbor.candidates lists, table by table, the points of P that collide with q. Cslib.DataStructure.NearNeighbor.query scans the first T colliding candidates and returns the first one that is not far from q. Its answers are always correct (query_eq_some), and if x₀ ∈ P is not far from q, returning none implies either x₀ collides with q in no table or the first T colliding candidates are all far (le_countP_candidates).

Probabilistic failure step. Let near pairs collide under g with probability at least P₁ and far pairs with probability at most P₂. The tables are drawn independently, so x₀ misses all of them with probability at most (1 - P₁) ^ L. The far colliding candidates number at most L |P| P₂ on average, and Markov's inequality gives Pr[fail] ≤ (1 - P₁) ^ L + L |P| P₂ / T (toOuterMeasure_query_eq_none_le), using only per-table marginals across far points.

Parameters. For a (p₁, p₂)-sensitive family with 0 < p₂ < p₁ ≤ 1 and n = |P|, let ρ = log (1 / p₁) / log (1 / p₂) (Cslib.DataStructure.NearNeighbor.rho). Take k = ⌈log n / log (1 / p₂)⌉ (numHashes), L = ⌈n ^ ρ / p₁⌉ (numTables) and T = 3 L (after the scanning rule of [IM98]; see [AI08], Section 2.4, "Strategy 1"). For n = |P| > 0 (obtained from a near-point witness x₀ ∈ P in the query theorems), these satisfy n p₂ ^ k ≤ 1 and L p₁ ^ k ≥ 1, so query returns none with probability at most e⁻¹ + 1 / 3 < 1 (toOuterMeasure_query_numTables_eq_none_le), and R independent repetitions all fail with probability at most (e⁻¹ + 1 / 3) ^ R (toOuterMeasure_queryRepeat_numTables_eq_none_le).

What is bounded, and what remains open (#3361). query tests far on at most min T (L |P|) colliding candidates (length_take_candidates_le, length_candidates_le), and the parameters satisfy k < log n / log (1 / p₂) + 1, L < n ^ ρ / p₁ + 1, and 0 ≤ ρ < 1 (numHashes_lt, numTables_lt, rho_nonneg, rho_lt_one). No declaration counts machine operations: candidates evaluates g (s j) across all of P in every table, and replacing full-list filtering with a Word-RAM hash dictionary, seed storage, and native O(n ^ ρ) query time is tracked in #3361.

Main definitions #

Main results #

References #

Unbucketed candidate model #

def Cslib.DataStructure.NearNeighbor.candidates {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] (g : ι → X → Y) {L : ℕ} (s : Fin L → ι) (P : List X) (q : X) :

Unbucketed candidate list for the probabilistic LSH step (#3361): the points of P that collide with q under g (s 0), …, g (s (L - 1)), computed by filtering all of P table by table (with repetitions) rather than looking up hash buckets.

def Cslib.DataStructure.NearNeighbor.query {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] (g : ι → X → Y) (far : X → X → Prop) [DecidableRel far] {L : ℕ} (s : Fin L → ι) (T : ℕ) (P : List X) (q : X) :

Unbucketed LSH query model (#3361): scan the first T entries of candidates g s P q and return the first point that is not far from q.

theorem Cslib.DataStructure.NearNeighbor.mem_candidates {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {g : ι → X → Y} {L : ℕ} {s : Fin L → ι} {P : List X} {q x : X} :
x ∈ candidates g s P q ↔ x ∈ P ∧ ∃ (j : Fin L), g (s j) x = g (s j) q
theorem Cslib.DataStructure.NearNeighbor.query_eq_some {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {far : X → X → Prop} [DecidableRel far] {g : ι → X → Y} {L : ℕ} {s : Fin L → ι} {T : ℕ} {P : List X} {q x : X} (h : query g far s T P q = some x) :
x ∈ P ∧ ¬far x q

Soundness of the unbucketed query model: every returned point belongs to P and is not far from q.

theorem Cslib.DataStructure.NearNeighbor.countP_candidates {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {far : X → X → Prop} [DecidableRel far] (g : ι → X → Y) {L : ℕ} (s : Fin L → ι) (P : List X) (q : X) :
List.countP (fun (x : X) => decide (far x q)) (candidates g s P q) = ∑ j : Fin L, List.countP (fun (x : X) => decide (g (s j) x = g (s j) q ∧ far x q)) P

The far candidates, counted with multiplicity, are the far points of P colliding with q, summed over the tables.

theorem Cslib.DataStructure.NearNeighbor.le_countP_candidates {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {far : X → X → Prop} [DecidableRel far] {g : ι → X → Y} {L : ℕ} {s : Fin L → ι} {T : ℕ} {P : List X} {q x : X} (hx : x ∈ P) (hnf : ¬far x q) (hj : ∃ (j : Fin L), g (s j) x = g (s j) q) (h : query g far s T P q = none) :
T ≤ List.countP (fun (y : X) => decide (far y q)) (candidates g s P q)

Deterministic failure decomposition on unbucketed candidates: if x ∈ P is not far from q, collides with q in some table, and query returns none, then at least T far colliding candidates were seen.

theorem Cslib.DataStructure.NearNeighbor.length_candidates_le {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] (g : ι → X → Y) {L : ℕ} (s : Fin L → ι) (P : List X) (q : X) :
(candidates g s P q).length ≤ L * P.length

Each of the L tables contributes at most |P| colliding candidates.

theorem Cslib.DataStructure.NearNeighbor.length_take_candidates_le {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] (g : ι → X → Y) {L : ℕ} (s : Fin L → ι) (T : ℕ) (P : List X) (q : X) :
(List.take T (candidates g s P q)).length ≤ min T (L * P.length)

Candidate-prefix bound: the scanned prefix (candidates g s P q).take T has length at most min T (L |P|) (bounding far tests on colliding candidates, not total hash evaluations across P; #3361).

Probabilistic failure step #

theorem Cslib.DataStructure.NearNeighbor.tsum_iid_mul_countP_candidates_le {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {far : X → X → Prop} [DecidableRel far] (ν : PMF ι) (g : ι → X → Y) (L : ℕ) (P : List X) (q : X) {P₂ : ℝ} (hfar : ∀ x ∈ P, far x q → Probability.collisionProb ν g x q ≤ P₂) :
∑' (s : Fin L → ι), (Probability.PMF.iid ν L) s * ↑(List.countP (fun (y : X) => decide (far y q)) (candidates g s P q)) ≤ ↑L * (↑P.length * ENNReal.ofReal P₂)

Expected far-candidate step on unbucketed candidates (#3361): if far pairs collide under g with probability at most P₂, the expected number of far colliding candidates over L independent tables is at most L |P| P₂.

theorem Cslib.DataStructure.NearNeighbor.toOuterMeasure_query_eq_none_le {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {far : X → X → Prop} [DecidableRel far] (ν : PMF ι) (g : ι → X → Y) (L : ℕ) {T : ℕ} (hT : 0 < T) {P : List X} {q x₀ : X} (hx₀ : x₀ ∈ P) (hnf : ¬far x₀ q) {P₁ P₂ : ℝ} (hP₁ : P₁ ≤ Probability.collisionProb ν g x₀ q) (hP₂ : 0 ≤ P₂) (hfar : ∀ x ∈ P, far x q → Probability.collisionProb ν g x q ≤ P₂) :
((Probability.PMF.iid ν L).toOuterMeasure {s : Fin L → ι | query g far s T P q = none}).toReal ≤ (1 - P₁) ^ L + ↑L * ↑P.length * P₂ / ↑T

Probabilistic query-failure step on unbucketed point-set filtering (after [IM98]; not a bucketed sublinear near-neighbour data structure, #3361). Let x₀ ∈ P be not far from q and collide with q under g with probability at least P₁, and let every far point of P collide with q with probability at most P₂. Over L independent tables with stop limit T > 0, query returns none with probability at most (1 - P₁) ^ L + L |P| P₂ / T.

Amplified sensitive families #

theorem Cslib.DataStructure.NearNeighbor.toOuterMeasure_query_andHash_eq_none_le {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {near far : X → X → Prop} [DecidableRel far] {seed : PMF ι} {hash : ι → X → Y} {p₁ p₂ : ℝ} (h : Probability.IsLocalitySensitive (Probability.collisionProb seed hash) near far p₁ p₂) (hp₂ : 0 ≤ p₂) (hp : p₂ < p₁) (k L : ℕ) {T : ℕ} (hT : 0 < T) {P : List X} {q x₀ : X} (hx₀ : x₀ ∈ P) (hnear : near x₀ q) :
((Probability.PMF.iid (Probability.PMF.iid seed k) L).toOuterMeasure {s : Fin L → Fin k → ι | query (Probability.andHash hash k) far s T P q = none}).toReal ≤ (1 - p₁ ^ k) ^ L + ↑L * ↑P.length * p₂ ^ k / ↑T

Probabilistic AND-table query-failure step on unbucketed point-set filtering (after [IM98]; not a bucketed sublinear near-neighbour data structure, #3361). When each of L tables concatenates k hashes of a (p₁, p₂)-sensitive family with p₂ < p₁ and some x₀ ∈ P is near q, query with stop limit T > 0 returns none with probability at most (1 - p₁ ^ k) ^ L + L |P| p₂ ^ k / T.

Parameters #

noncomputable def Cslib.DataStructure.NearNeighbor.rho (p₁ p₂ : ℝ) :

The LSH exponent ρ = log (1 / p₁) / log (1 / p₂).

noncomputable def Cslib.DataStructure.NearNeighbor.numHashes (n : ℕ) (p₂ : ℝ) :

The number of hashes per table, k = ⌈log n / log (1 / p₂)⌉.

noncomputable def Cslib.DataStructure.NearNeighbor.numTables (n : ℕ) (p₁ p₂ : ℝ) :

The number of tables, L = ⌈n ^ ρ / p₁⌉.

theorem Cslib.DataStructure.NearNeighbor.rho_nonneg {p₁ p₂ : ℝ} (hp₂ : 0 < p₂) (hp₂₁ : p₂ < p₁) (hp₁ : p₁ ≤ 1) :
0 ≤ rho p₁ p₂
theorem Cslib.DataStructure.NearNeighbor.rho_lt_one {p₁ p₂ : ℝ} (hp₂ : 0 < p₂) (hp₂₁ : p₂ < p₁) (hp₁ : p₁ ≤ 1) :
rho p₁ p₂ < 1

Parameter-exponent step: for 0 < p₂ < p₁ ≤ 1, rho p₁ p₂ < 1 (algebraic bound on ρ; sublinear Word-RAM query time is not formalized here, #3361).

theorem Cslib.DataStructure.NearNeighbor.mul_pow_numHashes_le {n : ℕ} (hn : 0 < n) {p₂ : ℝ} (hp₂ : 0 < p₂) (hp₂₁ : p₂ < 1) :
↑n * p₂ ^ numHashes n p₂ ≤ 1

With k = numHashes n p₂, far points are rare: n p₂ ^ k ≤ 1.

theorem Cslib.DataStructure.NearNeighbor.one_le_numTables_mul_pow {n : ℕ} (hn : 0 < n) {p₁ p₂ : ℝ} (hp₂ : 0 < p₂) (hp₂₁ : p₂ < p₁) (hp₁ : p₁ ≤ 1) :
1 ≤ ↑(numTables n p₁ p₂) * p₁ ^ numHashes n p₂

With k = numHashes n p₂ and L = numTables n p₁ p₂, near points are found: L p₁ ^ k ≥ 1.

theorem Cslib.DataStructure.NearNeighbor.numHashes_lt (n : ℕ) {p₂ : ℝ} (hp₂ : 0 < p₂) (hp₂₁ : p₂ < 1) :
↑(numHashes n p₂) < Real.log ↑n / Real.log (1 / p₂) + 1
theorem Cslib.DataStructure.NearNeighbor.numTables_lt (n : ℕ) {p₁ p₂ : ℝ} (hp₁ : 0 < p₁) :
↑(numTables n p₁ p₂) < ↑n ^ rho p₁ p₂ / p₁ + 1
theorem Cslib.DataStructure.NearNeighbor.numTables_failure_bound_le {n : ℕ} (hn : 0 < n) {p₁ p₂ : ℝ} (hp₂ : 0 < p₂) (hp₂₁ : p₂ < p₁) (hp₁ : p₁ ≤ 1) :
0 < numTables n p₁ p₂ ∧ (1 - p₁ ^ numHashes n p₂) ^ numTables n p₁ p₂ + ↑(numTables n p₁ p₂) * ↑n * p₂ ^ numHashes n p₂ / (3 * ↑(numTables n p₁ p₂)) ≤ Real.exp (-1) + 1 / 3

For (p₁, p₂)-sensitive parameters 0 < p₂ < p₁ ≤ 1 and n > 0, the explicit choices k = numHashes n p₂ and L = numTables n p₁ p₂ satisfy 0 < L and (1 - p₁ ^ k) ^ L + L * n * p₂ ^ k / (3 * L) ≤ exp (-1) + 1 / 3.

theorem Cslib.DataStructure.NearNeighbor.toOuterMeasure_query_numTables_eq_none_le {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {near far : X → X → Prop} [DecidableRel far] {seed : PMF ι} {hash : ι → X → Y} {p₁ p₂ : ℝ} (h : Probability.IsLocalitySensitive (Probability.collisionProb seed hash) near far p₁ p₂) (hp₂ : 0 < p₂) (hp₂₁ : p₂ < p₁) (hp₁ : p₁ ≤ 1) {P : List X} {q x₀ : X} (hx₀ : x₀ ∈ P) (hnear : near x₀ q) :
((Probability.PMF.iid (Probability.PMF.iid seed (numHashes P.length p₂)) (numTables P.length p₁ p₂)).toOuterMeasure {s : Fin (numTables P.length p₁ p₂) → Fin (numHashes P.length p₂) → ι | query (Probability.andHash hash (numHashes P.length p₂)) far s (3 * numTables P.length p₁ p₂) P q = none}).toReal ≤ Real.exp (-1) + 1 / 3

Probabilistic query-failure step with explicit parameters on unbucketed point-set filtering (after [IM98] and [HPIM12], Theorem 3.4; not a bucketed sublinear (c, r)-near-neighbour data structure, #3361). Let hash be (p₁, p₂)-sensitive with 0 < p₂ < p₁ ≤ 1, n = |P|, k = numHashes n p₂, L = numTables n p₁ p₂, and stop limit 3 L (as in [AI08], Section 2.4). If some x₀ ∈ P is near q, query returns none with probability at most e⁻¹ + 1 / 3.

Repetition #

def Cslib.DataStructure.NearNeighbor.queryRepeat {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] (g : ι → X → Y) (far : X → X → Prop) [DecidableRel far] {R L : ℕ} (s : Fin R → Fin L → ι) (T : ℕ) (P : List X) (q : X) :

Run the unbucketed query model with each supplied seed vector s r in turn and return the first answer (#3361); independence comes from the product law in the failure theorems.

theorem Cslib.DataStructure.NearNeighbor.queryRepeat_eq_none_iff {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {far : X → X → Prop} [DecidableRel far] {g : ι → X → Y} {R L : ℕ} {s : Fin R → Fin L → ι} {T : ℕ} {P : List X} {q : X} :
queryRepeat g far s T P q = none ↔ ∀ (r : Fin R), query g far (s r) T P q = none
theorem Cslib.DataStructure.NearNeighbor.queryRepeat_eq_some {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {far : X → X → Prop} [DecidableRel far] {g : ι → X → Y} {R L : ℕ} {s : Fin R → Fin L → ι} {T : ℕ} {P : List X} {q x : X} (h : queryRepeat g far s T P q = some x) :
x ∈ P ∧ ¬far x q

Every answer of queryRepeat belongs to P and is not far from q.

theorem Cslib.DataStructure.NearNeighbor.toOuterMeasure_queryRepeat_eq_none {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {far : X → X → Prop} [DecidableRel far] (ν : PMF ι) (g : ι → X → Y) (R L T : ℕ) (P : List X) (q : X) :
(Probability.PMF.iid (Probability.PMF.iid ν L) R).toOuterMeasure {s : Fin R → Fin L → ι | queryRepeat g far s T P q = none} = (Probability.PMF.iid ν L).toOuterMeasure {s : Fin L → ι | query g far s T P q = none} ^ R

R independent instances of query all return none with the R-th power of the failure probability of one instance (#3361).

theorem Cslib.DataStructure.NearNeighbor.toOuterMeasure_queryRepeat_numTables_eq_none_le {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [DecidableEq Y] {far : X → X → Prop} [DecidableRel far] {near : X → X → Prop} {seed : PMF ι} {hash : ι → X → Y} {p₁ p₂ : ℝ} (h : Probability.IsLocalitySensitive (Probability.collisionProb seed hash) near far p₁ p₂) (hp₂ : 0 < p₂) (hp₂₁ : p₂ < p₁) (hp₁ : p₁ ≤ 1) (R : ℕ) {P : List X} {q x₀ : X} (hx₀ : x₀ ∈ P) (hnear : near x₀ q) :
((Probability.PMF.iid (Probability.PMF.iid (Probability.PMF.iid seed (numHashes P.length p₂)) (numTables P.length p₁ p₂)) R).toOuterMeasure {s : Fin R → Fin (numTables P.length p₁ p₂) → Fin (numHashes P.length p₂) → ι | queryRepeat (Probability.andHash hash (numHashes P.length p₂)) far s (3 * numTables P.length p₁ p₂) P q = none}).toReal ≤ (Real.exp (-1) + 1 / 3) ^ R

Probabilistic repetition step on unbucketed point-set filtering (#3361): with the parameters of toOuterMeasure_query_numTables_eq_none_le, R independent instances of query all return none with probability at most (e⁻¹ + 1 / 3) ^ R.