plqcom.ReHProperty

ReHProperty: Several functions to check or perform the properties of ReHLoss.

Functions

affine_transformation(rehloss[, n, c, p, q, form, y])

Since composite ReLU-ReHU function is closure under affine transformation,

Module Contents

plqcom.ReHProperty.affine_transformation(rehloss: rehline._loss.ReHLoss, n=1, c=1, p=1, q=0, form='custom', y=1)

Since composite ReLU-ReHU function is closure under affine transformation, this function perform affine transformation on the PLQ object.

Parameters:
rehlossReHLoss

A ReHLoss object

c: a number or {array_like} of shape (n_samples,), default=1

Per-sample scale on the prototype loss (mathematical \(C_i\) in \(L_i(z) = C_i L(p_i z + q_i)\)). Use c=1 for uniform weights. This is not the same as C in ReHLine(C=...): for rehline >= 0.1.0, set global ERM strength via ReHLine(C=...) only and keep c=1 here unless you need heterogeneous sample weights. Do not pass c=C when also using ReHLine(C=C) — that applies the penalty twice.

p: a number or {array_like} of shape (n_samples,),default=1

scale parameter on z

q: a number or {array_like} of shape (n_samples,),default=0

shift parameter on z

n: int, default=1

number of samples

form: str, default=’custom’

Affine transformation form: 'custom', 'classification', or 'regression'. For 'custom', c, p, and q can be scalars or arrays. For 'classification', use L_i = c_i L(y_i z_i) (p=y_i, q=0). For 'regression', use L_i = c_i L(y_i - z_i) (p=-1, q=y).

y: {array_like} of shape (n_samples,), default=None, only required when form is ‘classification’ or ‘regression’

the label of the samples

Returns:
ReHLoss

A ReHLoss object after affine transformation

Examples

>>> from plqcom import PLQLoss, affine_transformation, plq_to_rehloss
>>> import numpy as np
>>> from rehline import ReHLine
>>> n, d, C = 1000, 3, 0.5
>>> np.random.seed(1024)
>>> X = np.random.randn(1000, 3)
>>> beta0 = np.random.randn(3)
>>> y = np.sign(X.dot(beta0) + np.random.randn(n))
>>> plqloss = PLQLoss(quad_coef={'a': np.array([0., 0.]), 'b': np.array([0., 1.]), 'c': np.array([0., 0.])}, cutpoints=np.array([0]))
>>> rehloss = plq_to_rehloss(plqloss)
>>> rehloss = affine_transformation(rehloss, n=X.shape[0], c=1, p=-y, q=1)