Documentation

CslibFrontier.MachineLearning.StatisticalQuery.Simulation

Simulating statistical queries from examples #

A statistical query learner can be run on random labelled examples: answer each query φ by the empirical mean of φ on a fresh block of m examples (StatisticalQuery.simulate). By Hoeffding's inequality an empirical mean is within the tolerance τ of the expectation except with probability 2 exp (-m τ² / 2), and by a union bound over the at most q queries of the run, all answers are within tolerance except with probability 2 q exp (-m τ² / 2). The run is then a run of the learner against an oracle answering within tolerance, so the hypothesis has error at most ε whenever the learner learns with tolerance τ and error ε (StatisticalQuery.Learns.toOuterMeasure_lt_disagreement_simulate_le). Whenever 2 q exp (-m τ² / 2) ≤ δ, this is a PAC learner from q m examples for the family of the distributions of a D-random point labelled by a concept of the class (StatisticalQuery.Learns.isPACLearnerFor): learnability from statistical queries implies PAC learnability [Kearns1998, Theorem 1]. The simulation needs a positive tolerance. For τ > 0 and 0 < δ < 1 the condition holds once m ≥ 2 log (2 q / δ) / τ². At τ = 0 it reads 2 q ≤ δ, which holds only for a learner making no queries.

The learner may choose its queries adaptively; the union bound runs along the tree of its calls (StatisticalQuery.toOuterMeasure_simulate_notMem_le): each query of the run is answered from a block of examples independent of the blocks used before, whatever the earlier answers were. This is the block form of the simulation in Reyzin, Section 2.1, with m examples per query. The union bound is proved by induction on the query budget, splitting off the first block with PMF.pi_fin_succ. The library's presampling theorem (Cslib.OracleComp.IsQueryBounded.run_interpret_presample) transports exact laws from online runs, and there is no online form of this bound to transport. Kearns's proof of Theorem 1 instead answers every query from a single sample, with sample bounds for a finite query space and for a query space of finite VC dimension; the single-sample form and both of its bounds are not formalized here.

Main definitions #

Main results #

References #

noncomputable def Cslib.MachineLearning.StatisticalQuery.empirical {X : Type} {m : ℕ} (φ : Query X) (s : Fin m → X × Bool) :

The empirical mean of the query φ on a block s of m labelled examples.

noncomputable def Cslib.MachineLearning.StatisticalQuery.simulate {X : Type} {m : ℕ} {α : Type} (n : ℕ) :
(Fin n → Fin m → X × Bool) → OracleComp (spec X) α → α

Run the statistical query program A on blocks of labelled examples: its i-th call φ is answered by the empirical mean of φ on the i-th block. Once the blocks run out, the remaining calls are answered by 0.

@[simp]
theorem Cslib.MachineLearning.StatisticalQuery.simulate_pure {X : Type} {m : ℕ} {α : Type} (n : ℕ) (blocks : Fin n → Fin m → X × Bool) (a : α) :
simulate n blocks (pure a) = a
@[simp]
theorem Cslib.MachineLearning.StatisticalQuery.simulate_query_bind {X : Type} {m : ℕ} {α : Type} (n : ℕ) (blocks : Fin (n + 1) → Fin m → X × Bool) (φ : Query X) (next : ℝ → OracleComp (spec X) α) :
simulate (n + 1) blocks (OracleComp.query φ >>= next) = simulate n (Fin.tail blocks) (next (empirical φ (blocks 0)))
theorem Cslib.MachineLearning.StatisticalQuery.toOuterMeasure_simulate_notMem_le {X : Type} [Finite X] {m : ℕ} {α : Type} {A : OracleComp (spec X) α} {n : ℕ} (hA : A.IsQueryBounded n) {possible : Query X → Set ℝ} {good : Set α} (hgood : OracleComp.supportWith possible A ⊆ good) (P : PMF (Fin m → X × Bool)) {β : ENNReal} (hP : ∀ (φ : Query X), P.toOuterMeasure {s : Fin m → X × Bool | empirical φ s ∉ possible φ} ≤ β) :
(Probability.PMF.pi fun (x : Fin n) => P).toOuterMeasure {b : Fin n → Fin m → X × Bool | simulate n b A ∉ good} ≤ ↑n * β

The union bound along an adaptive run. Let the program A make at most n calls, and let its results be in good whenever each call φ is answered by an element of possible φ. If the empirical mean of each query on a sample of P is outside possible φ with probability at most β, then running A on n independent samples of P gives a result outside good with probability at most n β.

noncomputable def Cslib.MachineLearning.StatisticalQuery.labelled {X : Type} (D : PMF X) (c : X → Bool) :
PMF (X × Bool)

The distribution of an example: a D-random point labelled by the target c.

theorem Cslib.MachineLearning.StatisticalQuery.toOuterMeasure_empirical_notMem_valid_le {X : Type} [Fintype X] (D : PMF X) (c : X → Bool) (m : ℕ) (φ : Query X) {τ : ℝ} (hτ : 0 ≤ τ) :
(Probability.PMF.pi fun (x : Fin m) => labelled D c).toOuterMeasure {s : Fin m → X × Bool | empirical φ s ∉ valid D c τ φ} ≤ ENNReal.ofReal (2 * Real.exp (-(↑m * τ ^ 2) / 2))

Estimating a statistical query. The empirical mean of the query φ on m independent examples of the target c under D is outside the tolerance τ ≥ 0 of its expectation with probability at most 2 exp (-m τ² / 2), by Hoeffding's inequality.

theorem Cslib.MachineLearning.StatisticalQuery.Learns.toOuterMeasure_lt_disagreement_simulate_le {X : Type} [Fintype X] {A : Algorithm X} {D : PMF X} {C : PACLearning.ConceptClass X Bool} {τ ε : ℝ} (hA : Learns A D C τ ε) {q : ℕ} (hq : OracleComp.IsQueryBounded A q) (hτ : 0 ≤ τ) {c : X → Bool} (hc : c ∈ C) (m : ℕ) :
(Probability.PMF.pi fun (x : Fin q) => Probability.PMF.pi fun (x : Fin m) => labelled D c).toOuterMeasure {b : Fin q → Fin m → X × Bool | ε < disagreement D c (simulate q b A)} ≤ ↑q * ENNReal.ofReal (2 * Real.exp (-(↑m * τ ^ 2) / 2))

Statistical queries from examples [Kearns1998, Theorem 1] [Reyzin, Section 2.1] [Rey20]. If A learns C under D from statistical queries of tolerance τ ≥ 0 with error ε, using at most q queries, then running A on q independent blocks of m examples of a target c ∈ C, each query answered by the empirical mean on its own block, gives a hypothesis of error above ε with probability at most 2 q exp (-m τ² / 2).

PAC learning #

The distributions of a D-random point labelled by a concept of C: the family over which learning under D is PAC learning.

The PAC learner from q m examples that runs A on q blocks of m examples, the block j consisting of the examples finProdFinEquiv (j, k).

Under a D-random point labelled by c, the error of h is its disagreement with c.

theorem Cslib.MachineLearning.StatisticalQuery.Learns.isPACLearnerFor {X : Type} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] {A : Algorithm X} {D : PMF X} {C : PACLearning.ConceptClass X Bool} {τ : ℝ} {ε δ : ↑(Set.Ioo 0 1)} (hA : Learns A D C τ ↑↑ε) {q : ℕ} (hq : OracleComp.IsQueryBounded A q) (hτ : 0 ≤ τ) {m : ℕ} (hm : ↑q * (2 * Real.exp (-(↑m * τ ^ 2) / 2)) ≤ ↑↑δ) :

Learning from statistical queries gives PAC learning [Kearns1998, Theorem 1] Reyzin, Section 2.1. If A learns C under D from statistical queries of tolerance τ ≥ 0 with error ε, using at most q queries, and 2 q exp (-m τ² / 2) ≤ δ, then running A on q blocks of m examples is a PAC learner with error ε and confidence 1 - δ from q m examples, for the distributions of a D-random point labelled by a concept of C.