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 with probability once (topic Generalization & Model Selection). Classes with are therefore statistically easy. The computational question is whether a consistent hypothesis can be found quickly: the consistency problem for asks, given labeled examples, whether some agrees with all of them.
For conjunctions of literals it can: start with all literals and delete every literal that some positive example falsifies, in time . For other classes it cannot be solved quickly unless something unexpected happens in complexity theory, and then proper learning is ruled out too.
Take an instance of the consistency problem: labeled examples . Let be the uniform distribution on these labeled points.
Run an efficient proper PAC learner on draws from with and . Every point carries mass , so error at most means no mistakes at all:
If some is consistent, is realizable and the learner finds one with probability at least ; 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 , each a conjunction of literals over Boolean variables. There are at most of them, so examples suffice statistically.
Given a graph on vertices , build examples in : for each vertex a positive example , all ones except a in position ; for each edge a negative example , all ones except s in positions and .
If has a 3-coloring, let be the conjunction of over the vertices not of color . Vertex satisfies the term of its own color, which omits . The endpoints of an edge have different colors, so every contains or and rejects :
Conversely, given a consistent 3-term DNF, color each vertex by a term that accepts . If adjacent vertices got the same term , then accepts both and , so it contains no negated literal and neither nor ; then also accepts , a contradiction. So the consistency problem for 3-term DNF is exactly graph 3-coloring, which is NP-complete, and the previous step applies.
Distribute over . A disjunction of three conjunctions equals the conjunction of all clauses that take one literal from each term:
So every 3-term DNF is a 3-CNF formula. There are clauses of at most three literals; treat each as a new Boolean variable, and a 3-CNF becomes a conjunction over these meta-variables.
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 :
Halfspaces: clean labels versus noise
With labels , a halfspace predicts . In the realizable case, ERM is a linear feasibility problem, for all , solvable in polynomial time by linear programming, and the VC dimension keeps the sample size small. Halfspaces are efficiently and properly PAC learnable. Noise changes the picture completely.
| Setting | What is known |
|---|---|
| Realizable | ERM is a linear program: polynomial time, proper. |
| Random classification noise | learnable in polynomial time (Blum, Frieze, Kannan & Vempala, 1998). |
| Agnostic, exact ERM | minimizing the number of disagreements is NP-hard (Höffgen, Simon & Van Horn, 1995). |
| Agnostic, proper, approximate | NP-hard to find a halfspace correct on a fraction even when one is correct on (Feldman, Gopalan, Khot & Ponnuswami, 2009; Guruswami & Raghavendra, 2009). |
| Agnostic, improper | under an assumption about refuting random -XOR formulas, no efficient algorithm achieves a constant approximation ratio (Daniely, 2016). |
| Agnostic, nice marginals | polynomial time in for each fixed when the input distribution is uniform on the cube or sphere, or log-concave (Kalai, Klivans, Mansour & Servedio, 2008). |
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.
Which statement about learning halfspaces is correct?
- Realizable and agnostic ERM are both linear programs
- Both are NP-hard, because halfspaces have infinitely many members
- Realizable ERM is a linear program, while agnostic proper learning is NP-hard even to approximate
- 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 define a linear feasibility problem. With arbitrary noise, even beating agreement when 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 is linear over GF(2), so each noiseless example is a linear equation in the unknown indicator vector of , and Gaussian elimination recovers from random examples. Add random classification noise at rate and elimination breaks down, because it adds up many equations and their errors compound.
Let the errors of equations be independent Bernoulli(). In form each has mean , and independence multiplies means:
So the sum of noisy equations is correct with probability
Elimination combines on the order of equations, so for constant its answer is right with probability exponentially close to . 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, . 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.
Each equation is wrong with probability . What is the probability that the sum of independent noisy equations is correct, in percent?
Show the answer
50.6 %
. Although each equation is right 90% of the time, a combination of twenty is barely better than a coin flip, and elimination over variables combines far more than twenty.
Take the uniform distribution on and labels . Split a query into a label-free part and a label-correlated part, and , so :
The parities are orthonormal under the uniform distribution. By Parseval, the squared correlations of with them sum to at most , so fewer than parities can have correlation larger than :
An oracle that always answers is within tolerance for all but fewer than targets per query. Two distinct parities disagree on half the inputs, so to reach error below the learner must rule out all but one of the candidates, which takes
The bound is unconditional: no complexity assumption is needed. With and it demands more than 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 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 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 agreement properly is NP-hard when 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 ), and the unconditional SQ lower bound of queries for parities.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Learning 3-term DNF with 3-term DNF hypotheses is NP-hard unless RP = NP, yet 3-term DNF is efficiently PAC learnable. How?
- By outputting 3-CNF hypotheses, which include every 3-term DNF and can be learned by elimination
- Because NP-hard problems are easy on average
- Because the hardness disappears once enough examples are available
- 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 into clauses makes it a conjunction over meta-variables, learnable by elimination in polynomial time. Hardness applied only to proper learners.
Why does NP-hardness of the consistency problem for rule out efficient proper PAC learning of , unless RP = NP?
- Because PAC learning requires zero training error
- Because a proper learner, run on the uniform distribution over a sample with , returns a consistent member of with probability at least
- Because every NP-hard problem is cryptographically hard
- Because the sample complexity of becomes exponential
Show the answer
B. Because a proper learner, run on the uniform distribution over a sample with , returns a consistent member of with probability at least
Each sample point has mass under the uniform distribution, so error below forces zero mistakes. The learner thus becomes a randomized one-sided-error algorithm for an NP-hard problem.
Logistic regression runs in polynomial time on any dataset. Why does this not contradict the NP-hardness of agnostic halfspace learning?
- Logistic regression is not a linear classifier
- The hardness results assume random classification noise
- NP-hardness concerns only exact optimization, and logistic regression is approximate
- 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.
Why can no statistical-query algorithm efficiently learn parities under the uniform distribution?
- Parities have exponentially large VC dimension
- SQ algorithms cannot cope with label noise
- The parities are pairwise uncorrelated, so each query with tolerance can rule out fewer than of them
- Parities cannot be computed in polynomial time
Show the answer
C. The parities are pairwise uncorrelated, so each query with tolerance can rule out fewer than of them
By Parseval, a query's label-dependent part correlates by more than with fewer than parities, so 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.