Cross-entropy Loss¶
Cross-entropy loss is an objective function minimized in the process of logistic regression training when a dependent variable takes more than two values.
Details¶
Given \(n\) feature vectors \(X = \{x_1 = (x_{11}, \ldots, x_{1p}),\ldots, x_n = (x_{n1}, \ldots, x_{np}) \}\) of \(n\) \(p\)-dimensional feature vectors, a vector of class labels \(y = (y_1, \ldots, y_n)\), where \(y_i \in \{0, T-1\}\) describes the class, to which the feature vector \(x_i\) belongs, where \(T\) is the number of classes, optimization solver optimizes cross-entropy loss objective function by argument \(\theta\), it is a matrix of size \(T \times (p + 1)\). The cross entropy loss objective function \(K(\theta, X, y)\) has the following format \(K(\theta, X, y) = F(\theta) + M(\theta)\) where
\(F(\theta) = -\frac{1}{n} \sum_{i=1}^{n} \log p_{y_i} (x_i, \theta) + \lambda_2 \sum_{t=0}^{T-1} \sum_{j=1}^{p} \theta_{tj}^2\), with \(p_t(z, \theta) = \frac{e^{f_t (z, \theta)}}{\sum_{i=0}^{K-1} e^{f_i (z, \theta)}}\) and \(f_t (z, \theta) = \theta_{t0} + \sum_{j=1}^{p} \theta_{tj} z_j\), \(\lambda_1 \geq 0\), \(\lambda_2 \geq 0\)
\(M(\theta) = \lambda_1 \sum_{t=0}^{T-1} \sum_{j=1}^{p} |\theta_{tj}|\)
For a given set of indices \(I = \{i_1, i_2, \ldots, i_m \}\), \(1 \leq i_r \leq n\), \(r \in \{1, \ldots, m \}\), the value and the gradient of the sum of functions in the argument X respectively have the format:
where
Hessian matrix is a symmetric matrix of size \(S \times S\), where \(S = T \times (p + 1)\)
\(\mathrm{prox}_\gamma^M (\theta_j) = \begin{cases} \theta_J - \lambda_1 \gamma, & \theta_j > \lambda_1 \gamma\\ 0, & |\theta_j| \leq \lambda_1 \gamma\\ \theta_j + \lambda_1 \gamma, & \theta_j < - \lambda_1 \gamma \end{cases}\), where \(\gamma\) is the learning rate
\(lipschitzConstant = \underset{i = 1, \ldots, n} \max \| x_i \|_2 + \frac{\lambda_2}{n}\)
For more details, see [Hastie2009].
Computation¶
Algorithm Input¶
The cross entropy loss algorithm accepts the input described below.
Pass the Input ID
as a parameter to the methods that provide input for your algorithm.
For more details, see Algorithms.
Input ID |
Input |
|
A numeric table of size \((p + 1) \times \mathrm{nClasses}\) with the input argument \(\theta\) of the objective function. Note The sizes of the argument, gradient, and hessian numeric tables do not depend on |
|
A numeric table of size \(n \times p\) with the data \(x_ij\). Note This parameter can be an object of any class derived from |
|
A numeric table of size \(n \times 1\) with dependent variables \(y_i\). Note This parameter can be an object of any class derived from |
Algorithm Parameters¶
The cross entropy loss algorithm has the following parameters.
Some of them are required only for specific values of the computation method’s parameter method
:
Parameter |
Default value |
Description |
|
|
The floating-point type that the algorithm uses for intermediate computations. Can be |
|
|
Performance-oriented computation method. |
|
Not applicable |
The number of terms in the objective function. |
|
Not applicable |
The numeric table of size \(1 \times m\), where \(m\) is the batch size, with a batch of indices to be used to compute the function results. If no indices are provided, the implementation uses all the terms in the computation. Note This parameter can be an object of any class derived from |
|
|
The 64-bit integer flag that specifies which characteristics of the objective function to compute. Provide one of the following values to request a single characteristic or use bitwise OR to request a combination of the characteristics:
|
|
|
A flag that indicates a need to compute \(\theta_{0j}\). |
|
\(0\) |
L1 regularization coefficient |
|
\(0\) |
L2 regularization coefficient |
|
Not applicable |
The number of classes (different values of dependent variable) |