Manual ReHLine Formulation¶
ReHLine is designed to address the regularized ReLU-ReHU minimization problem, named ReHLine optimization, of the following form:
where \(\mathbf{U} = (u_{li}),\mathbf{V} = (v_{li}) \in \mathbb{R}^{L \times n}\) and \(\mathbf{S} = (s_{hi}),\mathbf{T} = (t_{hi}),\mathbf{\tau} = (\tau_{hi}) \in \mathbb{R}^{H \times n}\) are the ReLU-ReHU loss parameters, and \((\mathbf{A},\mathbf{b})\) are the constraint parameters.
The key to using ReHLine` to solve any problem lies in utilizing custom ReHLine parameters to represent the problem, we illustrate this with following examples. Suppose that we have X and y as our data.
## Data
## X : [n x d]
## y : [n]
import numpy as np
n, d = X.shape
Note
Most of the examples below can be directly implemented by ReHLine: Empirical Risk Minimization; we are simply illustrating how to convert the problem to the ReHLine formulation.
SVM¶
SVMs solve the following optimization problem:
where \(\mathbf{x}_i \in \mathbb{R}^d\) is a feature vector, and \(y_i \in \{-1, 1\}\) is a binary label. Note that the SVM can be rewritten as a ReHLine optimization with
where \(\mathbf{1}_n = (1, \cdots, 1)^\intercal\) is the $n$-length one vector, \(\mathbf{X} \in \mathbb{R}^{n \times d}\) is the feature matrix, and \(\mathbf{y} = (y_1, \cdots, y_n)^\intercal\) is the response vector.
The python implementation is:
## SVM ReHLine parameters
clf = ReHLine()
## U
clf.U = -(C*y).reshape(1,-1)
## V
clf.V = (C*np.array(np.ones(n))).reshape(1,-1)
## Fit
clf.fit(X)
Smooth SVM¶
Smoothed SVMs solve the following optimization problem:
where \(\mathbf{x}_i \in \mathbb{R}^d\) is a feature vector, and \(y_i \in \{-1, 1\}\) is a binary label, and \(V(\cdot)\) is the modified Huber loss or the smoothed hinge loss:
Smoothed SVM can be rewritten as a ReHLine optimization with
where \(\mathbf{1}_n = (1, \cdots, 1)^\intercal\) is the $n$-length one vector, \(\mathbf{X} \in \mathbb{R}^{n \times d}\) is the feature matrix, and \(\mathbf{y} = (y_1, \cdots, y_n)^\intercal\) is the response vector.
The python implementation is:
## sSVM ReHLine parameters
clf = ReHLine()
## S
clf.S = -(np.sqrt(C/n)*y).reshape(1,-1)
## T
clf.T = (np.sqrt(C/n)*np.ones(n)).reshape(1,-1)
## Tau
clf.Tau = (np.sqrt(C/n)*np.ones(n)).reshape(1,-1)
## Fit
clf.fit(X)
FairSVM¶
The SVM with fairness constraints (FairSVM) solves the following optimization problem:
where \(\mathbf{x}_i \in \mathbb{R}^d\) is a feature vector, and \(y_i \in \{-1, 1\}\) is a binary label, $mathbf{z}_i$ is a collection of centered sensitive features
such as gender and/or race. The constraints limit the correlation between the $d_0$-length sensitive features \(\mathbf{z}_ i \in \mathbb{R}^{d_0}\) and the decision function \(\mathbf{\beta}^\intercal \mathbf{x}\), and the constants \(\mathbf{\rho} \in \mathbb{R}_+^{d_0}\) trade-offs predictive accuracy and fairness. Note that the FairSVM can be rewritten as a ReHLine optimization with
The python implementation is:
## FairSVM ReHLine parameters
clf = ReHLine()
## U
clf.U = -(C*y).reshape(1,-1)
## V
clf.V = (C*np.array(np.ones(n))).reshape(1,-1)
## A
## we illustrate that the first column of X as sensitive features, and tol is 0.1
X_sen = X[:,0]
tol_sen = 0.1
clf.A = np.repeat([X_sen @ X], repeats=[2], axis=0) / n
clf.A[1] = -clf.A[1]
## b
clf.b = np.array([tol_sen, tol_sen])
## Fit
clf.fit(X)
Ridge Huber regression¶
The Ridge regularized Huber minimization (RidgeHuber) solves the following optimization problem:
where \(H_\kappa(\cdot)\) is the Huber loss with a given parameter \(\kappa\):
In this case, the RidgeHuber can be rewritten as a ReHLine optimization with:
The python implementation is:
## Huber ReHLine parameters
clf = ReHLine()
## S
clf.S = -np.repeat([np.sqrt(1/n/lam)*np.ones(n)], repeats=[2], axis=0)
clf.S[1] = -clf.S[1]
## T
clf.T = np.repeat([np.sqrt(1/n/lam)*y], repeats=[2], axis=0)
clf.T[1] = -clf.T[1]
## Tau
clf.Tau = np.repeat([kappa*np.sqrt(1/n/lam)*np.ones(n)], repeats=[2], axis=0)
## Fit
clf.fit(X)