SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Anh Tuan Nguyen
Carnegie Mellon University atnguyen@cs.cmu.edu
Dravyansh Sharma
Carnegie Mellon University dravyans@cs.cmu.edu
The task of tuning regularization coefficients in regularized regression models with provable guarantees across problem instances still poses a significant challenge in the literature. This paper investigates the sample complexity of tuning regularization parameters in linear and logistic regressions under  $\ell_1$  and  $\ell_2$ -constraints in the data-driven setting. For the linear regression problem, by more carefully exploiting the structure of the dual function class, we provide a new upper bound for the pseudo-dimension of the validation loss function class, which significantly improves the best-known results on the problem. Remarkably, we also instantiate the first matching lower bound, proving our results are tight. For tuning the regularization parameters of logistic regression, we introduce a new approach to studying the learning guarantee via an approximation of the validation loss function class. We examine the pseudo-dimension of the approximation class and construct a uniform error bound between the validation loss function class and its approximation, which allows us to instantiate the first learning guarantee for the problem of tuning logistic regression regularization coefficients.
Regularized linear models, including the Elastic Net [1], and Regularized Logistic Regression [2, 3, 4], as well as their variants [5, 6, 7], have found widespread use in diverse fields and numerous application domains. Thanks to their simplicity and interpretability, those methods are popular choices for controlling model complexity, improving robustness, and preventing overfitting by selecting relevant features [4, 8, 9]. Moreover, regularized linear models can be adapted to the non-linear regime using kernel methods [10, 11], significantly expanding their applicability to a wide range of problems. In typical applications, one needs to solve not only a single regression problem instance, but several related problems from the same domain. Can we learn how to regularize with good generalization across the related problem instances?
Suppose we have a regression dataset  $(X,y)\in \mathbb{R}^{m\times p}\times \mathcal{Y}^m$ , where  $X$  is a design matrix with  $m$  samples and  $p$  features, and  $y$  is a target vector. Regularized linear models aim to compute an estimator  $\hat{\beta}^{(X,y)}(\lambda)$  by solving the optimization problem
$$
\hat {\beta} ^ {(X, y)} (\lambda) = \underset {\beta \in \mathbb {R} ^ {p}} {\operatorname {a r g m i n}} \left[ l (\beta , (X, y)) + \lambda_ {1} \| \beta \| _ {1} + \lambda_ {2} \| \beta \| _ {2} ^ {2} \right], \tag {1}
$$
where  $(\lambda_1,\lambda_2)\in \mathbb{R}_{\geq 0}^2$  are the regularization coefficients. For instance, if  $\lambda \in \mathbb{R}_{>0}^{2}$ ,  $y\in \mathbb{R}^{m}$  and  $l(\beta ,(X,y)) = \frac{1}{2}\| y - X\beta \| _2^2$  (squared-loss function), we get the well-known Elastic Net [1]. On the other hand, if  $\lambda \in \{(\lambda_1,0),(0,\lambda_2)\}$  for  $\lambda_1,\lambda_2 > 0$ ,  $y\in \{\pm 1\} ^m$ , and  $l(\beta ,(X,y)) = \frac{1}{m}\sum_{i = 1}^{m}\log (1 + \exp (-y_i x_i^\top \beta))$ , we obtain regularized logistic regression.
Correspondence: atnguyen@cs.cmu.edu.
In regularized linear models, the parameters  $\lambda$  play a crucial role in controlling the sparsity  $(\ell_1)$  and shrinkage  $(\ell_2)$  constraints, and are essential in ensuring better generalization and robustness [9, 4, 12]. A popular approach in practice is cross-validation, which involves choosing a finite grid of values of  $\lambda$  and iteratively solving the regression problem for multiple values of  $\lambda$  and evaluating on held-out validation sets to determine the optimal parameter. Principled techniques with theoretical guarantees suffer from various limitations, for example require strong assumptions about the original problem [13], or aim to search the optimal parameter over a discrete subset instead of the whole continuous domain. Moreover, repeatedly solving the regression problem is particularly inefficient if we have multiple problem instances from the same problem domain.
In this work, we investigate an alternative setting for tuning regularization parameters, namely data-driven algorithm design, following the previous line of work by Balcan et al. [14]. Unlike the traditional approach, which involves considering a single dataset  $(X,y)$ , in the data-driven approach, we analyze a collection of datasets or problem instances  $(X^{(i)},y^{(i)},X_{\mathrm{val}}^{(i)},y_{\mathrm{val}}^{(i)})$  drawn from an underlying problem distribution  $\mathcal{D}$ . Our objective is to determine the optimal regularization parameters  $\lambda$  so that when using the training set  $(X^{(i)},y^{(i)})$  and  $\lambda$  to select a model in Optimization problem 1, the selected model minimizes loss on the validation set  $(X_{\mathrm{val}}^{(i)},y_{\mathrm{val}}^{(i)})$ . As remarked by Balcan et al. [14], data-driven algorithm design can handle more diverse data generation scenarios in practice, including cross validation and multitask-learning [15, 16]. We emphasize that the data-driven setting differs significantly from the standard single dataset setting.
In this paper, we consider the problem of tuning regularization parameters in regularized logistic regression and the Elastic Net across multiple problem instances. Our contributions are:
- We present an improved upper bound (Theorem 3.3) on the pseudo-dimension for tuning the Elastic Net regularization parameters across problem instances by establishing a novel structural result for the validation loss function class (Theorem 3.2). We provide a crucial refinement to the piecewise structure of this function class established by Balcan et al. [14], by providing a bound on the number of distinct functional behaviors across the pieces. This enables us to describe the computation of the validation loss function as a GJ algorithm [17], which yields an upper-bound of  $O(p)$  on the pseudo-dimension, a significant improvement of the prior best bound of  $O(p^2)$  by Balcan et al. [14], and a corresponding improvement in the sample complexity (Theorem 3.4).
- Furthermore, we establish the tightness of our result by providing the first asymptotically matching lower bound of  $\Omega(p)$  on the pseudo-dimension (Theorem 3.5). It is worth noting that our results have direct implications for other specialized cases, such as LASSO and Ridge Regression.
- We further extend our results on the Elastic Net to regularized kernel linear regression problem (Corollary 3.6).
- We propose a novel approach to analyze the problem of tuning regularization parameters in regularized logistic regression, which involves indirectly investigating an approximation of the validation loss function class. Using this approach, we instantiate the first learning guarantee for this problem in the data-driven setting (Theorem 4.4).
Model selection for regularized linear models. Extensive research has focused on the selection of optimal parameters for regularized linear models, including the Elastic Net and regularized logistic regression. This process usually entails choosing the appropriate regularization coefficients for a given dataset [18, 19]. Nevertheless, a substantial proportion of this research relies on heuristic approaches that lack theoretical guarantees [20, 21]. Others have concentrated on creating tuning objectives that go beyond validation error [22, 23], but with no clearly defined procedures for provably optimizing them. The conventional method for selecting a tuning regularization parameter is through grid-based selection, which aims to choose the parameter from a subset, known as a grid, within the parameter space. While this approach provides certain guarantees [24], it falls short in delivering an optimal solution across the entire continuous parameter space, particularly when using tuning objectives that exhibit numerous discontinuities. Additionally, the grid-based technique is highly sensitive to density, as selecting a grid that is either too dense or too coarse might result in inefficient search or highly inaccurate solutions. Other guarantees require strong assumptions on the data distribution, such as sub-Gaussian noise [25, 13]. Some studies focus on evaluating regularized linear models by
Figure 1: The process of tuning regularization parameter  $\lambda$  across problem instances. Given a set of  $N$  problem instances  $\{P^{(1)},\dots ,P^{(N)}\}$  drawn from some problem distribution  $\mathcal{D}$ , one seeks to choose the best parameter  $\hat{\lambda}$  by minimizing the total validation loss  $\sum_{i = 1}^{N}h(P^{(i)};\lambda)$ .
constructing solution paths [26, 2, 27]. However, it is important to note that these approaches are primarily computational in nature and do not provide theoretical guarantees.
Data-driven algorithm design. Data-driven algorithms can adapt their internal structure or parameters to problem instances from unknown application-specific distributions. It is proved to be effective for a variety of combinatorial problems, such as clustering, integer programming, auction design, and graph-based semi-supervised learning [28, 29, 30, 31]. Balcan et al. [14] recently introduced a novel approach to tuning regularization parameters in regularized linear regression models, such as Elastic Net and its variants. They applied data-driven analysis to reveal the underlying discrete structure of the problem and leveraged a general result from [32] to obtain an upper bound on the pseudo-dimension of the problem. To provably tune the regularization parameters across problem instances, they proposed a simple ERM learner and provided sample complexity guarantee for such learner. However, the general techniques from [32] do not always lead to optimal bounds on the pseudodimension. Our paper is an example of a problem where these bounds (as derived in [14]) are sub-optimal, and more specialized techniques due to [31] result in the tighter bounds that we obtain. Also prior work does not establish any lower bound on the pseudodimension. Furthermore, it should be noted that their analysis heavily relies on the assumption of having a closed-form representation of the Elastic Net estimator [27]. This approach may not be applicable in analyzing other regularized linear models, such as regularized logistic regression, for which we propose an alternative approach.
In this section, we provide a formal definition of the problem of tuning regularization parameters in the Elastic Net and regularized logistic regression (RLR) across multiple problem instances, which follows the settings by Balcan et al. [14]. Given a problem instance  $P = (X,y,X_{\mathrm{val}},y_{\mathrm{val}})$ , where  $(X,y)\in \mathbb{R}^{m\times p}\times \mathcal{V}^m$  represents the training dataset with  $m$  samples and  $p$  features, and  $(X_{\mathrm{val}},y_{\mathrm{val}})\in \mathbb{R}^{m'\times p}\times \mathcal{V}^{m'}$  denotes the validation split with  $m'$  samples, we consider the estimator  $\hat{\beta}_{(X,y)}(\lambda)$  defined as:
$$
\hat {\beta} _ {(X, y)} (\lambda) \in \underset {\beta \in \mathbb {R} ^ {p}} {\operatorname {a r g m i n}} l (\beta , (X, y)) + \langle \lambda , R (\beta) \rangle , \tag {2}
$$
where  $l(\beta, (X, y))$  represents the objective loss function,  $\lambda$  denotes the regularization coefficients, and  $R(\beta) = (\| \beta \|_1, \| \beta \|_2^2)$  represents the regularization vector function.
For instance, if  $\lambda \in \mathbb{R}_{>0}^2$ ,  $\mathcal{Y} \equiv \mathbb{R}$ , and  $l(\beta, (X,y)) = l_{\mathrm{EN}}(\beta, (X,y)) = \frac{1}{2m} \|y - X\beta\|_2^2$ , we get the well-known Elastic Net. On the other hand, if  $\lambda \in \{(\lambda_1,0), (0,\lambda_2)\}$  for  $\lambda_1, \lambda_2 > 0$ ,  $y \in \{\pm 1\}^m$ , and  $l(\beta, (X,y)) = l_{\mathrm{RLR}}(\beta, (X,y)) = \frac{1}{m}\sum_{i=1}^{m}\log(1 + \exp(-y_i x_i^\top \beta))$ , we obtain RLR with  $\ell_1$  or  $\ell_2$  regularization. Note that for the Elastic Net hyperparameter tuning problem, we allows the regularization coefficients of both  $\ell_1, \ell_2$  are positive, while in the Regularized Logistic Regression
problem, we consider either  $\ell_1$  or  $\ell_2$  as the regularization term. We then use the validation set  $(X_{\mathrm{val}},y_{\mathrm{val}})$  to calculate the validation loss  $h(\lambda ,P) = l(\hat{\beta}_{(X,y)}(\lambda),(X_{\mathrm{val}},y_{\mathrm{val}}))$  corresponding to the problem instance  $P$  and learned regularization parameters  $\lambda$ .
In the data-driven setting, we receive a collection of  $n$  problem instances  $P^{(i)} = (X^{(i)},y^{(i)},X_{\mathrm{val}}^{(i)},y_{\mathrm{val}}^{(i)})\in \mathcal{R}_{m_i,p_i,m_i'}$  for  $i\in [n]$ , where  $\mathcal{R}_{m_i,p_i,m_i'}\coloneqq \mathbb{R}^{m_i\times p_i}\times \mathcal{V}^{m_i}\times \mathbb{R}^{m_i'\times p_i}\times \mathcal{V}^{m_i'}$ . The problem space  $\Pi_{m,p}$  is given by  $\Pi_{m,p} = \cup_{m_1\geq 0,m_2\leq m,p_1\leq p}\mathcal{R}_{m_1,p_1,m_2}$ , and we assume that problem instance  $P$  is drawn i.i.d from the problem distribution  $\mathcal{D}$  over  $\Pi_{m,p}$ . Remarkably, in this setting, problem instances can have varying training and validation sample sizes, as well as different sets of features. This general framework applies to practical scenarios where the feature sets differ among instances and allows one to learn regularization parameters that effectively work on average across multiple different but related problem instances. See Figure 1 for an illustration of the setting.
The goal here is to learn the value  $\hat{\lambda}$  s.t. with high probability over the draw of  $n$  problem instances, the expected validation loss  $\mathbb{E}_{P\sim \mathcal{D}}h(\hat{\lambda},P)$  is close to  $\min_{\lambda}\mathbb{E}_{P\sim \mathcal{D}}[h(\lambda ,P)]$ . This paper primarily focuses on providing learning guarantees in terms of sample complexity for the problem of tuning regularization parameters in the Elastic Net and regularized logistic regression (RLR). Specifically, we aim to address the question of how many problem instances are required to learn a value of  $\lambda$  that performs well across all problems  $P$  drawn from the problem distribution  $\mathcal{D}$ . To achieve this, we analyze the pseudo-dimension (in the case of the Elastic Net) or the Rademacher Complexity (for RLR) of the validation loss function class  $\mathcal{H} = \{h(\lambda ,\cdot)\mid \lambda \in \Lambda \}$ , where  $\Lambda$  represents the search space for  $\lambda$ .
3 Tight pseudo-dimension bounds for Elastic Net hyperparameter tuning
In this section, we will present our results on the pseudo-dimension upper and lower bounds for the regularized linear regression problem in the data-driven setting. Classic learning-theoretic results [33, 34] connect the pseudo-dimension of the validation loss function class (parameterized by the regularization coefficient) with the sample complexity of the number of problem instances  $\{P^{(1)},\ldots ,P^{(n)}\}$  drawn i.i.d. from some unknown problem distribution  $\mathcal{D}$  needed for learning good regularization parameters with high confidence. Let  $h_{\mathrm{EN}}(\lambda ,P) = l_{\mathrm{EN}}(\hat{\beta}_{(X,y)}(\lambda),(X_{\mathrm{val}},y_{\mathrm{val}}))$  be the validation loss function of the Elastic Net, and  $\mathcal{H}_{\mathrm{EN}} = \{h_{\mathrm{EN}}(\lambda ,P):\Pi_{m,p}\to \mathbb{R}_{\geq 0}|\lambda \in \mathbb{R}_{>0}^2\}$  be the corresponding validation loss function class, we now present tight bounds for  $\operatorname {Pdim}(\mathcal{H}_{\mathrm{EN}})$ .
3.1 The Goldberg-Jerrum framework
Recently, Bartlett et al. [31] instantiate a simplified version of the well-known Goldberg-Jerrum (GJ) Framework [17]. The GJ framework offers a general pseudo-dimension upperbound for a wide class of functions in which each function can be computed by a  $GJ$  algorithm. We provide a brief overview of the GJ Framework which is useful in establishing our improved pseudo-dimension upper bound.
Definition 1 (GJ Algorithm, [31]). A GJ algorithm  $\Gamma$  operates on real-valued inputs, and can perform two types of operations:
- Arithmetic operators of the form  $v'' = v \odot v'$ , where  $\odot \in \{+, -, \times, \div\}$ , and
- Conditional statements of the form "if  $v \geq 0 \ldots$  else ..."
In both cases,  $v$  and  $v'$  are either inputs or values previously computed by the algorithm.
General speaking, each intermediate value of the GJ algorithm  $\Gamma$  can be described by a rational function, which is a fractional between two polynomials, of the algorithm's inputs. The degree of a rational function is equal to the maximum degree of the polynomials in its numerator and its denominator. We can define two quantities that represent the complexity of GJ algorithms.
Definition 2 (Complexity of GJ algorithm, [31]). The degree of a GJ algorithm is the maximum degree of any rational function it computes of the inputs. The predicate complexity of a GJ algorithm is the number of distinct rational functions that appear in its conditional statements.
The following theorem essentially shows that for any function class  $\mathcal{F}$ , if we can describe any function  $f\in \mathcal{F}$  by a GJ algorithm of which the degree and predicate complexity are at most  $\Delta$  and  $\Lambda$ , respectively, then we can automatically obtain the upper bound for the pseudo-dimension of  $\mathcal{F}$ .
Theorem 3.1 ([31]). Suppose that each function  $f \in \mathcal{F}$  is specified by  $n$  real parameters. Suppose that for every  $x \in \mathcal{X}$  and  $r \in \mathbb{R}$ , there is a GJ algorithm  $\Gamma_{x,r}$  that given  $f \in \mathcal{F}$ , returns "true" if  $f(x) \geq r$  and "false" otherwise. Assume that  $\Gamma_{x,r}$  has degree  $\Delta$  and predicate complexity  $\Lambda$ . Then,  $\mathrm{Pdim}(\mathcal{F}) = O(n\log (\Delta \Lambda))$ .
3.2 Upper bound
Our work improves on prior research [14] by presenting an upper bound on the pseudo-dimension of Elastic Net validation loss function class  $\mathcal{H}_{\mathrm{EN}}$  parameterized by  $\lambda$ . We extend the previous piecewise-decomposable structure of the loss function by providing a bound on the number of distinct rational piece functions for any fixed problem instance (Definition 3). This allows us to use a GJ algorithm and Theorem 3.1 to obtain better bounds on the number of distinct predicates that need to be computed. While prior research only used a bound on the number of distinct loss function pieces generated by algebraic boundaries, our new observation that the loss function has a limited number of possible distinct functional behaviors yields a tighter upper bound on the pseudo-dimension (Theorem 3.2). In Theorem 3.5, we will demonstrate the tightness of our upper bound by providing a novel lower bound for the problem.
We first provide a refinement of the piece-wise decomposable function class terminology introduced by [32] which is useful for establishing our improved upper bound. Intuitively, this corresponds to real-valued functions for which the domain is partitioned by finitely many boundary functions such that the function is well-behaved in each piece in the partition, i.e. can be computed using a piece function from another function class.
Figure 2: An illustration of piece-wise structure of  $\mathcal{H}_{EN}^{*} = \{h_{P}^{*}:\mathcal{H}_{EN}\to \mathbb{R}_{\geq 0}\mid P\in \Pi_{m,p}\}$ . Given a problem instance  $P$ , the function  $h_P^* (\lambda) = h(P;\lambda)$  is a fixed rational function  $f_{i}(\lambda)$  in each piece (piece function), that is regulated by boundary functions  $g_{r_i}$  of the form  $\mathbb{1}\{r_i(\lambda) < 0\}$ . As mentioned in our main result, there are at most  $3^{p}$  functions  $f_{i}$  of degree at most  $2p$ , and at most  $p3^{p}$  functions  $g_{r_i}$  where  $r_i$  is a polynomial of degree at most  $p$ .
Definition 3. A function class  $\mathcal{H} \subseteq \mathbb{R}^{\mathcal{V}}$  that maps a domain  $\mathcal{V}$  to  $\mathbb{R}$  is  $(\mathcal{F}, k_{\mathcal{F}}, \mathcal{G}, k_{\mathcal{G}})$ -piecewise decomposable for a class  $\mathcal{G}$  of boundary functions and a class  $\mathcal{F} \in \mathbb{R}^{\mathcal{V}}$  of piece functions if the following holds: for every  $h \in \mathcal{H}$ , (1) there are  $k_{\mathcal{G}}$  functions  $g^{(1)}, \ldots, g^{(k_{\mathcal{G}})} \in \mathcal{G}$  and a function  $f_{\boldsymbol{b}} \in \mathcal{F}$  for each bit vector  $\boldsymbol{b} \in \{0,1\}^{k_{\mathcal{G}}}$  s.t. for all  $y \in \mathcal{V}$ ,  $h(y) = h_{\boldsymbol{b}_y}(y)$  where  $\boldsymbol{b}_y = \{(g^{(1)}(y), \ldots, g^{(k_{\mathcal{G}})}(y))\} \in \{0,1\}^{k_{\mathcal{G}}}$ , and (2) there is at most  $k_{\mathcal{F}}$  different functions in  $\mathcal{F}$ .
A key distinction from [32] is the finite bound  $k_{\mathcal{F}}$  on the number of different piece functions needed to define any function in the class  $\mathcal{H}$ . Under this definition we give the following more refined structure for the Elastic Net loss function class by extending arguments from [14].
Theorem 3.2. Let  $\mathcal{H}_{EN} = \{h_{EN}(\lambda, \cdot) : \Pi_{m,p} \to \mathbb{R}_{\geq 0} \mid \lambda \in \mathbb{R}_{>0}^2\}$  be the class of Elastic Net validation loss function class. Consider the dual class  $\mathcal{H}_{EN}^{*} = \{h_{P}^{*} : \mathcal{H}_{EN} \to \mathbb{R}_{\geq 0} \mid P \in \Pi_{m,p}\}$ , where  $h_{P}^{*}(h_{EN}(\lambda, \cdot)) = h_{EN}(\lambda, P)$ . Then  $\mathcal{H}_{EN}^{*}$  is  $(\mathcal{F}, 3^{p}, \mathcal{G}, p3^{p})$ -piecewise decomposable, where the piece function class  $\mathcal{F} = \{f_{q} : \mathcal{H}_{EN} \to \mathbb{R}\}$  consists at most  $3^{p}$  rational functions  $f_{q_{1}, q_{2}} : h_{EN}(\lambda, \cdot) \mapsto \frac{q_{1}(\lambda_{1}, \lambda_{2})}{q_{2}(\lambda_{1}, \lambda_{2})}$  of degree at most  $2p$ , and the boundary function class  $\mathcal{G} = \{g_{r} : \mathcal{H}_{EN} \to \{0, 1\}\}$  consists
of semi-algebraic sets bounded by at most  $p3^p$  algebraic curves  $g_r : h_{EN}(\lambda, \cdot) \mapsto \mathbb{1}\{r(\lambda_1, \lambda_2) < 0\}$ , where  $r$  is a polynomial of degree at most  $p$ .
Figure 2 demonstrates the piece-wise structure of  $\mathcal{H}_{\mathrm{EN}}^{*}$ , which allows us to establish an improved upper bound on the pseudo-dimension.
Theorem 3.3. Let  $\mathcal{H}_{EN} = \{h_{EN}(\lambda, \cdot) : \Pi \to \mathbb{R}_{\geq 0} \mid \lambda \in \mathbb{R}_{>0}^2\}$  be the Elastic Net validation loss function class that maps problem instance  $P$  to validation loss  $h_{val}(\lambda, P)$ . Then  $\mathrm{Pdim}(\mathcal{H}_{EN})$  is  $O(p)$ .
Proof Sketch. For every problem instance  $P \in \Pi_{m,p}$ , and a threshold  $r \in \mathbb{R}$ , consider the computation  $\mathbb{1}\{h_{\mathrm{EN}}(\lambda, P) - r \geq 0\}$  for any  $h_{\mathrm{EN}}(\lambda, \cdot) \in \mathcal{H}_{\mathrm{EN}}$ . From Theorem 3.2, we can describe  $\mathbb{1}\{h_{\mathrm{EN}}(\lambda, P) - r \geq 0\}$  as a GJ algorithm  $\Gamma_{P,r}$  which is specified by 2 parameters  $\lambda_1, \lambda_2$ , has degree of at most  $2p$ , and has predicate complexity of at most  $(p + 1)3^p$  (See Figure 3). Then Theorem 3.1 implies that  $\operatorname{Pdim}(\mathcal{H}_{\mathrm{EN}}) = O(p)$ .
Figure 3: An illustration of how  $\mathbb{1}\{h_{\mathrm{EN}}(\lambda, P) - r \geq 0\}$  is computed as a GJ algorithm. The number of boundary (polynomial) functions  $k_{\mathcal{G}}$  is at most  $p3^p$ , and there are at most  $M = 3^p$  distinct (rational) piece functions. All the polynomial and rational functions are of degree at most  $2p$ .
The detailed proof of Theorem 3.3 can be found on Appendix B.1.2. Recent work by Balcan et al. [14] also studied the Elastic Net, and showed the piece-wise structure of the dual function of the validation loss function which implies an upper bound of  $O(p^2)$  by employing the general tool from [32]. We establish a tighter bound of  $O(p)$  in Theorem 3.3 by establishing additional properties of the loss function class and giving a GJ algorithm for computing the loss functions.