The Computational Complexity of Training ReLU(s)
Pasin Manurangsi, Daniel Reichman
Our Results
We prove both hardness results as well as algorithmic results for training a single ReLU as well as depth-2 ReLUs with units. In terms of hardness, we prove NP-hardness results for the ReLU training problem showing that this problem is hard even for a single ReLU, not only to solve exactly but also to approximate (Section 2). In Section 3, we prove that, in contrast to the case of single ReLU, training 2 ReLUs is NP-hard even in the realizable caseFor completeness we provide a proof in Appendix B that training a single ReLU can be done in polynomial time in the realizable case.. We remark that this latter result also yields, as an immediate corollary, NP-hardness for training networks considered in [BDL18]. Our proof is shorter and arguably simpler than the proof appearing in [BDL18] altough their result also applies to the case of whereas ours hardness result only applies when .
On the algorithmic side, we show, in Section 4, that depth-2 ReLUs can be properly (agnostically) learned in time provided that the inputs and weights of the units belong to the unit ball (see Section 4 for precise learning-theoretic definitions). To the best of our knowledge, only improper learning algorithms were known before [GKKT17]. The insight here is very simple: standard generalization bounds (similar to those used in [GKKT17]) imply that it suffices to consider only samples. We then observe that the algorithm of [ABMM18] runs in exponential time in the number of samples. Putting these together immediately results in the proper learning algorithm.
We additionally show that, when the coefficients ’s are all positive, they can be reliably properly learned (see Subsection 4.5 for more details) in similar running time. For the reliable model, we need to also take the advantage of the biases to ensure that there are few false positives. We remark here that Goel et al. [GKKT17] did not allow bias in their ReLUs and hence our algorithm for the reliable model would still be improper for their setting; nevertheless, our output (ReLUs with biases) is still arguably simpler than that of [GKKT17] (which is a “clipped” of a low degree polynomial). We note that, similar to [GKKT17], our algorithms work also for more general loss functions, as long as they are convex and -Lipschitz; we only focus on the squared loss for the simplicity of presentation.
Our lower bounds and algorithms contribute to the quest to understand how neural networks can be trained efficiently despite NP-hardness results. Specifically, while we prove NP-hardness results for training ReLUs, our learning results (paralleling those of [GKKT17] for improper learning) show that efficient trainingA proper learning algorithm immediately yields a polynomial time training algorithm with additive error for any constant (i.e., an additive PTAS). (up to small additive errors) is possible when weights and inputs of bounded norms are concerned. The exponential dependency of our algorithms on makes them impractical, and we believe it is of interest to find faster algorithms for properly learning ReLUS.
Hardness of Training a Single ReLU
We start by showing NP-hardness of training a single ReLU:
ReLU training problem for a neural network consisting of a single ReLU is NP-hard.
For the simplicity of exposition, we will assume in all our hardness proofs (in this section and Section 3) that the biases are equal to zero. In Appendix A, we explain how our proofs can be easily extended to handle non-zero biases.
We reduce the set cover problem to the training ReLU problem. Recall that, in the set cover problem, we are given a set along with a family of subsets of . Our goal is to determine if one can choose subsets from whose union equals . Set cover is well known to be NP-hard.
We consider a ReLU with variables. For each , we have a variable . We also have two dummy variables and . Let and .
We introduce the following training points. First, for each , add an -dimensional vector having for the coordinate corresponding to the dummy variable , in all coordinates that correspond to a subset in containing and to all other coordinates. We label this vector by . This labeled data point corresponds to the constraint
Second, for every , add an -dimensional vector having in the -th location, in the coordinate corresponding to and for all other coordinates. We label it by . This corresponds to
We then add a vector having in the coordinate corresponding to and elsewhere. We label these vectors by . This corresponds to
We also add vectors having in the coordinate corresponding to and elsewhere. We label these vectors by . These vectors correspond to copies of the constraint
Finally, we set the target error to be where is the target value in the set cover instance. Clearly, this reduction runs in polynomial time.
We now prove the correctness of this reduction.
(YES Case) Assume that there is a set cover of size consisting of the subsets in . Assigning , and to all other variables results in an error of . This is because exactly of the constraints from (3) are violated and each violated constraint contributes to the squared error. All other constraints are satisfied.
(NO Case) Suppose contrapositively that there is a weight vector that results in an error of at most . First, observe that ; otherwise, the squared error from (4) is more than . Observe also that ; otherwise, the squared error from (5) must be more than . Moreover, notice that must be non-negative, since otherwise the copies of (5) must incur total error of .
Our main observation is that the family is a set cover. The reason is as follows: if there is an element that is not covered by , then , which means that the corresponding constraint (2) for will incur already a squared error of at least (recall that is no larger than ). Thus, the observation follows.
The last step of the proof is to show that the family contains at most subsets. To see that this is the case, observe that, for every , we have , meaning that the corresponding constraint (3) incurs a squared error of . Since the total squared error is at most , we can immediately concludes that at most subsets belong to .
Thus, is a set cover with at most subsets, which completes the NO case of the proof. ∎
We remark that the above proof (and also that of Theorem 2 below) also works for the case where is treated as an unknown. This is because, if , then the error incurred in (4) (resp. in (8) below) already exceeds the target error. Thus, it must be that .
The reduction above coupled with the fact that set cover is hard to approximate within a factor [Fei98] immediately implies that the problem of approximating the minimum training error to within a factor of is also hard. In this subsection, we will substantially improve this inapproximability ratio to an almost polynomial (i.e. ) factor:
Given an instance of the single ReLU training problem, it is NP-hard to approximate the minimum squared error to within a factor of .
To prove Theorem 2, we will reduce from the Minimum Monotone Circuit Satisfiability problem, which is formally defined below.
A monotone circuit is a circuit where each gate is either an OR or an AND gate. We use to denote the number of wires in the circuit.
In the Minimum Monotone Circuit Satisfiabilityi (MMCSi) problem, we are given a monotone circuit of depth , and the objective is to assign as few Trues as possible to the input wires while ensuring that the circuit is satisfied (i.e. output wire is evaluated to True).
For any monotone circuit , we use to denote the optimum of the MMCS problem on , i.e., the smallest number of input wires need to be set to True so that is satisfied.
The hardness of approximating MMCS has long been studied (e.g. [ABMP01, DS04]). By now, this problem is known to be NP-hard to approximate to within a factor of :
is NP-hard to approximate to within factor.
Dummy Variable Constraint. We add the following constraint
Input Wire Constraint. For each input wire , we add the constraint
Output Wire Constraint. For the output wire , we add the constraint
OR Gate Constraint. For each OR gate with input wires and output wire , we add the constraint
AND Gate Constraint. For each AND gate with input wires and output wire , we add the following constraints:
We will now show that the minimum squared training error is exactly . First, we will show that the error is at most . Suppose that is an assignment to with Trues that satisfies the circuit. We assign , and, for each wire , we assign to be 1 if the wire is evaluated to be True on input and 0 otherwise. It is clear that every constraint is satisfied except the input wire constraints (7) for the wires that are assigned to True by . There are exactly such wires, and each contributes to the error; as a result, the training error of such weights is exactly .
Next, we will show that the minimum squared training error is at least . Suppose for the sake of contradiction that the minimum error is less than . Observe that, from and from our choice of , we have
Consider an assignment that assigns each input wire to be True iff . The following proposition bounds the weight of every False wire.
For any wire at height that is evaluated to False on , .
Note that we define the height recursively by first letting the heights of all input wires be zero and then let the height of the output wire of each gate be one plus the maximum of the heights among all input wires of . The proof of this proposition, which is based on a simple induction, is deferred to Appendix C.
Now, consider the output wire . We claim that must be evaluated to True on . Otherwise, Proposition 5 ensures that is at most
where the second inequality comes from our choice of . This would mean that the squared error incurred in (8) is at least . Thus, it must be that satisfies .
Moreover, since assigns each input wire to be True iff , each input wire that is assigned True incurs a squared error of from (7). Thus, the number of input wires assigned True is at most , which is a contradiction as we argued that satisfies . ∎
Observe that, in both Theorem 4 and Theorem 1, the target squared error tends to zero as the dimension tends to infinity. However, this is not an issue: if the norms of the sample vectors are not required to be bounded, then we can simply multiply them by any factor to make the error arbitrarily large. On the other hand, our learning algorithm below implies that, when the norms of samples and weights of ReLUs are bounded, we can approximate the minimum training error for ReLUs up to an additive error of in time .
NP-hardness of Training Two ReLUs
We next prove that, for two ReLUs, not only the training problem is NP-hard, but it is NP-hard to even determine whether the samples are realizable. (We remark that this also rules out any multiplicative approximation for the training problem with two ReLUs.) This is in contrast with the single ReLU case, where the realizable case is easy to solve (see Appendix B).
It is NP-hard to determine, given labeled samples of a network consisting of two ReLUs, whether it is possible to assign weights to the units such that the training error is .
We reduce from the 3SAT problem. Recall that, in the 3SAT problem, we are given 3CNF formulas with clauses on Boolean variables and we would like to determine whether there exists an assignment that satisfies the formula.
The reduction proceeds as follows. Let and . We view the -th coordinate of each sample as a coefficient of dummy variables which we will refer to as () and (). Moreover, let .
The first sample has only one non-zero coordinate corresponding to which is set to one and has label , i.e., this corresponds to
Next, for every variable , we add constraints
Finally, for each clause , we add a constraint as follows. For , let denote the variable corresponding to the literal ; moreover, let be +1 if the literal is positive and -1 otherwise. We then add the following constraint for this clause:
The reduction clearly runs in polynomial time. Next, we argue the correctness of the reduction.
(YES Case) We will start with the YES case. Suppose that the formula is satisfiable. That is, there exists an assignment that satisfies all clauses. Set and, for every , and . It is easy to verify that all constraints are satisfied, i.e., that the samples are realizable by a sum of two ReLUs with boolean weights.
We remark that, once again, the hardness in Theorem 6 applies even to the case where are treated as unknowns. Specifically, (13) and (14) already enforce both and to be positive.
Learning ReLUs
Another model we consider is the reliable agnostic learning model; in the real-valued setting, this model was first defined in [GKKT17], based on the model of [KKM12] for the standard PAC learning model. Informally speaking, reliability puts more emphasis on false positives, i.e., supported on such that but . The additional requirement is that such false positives should only happen with probability . (For motivations of the model, see e.g. [GKKT17].)
where is the probability of false positive, and denote all functions in the concept class that (with probability 1) do not admit any false positives. Similar to before, we say that is proper if .
Before we move on, we remark that, in the reliable model, the error is only compared to for that does not admit any false positives, unlike in the (non-reliable) agnostic learning model where all are considered. In other words, the fact that a concept class is reliably agnostically learnable does not necessarily imply that it is agnostically learnable. It is also not hard to verify that the fact that a concept class is agnostically learnable does not imply that it is reliably agnostically learnable.
We now proceed to state our results. The concept classes we consider are the classes of sums of ReLUs, where each weight vector has norm at most one, and the distribution is allowed to be any distribution on the unit ball. More specifically, the class ReLU, which represent the sums of ReLUs, is defined as follows:
Let ReLU denote the class .
We show that, for any fixed number of ReLUs and error parameter , the class above can be efficiently agnostically properly learned (both reliably and non-reliably), as stated below.
Observe that both Theorems consider learning the sum of ReLUs, i.e., when . For Theorem 7, the same result holds for arbitrary coefficients (with a similar proof). This theorem can be further generalized to the case where the coefficients are unknowns with only multiplicative overhead to the running time, by enumerating all . On the other hand, it is unclear how to extend the algorithm in Theorem 8 to work for negative coefficients; however, we note that it is not even clear whether “reliable” makes sense in this case, since the predicted values can take negative values.
Our results above should be compared to those of [GKKT17] who showed similar results, except that their algorithm is improper: their output is a (“clipped” of) low-degree polynomial, as opposed to sums of ReLUs (which our algorithm outputs). While our algorithm is advantageous to theirs in this sense, theirs is fasterWe do not attempt to optimize our running time, for the sake of simplicity. Nevertheless, it is clear that our approach cannot go beyond time, which is still slower than the algorithms of [GKKT17]. and extends to a larger class of networks.
Our proof is simple. It first applies generalization bounds (similar to [GKKT17]) which implies that it suffices to take samples and solve (even approximately) the training problem on these samples. Hence, by invoking the algorithm from Arora et al.’s work [ABMM18] (see Lemma 12), we immediately get Theorem 7.
To ensure the reliability guarantee (Theorem 8), we do not immediately output the minimizer from Arora et al.’s algorithm. Rather, we “shift” the biases by subtracting them with a small number. By doing so, for any such that and is non-zero but not too large, the modified hypothesis makes sure that is not a false positive (see (19) below). This is a difference between our proof and the one used in [GKKT17] where all biases are assumed to be zero and hence they need to “clip” their hypothesis instead. This is also where we need the positivity of ’s; if ’s are allowed to be negative, it could be that is small but it remains non-zero after bias shifts.
2 Generalization Bounds
Before we get to our proofs, we state the necessary generalization bounds; these are exactly the same as those used in [GKKT17]. (See Section 2.5 there.)
where is the Rademacher complexity of .
Let and . Then, .
3 Arora et al.’s Training Algorithm
Another ingredient is the algorithm of [ABMM18], which runs in time and output the optimal training error (to within arbitrarily small accuracy). We observe that, for , the running time becomes which is even faster:
Since the result stated here is slightly different than the version in [ABMM18], we sketch its proof in Appendix D.
4 Properly Learning ReLUs
We now proceed to prove Theorem 7. When we invoke the algorithm from Lemma 12, we will ignore the accuracy parameter and pretend that the algorithm output an actual optimal solution. This is with out loss of generality as in the applications below we can always set sufficiently small such that it becomes negligible. We only choose to ignore it because the proof is much cleaner this way.
First, let us describe the algorithm. Given samples whereIf there are more than samples, just consider of them.
we use the algorithm in Lemma 12 to solve for that minimizes the training error. Then, output the hypothesis .
Clearly, the algorithm is a proper learning algorithm (i.e. ReLU). Furthermore, it runs in time .
Thus, we are left to bound the error . Observe that, from Theorems 10 and 11, we have . Hence, from Fact 1, we have . Since the squared loss function is -Lipschitz and -bounded in , Theorem 9 implies that the following holds for all with probability at least :
For any , since minimizes the training error,
5 Properly Reliably Learning ReLUs
Again, we start with our algorithm. Given samples where
We use the algorithm from Lemma 12 to solve for that minimizes the training error for the samples subject to the additional constraints that, for every sample with , we have . Then, let for all where and output the hypothesis .
This is clearly a proper learning algorithm and runs in time.
Thus, we are left to bound the loss. To do so, first recall (from the proof of Theorem 7) that . Recall also that, for reliable learning, we need to bound two losses:
For convenience, let be the minimizer before bias shifts.
Observe that, if , then the bias shifts ensure that ; this is because implies that for all , which means that . (Note that this is the place where we need positivity of ’s.) As a result, we have
Combining (19) and (18), we can conclude that the following holds with probability :
where the last inequality also comes from the fact that for all with , i.e., .
Bounding ℒℒ\mathcal{L}.
Notice that, for any , . Since the squared loss function is -Lipschitz in the domain , it holds that
Finally, let be any function in ReLU such that for all in the support of such that . From how is computed, we must have
By combining the above bounds, the following holds with probability :
which, together with (20), completes our proof. ∎
Acknowledgments
We are indebted to Adam Klivans for useful comments on an preliminary version of this work and for his suggestion to study the bounded norm case. We thank Amir Globerson and Amit Daniely for helpful discussions. We thank an anonymous reviewer for pointing out an error in a previous version of this work.
References
Appendix A Dealing with Biases In NP-hardness Proofs
As stated earlier, the proofs for NP-hardness results in the main body of the paper assumes that the biases are all zeros. However, all NP-hardness results apply even for unknown , with little to no change. We elaborate on this below.
For Theorem 1, the same reduction establishes NP-hardness result when there is a bias variable in the ReLU. In the YES case, we can simply set to . In the NO case, we can get an assignment with the same squared error and no bias by replacing by and by , and thereafter use the same arguments as in the proof of Theorem 1.
A.2 NP-hardness of Training Two ReLUs
For Theorem 6, we need to add two dummy variables and , and add the following constraints
The YES case proceeds the same as before, by additionally setting and . In the NO case, these constraints force and to both be zero. The rest of the proof remains unchanged.
A.3 NP-hardness of Approximating Training Error of a Single ReLU
For Theorem 2, we add a dummy variable , and add the following constraints:
Again, it is simple to see that the minimum training error is at most is at most , by additionally setting and .
The other direction of the proof (i.e. that the minimum training error is at least ) is more delicate. First, one needs to observe that cannot be more than ; otherwise, one of the three additional constraints must contribute to more than to the training error. Then, we can once again use induction as before to prove a statement similar to Proposition 5, except that the bound will now be . The rest of the proof proceeds as before. Once again, we will be able to conclude that assign less than input wires to True but satisfies the circuit, which is a contradiction.
Appendix B Training a Single ReLU in the Realizable Case
Here we demonstrate that training a single ReLU in the realizable case can be done in polynomial time using linear programming. The key observation is the following.
Consider a system of equalities of the form where are fixed -dimensional vectors and is an -dimensional vector composed of the variables . Then there is a polynomial time algorithm in and the binary representation of the numbers in to determine if is feasible, and, in the feasible case, output an assignment to the ’s satisfying all equalities in .
We show how to transform each equality to a linear equality or inequality. Consider . If then the inequality is not satisfied by any assignment and has no solution. If then replace the equality by . If then replace the equality by . Since transforming the equalities to linear (in)equalities can be done in polynomial time and as we can decide whether a system of linear inequalities over the reals is satisfiable in polynomial time using linear programing, the claimed statement follows. ∎
Recall a training sample of a single ReLU is called realizable if there exists a choice of weights and a bias such that for all . Hence, the above lemma immediately implies that the training problem for a single ReLU can be solved in polynomial time for realizable samples.
Appendix C Missing proof of Proposition 5
Recall that we have the following constraints in our training sample:
Dummy Variable Constraint. We add the following constraint
OR Gate Constraint. For each OR gate with input wires and output wire , we add the constraint
AND Gate Constraint. For each AND gate with input wires and output wire , we add the following constraints:
We will prove by induction on the height .
Base Case. Consider any input wire (of height 0) that is assigned False by . By definition of , we have . Note that must be at most , as otherwise the squared error incurred in (24) is already more than . Thus, we have as claimed.
is an output of an OR gate. Let be the inputs of the gate. Since is evaluated to False, must all be evaluated to False. From our inductive hypothesis, we have . Now, observe that can be at most , as otherwise the squared error incurred in (25) would be more than . As a result, we have
is an output of an AND gate. Let be the inputs of the gate. Since is evaluated to False, at least one of must all be evaluated to False. Let be one such wire. Observe that can be at most , as otherwise the squared error incurred in (26) would be more than . Hence, we have
where the second inequality comes from the inductive hypothesis.
In both cases, we have , which concludes the proof of Proposition 5. ∎
Appendix D The Running Time of Arora et al.’s Algorithm
[ABMM18] gives a simple algorithm that runs in time and outputs the optimal training error (to within arbitrarily small accuracy). Below, we observe that their algorithm also yields an time algorithm; we use this running time guarantee for agnostically learning depth-2 networks of ReLUs. Before we proceed to the statement and the proof of the algorithm, we remark that, our NP-hardness proof for 2 ReLUs in fact also implies that, assuming the Exponential Time Hypothesis (ETH) [IP01, IPZ01]ETH states that 3SAT with variables and clauses cannot be solved in time., the training problem for 2 ReLUs cannot be done in time. Hence, the dependency in the exponent is tight in this sense.
up to an additive error of . We assume the bit complexity of every number appearing in the coordinates of the ’s and ’s is at most . Furthermore, there is an algorithm with the same running time up to polynomial factors that finds subjects to an additional constraint that for all such that .
For each ReLU term guess whether it equals or and replace the term in the error function accordingly. Furthermore, if the guess was made then add the linear constraint . Else, add the linear constraint . Finally add the constraints for all . After all guesses are made we get a convex quadratically constrained quadratic program (QCQP). It is well known that such a convex optimization problem can be solved in time polynomial in using a separation oracles and the ellipsoid algorithm (see for example, [B+15], section 2.1). Since the number of guesses is at most , the claim follows. For the second part of the lemma, simply substitute the constraint according to the guesses made and add the resulting linear constraint. The claim follows. ∎