- Github Repo: https://github.com/keepwith/PLQComposite
- Documentation: https://plqcomposite.readthedocs.io
- Open Source License: MIT license
- Download Repo:
$ git clone https://github.com/keepwith/PLQComposite.git
- Technical Details: technical_details.pdf
Empirical Risk Minimization (ERM)[3] is a fundamental framework that provides a general methodology for addressing a wide variety of machine learning tasks. In many machine learning ERM problems, loss functions can be represented as piecewise linear-quadratic (PLQ) functions. Specifically, the formulation given a PLQ loss function
where
Our objective is to transform the form of the PLQ loss function
where
and
Finally, users can utilize ReHLine which is another useful software package to solve the ERM problem.
In general, to solve the ERM problem using plqcom and reline, follow the four steps outlined below. For specific details about these functions, please refer to the API documentation.
We consider three distinct representations of the PLQ functions, which are enumerated as follows.
plq: specifying the coefficients of each piece with cutoffs.
max: specifying the coefficients of a series of quadratic functions and taking the pointwise maximum of each function.
points: constructing piecewise linear functions based on a series of given points.
where
Create a PLQ Loss
import numpy as np
from plqcom import PLQLoss
# plq
plqloss1 = PLQLoss(cutpoints=np.array([0, 1, 2, 3]),quad_coef={'a': np.array([0, 0, 0, 0, 0]), 'b': np.array([0, 1, 2, 3, 4]), 'c': np.array([0, 0, -1, -3, -6])})
# max
plqloss2 = PLQLoss(quad_coef={'a': np.array([0., 0., 0.5]), 'b': np.array([0., -1., -1.]), 'c': np.array([0., 1., 0.5])}, form='max')
# points
plqloss3 = PLQLoss(points=np.array([[-3, 0], [0, 0], [1, 1], [2, 2]]), form="points")
We can call plq_to_rehloss method to decompose it to form
from plqcom import plq_to_rehloss
rehloss = plq_to_rehloss(plqloss1)
Note that, in practice,
where
- for classification problems:
- for regression problems:
Utilize the affine_transformation method to broadcast by providing
If the specific relationship does not apply to your task, you may manually repeat stage 1 and 2. Then, combine all the rehloss together and use rehline to address the problem.
from plqcom import affine_transformation
# specify p and q
rehloss = affine_transformation(rehloss, n=X.shape[0], c=C, p=y, q=0)
# form = 'classification'
rehloss = affine_transformation(rehloss, n=X.shape[0], c=C, form='classification')
from rehline import ReHLine
clf = ReHLine(loss={'name': 'custom'}, C=C)
clf.U, clf.V, clf.Tau, clf.S, clf.T= rehloss.relu_coef, rehloss.relu_intercept,rehloss.rehu_cut, rehloss.rehu_coef, rehloss.rehu_intercept
clf.fit(X=X)
print('sol privided by rehline: %s' % clf.coef_)
- [1] Dai B, Qiu Y (2024). ReHLine: regularized composite ReLU-ReHU loss minimization with linear computation and linear convergence. Advances in Neural Information Processing Systems (NIPS), 36.
- [2] Fukushima K (1969). Visual feature extraction by a multilayered network of analog threshold elements. IEEE Transactions on Systems Science and Cybernetics, 5(4): 322–333.
- [3] Vapnik, V. (1991). Principles of risk minimization for learning theory. In Advances in Neural Information Processing Systems, pages 831–838.