- Paper: ReLU-ReHU Representations of Piecewise Linear-Quadratic Losses (Journal of Data Science, Vol. 23, No. 4, pp. 648–658, 2025)
- 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
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 ex4_portfolio.ipynb).
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
Do not confuse c and C in code (they are related to, but not the same as, the mathematical
| Symbol | Where | Role |
|---|---|---|
c in affine_transformation(..., c=...)
|
plqcom | Per-sample scale on the prototype loss after decomposition. Use c=1 for uniform weighting. Use c != 1 only for heterogeneous sample weights |
C in ReHLine(C=...) / plq_Ridge_*(C=...)
|
rehline | Global ERM weight / inverse regularization strength — the main tuning knob for loss vs ridge penalty. |
For rehline ReHLine(C=...) (or sklearn C=...) only; use c=1 in affine_transformation unless you need per-sample weights. Do not pass c=C when you also set ReHLine(C=C) — ReHLine applies C internally and the penalty would be doubled.
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 (c=1; C is set on ReHLine below)
rehloss = affine_transformation(rehloss, n=X.shape[0], c=1, p=y, q=0)
# form = 'classification'
rehloss = affine_transformation(rehloss, n=X.shape[0], c=1, form='classification', y=y)ReHLine
Use this when the loss is a custom PLQ composite from plqcom (steps 1–3). Pass the decomposed parameters to ReHLine and call fit(X):
# C: ReHLine ERM weight (ex1/ex2 use 0.5; ex3 uses 1.0; ex4 uses 0.5)
C = 0.5
from rehline import ReHLine
clf = ReHLine(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 provided by rehline: %s' % clf.coef_)For problems with linear constraints (e.g. portfolio), also set clf._A and clf._b.
For standard PLQ losses already built into ReHLine (SVM, hinge, Huber, MSE, MAE, ...), use plq_Ridge_Classifier or plq_Ridge_Regressor with fit(X, y) — no plqcom decomposition needed:
# C: inverse regularization strength in ReHLine (tune per problem; see notebooks)
C = 1.0
# Classification (e.g. SVM; ex2_svm.ipynb uses C=0.5)
from rehline import plq_Ridge_Classifier
clf = plq_Ridge_Classifier(loss={'name': 'svm'}, C=C)
clf.fit(X, y)
# Regression (e.g. ridge / MSE; ex3_regression.ipynb uses C=1)
from rehline import plq_Ridge_Regressor
clf = plq_Ridge_Regressor(loss={'name': 'MSE'}, C=C)
clf.fit(X, y)
print(clf.coef_, clf.intercept_)See the ReHLine-python documentation for the full list of built-in loss names.
| Notebook | Description |
|---|---|
| ex1: Hinge–Square | Custom composite classification loss; low-level ReHLine API only |
| ex2: SVM | Hinge SVM via plqcom decomposition and plq_Ridge_Classifier |
| ex3: Ridge Regression | MSE / ridge via plqcom and plq_Ridge_Regressor |
| ex4: Portfolio | PLQ from points + linear constraints (_A, _b) |
Source notebooks live in examples/ and are mirrored under docs/source/notebooks/ for Sphinx.
If you use plqcom in your research, please cite our paper:
@article{GaoDaiQiu2025,
title = {ReLU-ReHU Representations of Piecewise Linear-Quadratic Losses},
author = {Gao, Tingxian and Dai, Ben and Qiu, Yixuan},
journal = {Journal of Data Science},
volume = {23},
number = {4},
pages = {648--658},
year = {2025},
doi = {10.6339/24-JDS1162},
url = {https://jds-online.org/journal/JDS/article/1401/info}
}- [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.