Simple Algorithm
Machine Learning · Convergence · 28 min

The Computational Hardness of Learning

When finding a good hypothesis is harder than fitting the data.

Sample complexity asks how many examples suffice; it says nothing about how long the learner must compute. This lesson separates the two. Some classes need only a few examples yet cannot be learned in polynomial time if the output must come from the class itself, unless RP = NP; some become easy the moment you change the output language; and some look hard for every algorithm, with evidence from cryptography, from decades of attacks on learning parity with noise, and from unconditional lower bounds for statistical-query algorithms.

What you’ll learn

  • Define efficient PAC learnability, distinguish proper from improper learning, and show why NP-hardness of the consistency problem rules out efficient proper learning unless RP = NP.
  • Prove that 3-term DNF is hard to learn properly via a reduction from graph 3-coloring, yet efficiently learnable with 3-CNF hypotheses.
  • Contrast realizable halfspaces (a linear program) with agnostic halfspaces (NP-hard even to approximate properly), and explain how convex surrogates sidestep the hardness.
  • Explain representation-independent hardness: cryptographic reductions, learning parity with noise, and the statistical-query lower bound for parities.

Samples versus time

For a finite class, any consistent hypothesis has error at most ε\varepsilon with probability 1−δ1-\delta once m≥(ln⁡∣Cn∣+ln⁡(1/δ))/εm\ge(\ln\abs{\mathcal C_n}+\ln(1/\delta))/\varepsilon (topic Generalization & Model Selection). Classes with ln⁡∣Cn∣=poly⁡(n)\ln\abs{\mathcal C_n}=\poly(n) are therefore statistically easy. The computational question is whether a consistent hypothesis can be found quickly: the consistency problem for H\mathcal H asks, given labeled examples, whether some h∈Hh\in\mathcal H agrees with all of them.

For conjunctions of literals it can: start with all 2n2n literals and delete every literal that some positive example falsifies, in time O(nm)\order{nm}. For other classes it cannot be solved quickly unless something unexpected happens in complexity theory, and then proper learning is ruled out too.

DerivationA proper learner solves the consistency problem
  1. D=1m∑i=1mδ(xi,yi)\mathcal D=\frac1m\sum_{i=1}^m\delta_{(\mathbf x_i,y_i)}

    Take an instance of the consistency problem: labeled examples (x1,y1),…,(xm,ym)(\mathbf x_1,y_1),\dots,(\mathbf x_m,y_m). Let D\mathcal D be the uniform distribution on these mm labeled points.

  2. RD(h)≤12m<1m⟹h(xi)=yi  for every iR_{\mathcal D}(h)\le\frac1{2m}<\frac1m\quad\Longrightarrow\quad h(\mathbf x_i)=y_i\ \text{ for every }i

    Run an efficient proper PAC learner on draws from D\mathcal D with ε=1/(2m)\varepsilon=1/(2m) and δ=1/2\delta=1/2. Every point carries mass 1/m>ε1/m>\varepsilon, so error at most ε\varepsilon means no mistakes at all:

  3. consistency for H is NP-hard  and  H is efficiently properly PAC learnable ⟹ NP=RP\text{consistency for }\mathcal H\text{ is NP-hard}\ \ \text{and}\ \ \mathcal H\text{ is efficiently properly PAC learnable}\ \Longrightarrow\ \mathrm{NP}=\mathrm{RP}

    If some h∈Hh\in\mathcal H is consistent, D\mathcal D is realizable and the learner finds one with probability at least 1/21/2; checking its output takes polynomial time; if none exists, no output passes the check. That is a randomized polynomial-time algorithm with one-sided error, so:

Since NP = RP is believed false, NP-hard consistency problems rule out efficient proper learning. Notice what the argument does not rule out: a learner whose hypotheses come from a different, larger class.

Representation matters: 3-term DNF

A 3-term DNF formula is T1∨T2∨T3T_1\lor T_2\lor T_3, each TcT_c a conjunction of literals over nn Boolean variables. There are at most 33n3^{3n} of them, so O((n+ln⁡(1/δ))/ε)\order{(n+\ln(1/\delta))/\varepsilon} examples suffice statistically.

DerivationHardness: a reduction from graph 3-coloring
  1. Given a graph GG on vertices 1,…,n1,\dots,n, build examples in {0,1}n\{0,1\}^n: for each vertex ii a positive example v(i)\mathbf v^{(i)}, all ones except a 00 in position ii; for each edge {i,j}\{i,j\} a negative example e(ij)\mathbf e^{(ij)}, all ones except 00s in positions ii and jj.

  2. Tc=⋀j: color(j)≠cxj,T1∨T2∨T3  is consistent with every exampleT_c=\bigwedge_{j:\ \mathrm{color}(j)\ne c}x_j,\qquad T_1\lor T_2\lor T_3\ \text{ is consistent with every example}

    If GG has a 3-coloring, let TcT_c be the conjunction of xjx_j over the vertices jj not of color cc. Vertex ii satisfies the term of its own color, which omits xix_i. The endpoints of an edge have different colors, so every TcT_c contains xix_i or xjx_j and rejects e(ij)\mathbf e^{(ij)}:

  3. Conversely, given a consistent 3-term DNF, color each vertex ii by a term that accepts v(i)\mathbf v^{(i)}. If adjacent vertices i,ji,j got the same term TT, then TT accepts both v(i)\mathbf v^{(i)} and v(j)\mathbf v^{(j)}, so it contains no negated literal and neither xix_i nor xjx_j; then TT also accepts e(ij)\mathbf e^{(ij)}, a contradiction. So the consistency problem for 3-term DNF is exactly graph 3-coloring, which is NP-complete, and the previous step applies.

DerivationEasiness: change the output language
  1. T1∨T2∨T3=⋀u∈T1, v∈T2, w∈T3(u∨v∨w)T_1\lor T_2\lor T_3=\bigwedge_{u\in T_1,\ v\in T_2,\ w\in T_3}(u\lor v\lor w)

    Distribute ∨\lor over ∧\land. A disjunction of three conjunctions equals the conjunction of all clauses that take one literal from each term:

  2. So every 3-term DNF is a 3-CNF formula. There are O(n3)\order{n^3} clauses of at most three literals; treat each as a new Boolean variable, and a 3-CNF becomes a conjunction over these meta-variables.

  3. m=O(n3+ln⁡(1/δ)ε)  examples sufficem=\order{\frac{n^3+\ln(1/\delta)}{\varepsilon}}\ \text{ examples suffice}

    Learn that conjunction by elimination: start with every clause and delete each one falsified by a positive example. The target's clauses are never deleted, so the result rejects every negative example, and it accepts every positive one by construction. It runs in polynomial time, and since ln⁡∣3-CNF∣=O(n3)\ln\abs{3\text{-CNF}}=\order{n^3}:

Halfspaces: clean labels versus noise

With labels y∈{−1,+1}y\in\{-1,+1\}, a halfspace predicts sign⁡(w⊤x+b)\sign(\mathbf w^\top\mathbf x+b). In the realizable case, ERM is a linear feasibility problem, yi(w⊤xi+b)≥1y_i(\mathbf w^\top\mathbf x_i+b)\ge1 for all ii, solvable in polynomial time by linear programming, and the VC dimension d+1d+1 keeps the sample size small. Halfspaces are efficiently and properly PAC learnable. Noise changes the picture completely.

SettingWhat is known
RealizableERM is a linear program: polynomial time, proper.
Random classification noiselearnable in polynomial time (Blum, Frieze, Kannan & Vempala, 1998).
Agnostic, exact ERMminimizing the number of disagreements is NP-hard (Höffgen, Simon & Van Horn, 1995).
Agnostic, proper, approximateNP-hard to find a halfspace correct on a 1/2+δ1/2+\delta fraction even when one is correct on 1−ε1-\varepsilon (Feldman, Gopalan, Khot & Ponnuswami, 2009; Guruswami & Raghavendra, 2009).
Agnostic, improperunder an assumption about refuting random KK-XOR formulas, no efficient algorithm achieves a constant approximation ratio (Daniely, 2016).
Agnostic, nice marginalspolynomial time in nn for each fixed ε\varepsilon when the input distribution is uniform on the cube or sphere, or log-concave (Kalai, Klivans, Mansour & Servedio, 2008).
The approximation result is tight in a trivial sense: one of the two constant classifiers is already right on at least half of the examples.

This is the computational reason behind the convex surrogates of The Learning Problem. Logistic regression and SVMs run in polynomial time on any data because they minimize a convex surrogate; their guarantees concern the best surrogate risk, which can be far from the best 0–1 error any halfspace achieves. Calibration (the Convergence lesson Risk, Bayes Optimality & Excess Risk) closes the gap over all functions, not within the class of halfspaces.

Check your understanding

Which statement about learning halfspaces is correct?

  1. Realizable and agnostic ERM are both linear programs
  2. Both are NP-hard, because halfspaces have infinitely many members
  3. Realizable ERM is a linear program, while agnostic proper learning is NP-hard even to approximate
  4. The difficulty is statistical: halfspaces have infinite VC dimension
Show the answer

C. Realizable ERM is a linear program, while agnostic proper learning is NP-hard even to approximate

Without noise, the constraints yi(w⊤xi+b)≥1y_i(\mathbf w^\top\mathbf x_i+b)\ge1 define a linear feasibility problem. With arbitrary noise, even beating 1/2+δ1/2+\delta agreement when 1−ε1-\varepsilon is possible is NP-hard for proper learners.

Hardness for every algorithm

NP-hardness of consistency says nothing about improper learners. Evidence against every efficient learner comes from three directions.

Cryptography. Goldreich, Goldwasser and Micali (1986) built pseudorandom functions from pseudorandom generators, which exist if one-way functions do. Such functions are computable by polynomial-size circuits, yet no efficient algorithm given input–output pairs can tell them from truly random functions; a learner that predicted them better than chance would be such a test. So, under that assumption, polynomial-size circuits are not efficiently PAC learnable with any hypotheses. Kearns and Valiant (1994) brought the line down to small classes: a polynomial-time learner for polynomial-size Boolean formulas or deterministic finite automata, with any hypothesis representation and even one predicting only slightly better than random guessing, could be used to break the RSA cryptosystem or to factor Blum integers.

Parity with noise. A parity χS(x)=⨁i∈Sxi\chi_S(\mathbf x)=\bigoplus_{i\in S}x_i is linear over GF(2), so each noiseless example is a linear equation in the unknown indicator vector of SS, and Gaussian elimination recovers SS from O(n)\order{n} random examples. Add random classification noise at rate η\eta and elimination breaks down, because it adds up many equations and their errors compound.

DerivationWhy noise ruins elimination (the piling-up lemma)
  1. E[(−1)e1⊕⋯⊕ek]=∏t=1kE[(−1)et]=(1−2η)k\E\big[(-1)^{e_1\oplus\cdots\oplus e_k}\big]=\prod_{t=1}^k\E\big[(-1)^{e_t}\big]=(1-2\eta)^k

    Let the errors e1,…,eke_1,\dots,e_k of kk equations be independent Bernoulli(η\eta). In ±1\pm1 form each has mean 1−2η1-2\eta, and independence multiplies means:

  2. P(e1⊕⋯⊕ek=0)=12+12(1−2η)kP\big(e_1\oplus\cdots\oplus e_k=0\big)=\frac12+\frac12(1-2\eta)^k

    So the sum of kk noisy equations is correct with probability

  3. Elimination combines on the order of nn equations, so for constant η\eta its answer is right with probability exponentially close to 1/21/2. Blum, Kalai and Wasserman (2003) keep the combinations short by cancelling coordinates block by block, at the price of many more examples, and learn parities with noise in slightly subexponential time and sample size, 2O(n/log⁡n)2^{\order{n/\log n}}. No polynomial-time algorithm is known. Learning parity with noise and its generalization, learning with errors (Regev, 2009), are believed hard, and lattice-based cryptography rests on that belief.

Predict before you look

Each equation is wrong with probability η=0.1\eta=0.1. What is the probability that the sum of k=20k=20 independent noisy equations is correct, in percent?

Show the answer

50.6 %

12+12(0.8)20≈0.5+0.5×0.0115≈0.506\tfrac12+\tfrac12(0.8)^{20}\approx0.5+0.5\times0.0115\approx0.506. Although each equation is right 90% of the time, a combination of twenty is barely better than a coin flip, and elimination over n=100n=100 variables combines far more than twenty.

DerivationWhy parities defeat every SQ algorithm
  1. E q(x,χS(x))=E q0(x)+E[q1(x) χS(x)]\E\,q(\mathbf x,\chi_S(\mathbf x))=\E\,q_0(\mathbf x)+\E\big[q_1(\mathbf x)\,\chi_S(\mathbf x)\big]

    Take the uniform distribution on {0,1}n\{0,1\}^n and labels y=χS(x)∈{−1,+1}y=\chi_S(\mathbf x)\in\{-1,+1\}. Split a query into a label-free part and a label-correlated part, q0=12(q(⋅,1)+q(⋅,−1))q_0=\tfrac12\big(q(\cdot,1)+q(\cdot,-1)\big) and q1=12(q(⋅,1)−q(⋅,−1))q_1=\tfrac12\big(q(\cdot,1)-q(\cdot,-1)\big), so ∣q1∣≤1\abs{q_1}\le1:

  2. ∑S⊆{1,…,n}E[q1χS]2=E[q12]≤1⟹#{S: ∣E[q1χS]∣>τ}<1τ2\sum_{S\subseteq\{1,\dots,n\}}\E\big[q_1\chi_S\big]^2=\E\big[q_1^2\big]\le1\quad\Longrightarrow\quad\#\big\{S:\ \abs{\E[q_1\chi_S]}>\tau\big\}<\frac1{\tau^2}

    The 2n2^n parities are orthonormal under the uniform distribution. By Parseval, the squared correlations of q1q_1 with them sum to at most 11, so fewer than 1/τ21/\tau^2 parities can have correlation larger than τ\tau:

  3. Q ≥ (2n−1) τ2queriesQ\ \ge\ (2^n-1)\,\tau^2\quad\text{queries}

    An oracle that always answers E q0\E\,q_0 is within tolerance for all but fewer than 1/τ21/\tau^2 targets per query. Two distinct parities disagree on half the inputs, so to reach error below 1/41/4 the learner must rule out all but one of the 2n2^n candidates, which takes

The bound is unconditional: no complexity assumption is needed. With n=100n=100 and τ=0.01\tau=0.01 it demands more than 102610^{26} queries. Blum, Furst, Jackson, Kearns, Mansour and Rudich (1994) characterized weak learnability with statistical queries, under a fixed input distribution, through the SQ dimension, the largest number of nearly uncorrelated functions in a class. Learning parity with noise sits exactly in the gap between models: the algorithm of Blum, Kalai and Wasserman uses individual examples in an essentially non-statistical way, which is how it learns parities on the first O(log⁡nlog⁡log⁡n)\order{\log n\log\log n} bits in polynomial time despite noise, the first noise-tolerant learner for a class provably not learnable with statistical queries.

Key takeaways

  • Statistical and computational complexity are different. A class with ln⁡∣Cn∣=poly⁡(n)\ln\abs{\mathcal C_n}=\poly(n) needs few examples, but finding a good hypothesis can be intractable; efficient PAC learning (Valiant, 1984) demands polynomial time as well.
  • Representation matters. 3-term DNF is NP-hard to learn properly (Pitt & Valiant, 1988, via graph 3-coloring) yet easy with 3-CNF hypotheses; NP-hardness of the consistency problem rules out only proper learners, unless RP = NP.
  • Halfspaces: realizable ERM is a linear program, but agnostically even beating 1/2+δ1/2+\delta agreement properly is NP-hard when 1−ε1-\varepsilon is possible. Convex surrogates trade the 0–1 objective for tractability.
  • Evidence against every learner: cryptography (formulas and automata, Kearns & Valiant, 1994), learning parity with noise (best known 2O(n/log⁡n)2^{\order{n/\log n}}), and the unconditional SQ lower bound of (2n−1)τ2(2^n-1)\tau^2 queries for parities.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Learning 3-term DNF with 3-term DNF hypotheses is NP-hard unless RP = NP, yet 3-term DNF is efficiently PAC learnable. How?

  1. By outputting 3-CNF hypotheses, which include every 3-term DNF and can be learned by elimination
  2. Because NP-hard problems are easy on average
  3. Because the hardness disappears once enough examples are available
  4. Because 3-term DNF has infinite VC dimension
Show the answer

A. By outputting 3-CNF hypotheses, which include every 3-term DNF and can be learned by elimination

Expanding T1∨T2∨T3T_1\lor T_2\lor T_3 into clauses (u∨v∨w)(u\lor v\lor w) makes it a conjunction over O(n3)\order{n^3} meta-variables, learnable by elimination in polynomial time. Hardness applied only to proper learners.

Question 2

Why does NP-hardness of the consistency problem for H\mathcal H rule out efficient proper PAC learning of H\mathcal H, unless RP = NP?

  1. Because PAC learning requires zero training error
  2. Because a proper learner, run on the uniform distribution over a sample with ε<1/m\varepsilon<1/m, returns a consistent member of H\mathcal H with probability at least 1/21/2
  3. Because every NP-hard problem is cryptographically hard
  4. Because the sample complexity of H\mathcal H becomes exponential
Show the answer

B. Because a proper learner, run on the uniform distribution over a sample with ε<1/m\varepsilon<1/m, returns a consistent member of H\mathcal H with probability at least 1/21/2

Each sample point has mass 1/m1/m under the uniform distribution, so error below 1/m1/m forces zero mistakes. The learner thus becomes a randomized one-sided-error algorithm for an NP-hard problem.

Question 3

Logistic regression runs in polynomial time on any dataset. Why does this not contradict the NP-hardness of agnostic halfspace learning?

  1. Logistic regression is not a linear classifier
  2. The hardness results assume random classification noise
  3. NP-hardness concerns only exact optimization, and logistic regression is approximate
  4. It minimizes a convex surrogate, so its guarantee concerns the best logistic risk, not the best 0–1 error of any halfspace
Show the answer

D. It minimizes a convex surrogate, so its guarantee concerns the best logistic risk, not the best 0–1 error of any halfspace

The NP-hard problem is to find a halfspace whose 0–1 error is close to the best possible. Logistic regression solves a different, convex problem; on adversarial data its 0–1 error can be far from optimal.

Question 4

Why can no statistical-query algorithm efficiently learn parities under the uniform distribution?

  1. Parities have exponentially large VC dimension
  2. SQ algorithms cannot cope with label noise
  3. The 2n2^n parities are pairwise uncorrelated, so each query with tolerance τ\tau can rule out fewer than 1/τ21/\tau^2 of them
  4. Parities cannot be computed in polynomial time
Show the answer

C. The 2n2^n parities are pairwise uncorrelated, so each query with tolerance τ\tau can rule out fewer than 1/τ21/\tau^2 of them

By Parseval, a query's label-dependent part correlates by more than τ\tau with fewer than 1/τ21/\tau^2 parities, so (2n−1)τ2(2^n-1)\tau^2 queries are needed. The obstacle is information that statistical queries cannot extract, not computation.

Further reading

  • L. Pitt & L. G. Valiant, "Computational limitations on learning from examples," Journal of the ACM 35, 965–984 (1988).
  • M. Kearns & L. Valiant, "Cryptographic limitations on learning Boolean formulae and finite automata," Journal of the ACM 41(1), 67–95 (1994).
  • M. Kearns, "Efficient noise-tolerant learning from statistical queries," Journal of the ACM 45, 983–1006 (1998).
  • A. Blum, A. Kalai & H. Wasserman, "Noise-tolerant learning, the parity problem, and the statistical query model," Journal of the ACM 50(4), 506–519 (2003).
  • S. Shalev-Shwartz & S. Ben-David, Understanding Machine Learning: From Theory to Algorithms (Cambridge University Press, 2014), chapter 8.