plqcom.ReHProperty¶
ReHProperty: Several functions to check or perform the properties of ReHLoss.
Functions¶
|
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
scale parameter on loss function and require c > 0
- 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’
the form of affine transformation ‘custom’ for custom form
In this form, the c, p, q can be either a number or an array
- ‘classification’ for classification form
In this form, $L_i = c_iL(y_i z_i)$, i.e. p=y_i, q=0
- ‘regression’ for regression form
In this form, $L_i = c_iL(y_i - z_i)$, i.e. p=-1, q=y should be very careful when specify the original L and parameters
- 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=C, p=-y, q=1)