L1#

class usencrypt.ai.regularizers.L1(l1=0.01)#

Applies an L1 regularization penalty, defined as l1 * numpy.sum(numpy.abs(x)).

Parameters

l1 (float) – The L1 regularization factor. Defaults to 0.01.

Call arguments
Returns

The L1 regularization of the input values.

Return type

numpy.ndarray of float or usencrypt.cipher.Float

Inheritance
Examples

The L1 regularization penalty can be passed into supported layers (e.g., usencrypt.ai.nn.layers.FCLayer) as either a weight_regularizer or bias_regularizer argument, as follows:

>>> import usencrypt as ue
>>> l1_reg = ue.ai.regularizers.L1()
>>> layer = ue.ai.nn.layers.FCLayer(3, 4, weight_regularizer=l1_reg)

Further, the regularization penalty can be called directly:

>>> import numpy as np
>>> import usencrypt as ue
>>> x = np.random.rand(1, 3)
>>> x
array([[0.46363754, 0.69529382, 0.21814414]])
>>> ue_x = ue.encrypt(x)
>>> ue_x
array([[(0xffff80eb7970) Float: 0xf49ae86bff5c716598da26a6d4e41081f87ebc8f67ad9a5c83baa9f8835f5a01,
        (0xffff80eb7a30) Float: 0xa0a4f574e595f1d59d1e91a9a27d18dfb405386acefe1ccbb174a16387492562,
        (0xffff80eb7940) Float: 0xcd1f75027943eb1d42d805abdaa260449ac8008be3433c5be82638f4d2e1d749]],
     dtype=object)
>>> l1 = ue.ai.regularizers.L1(l1=0.01)
>>> reg = l1(x)
>>> reg
0.013770755003889343
>>> ue_reg = l1(ue_x)
>>> ue_reg
(0xffff81a10430) Float: 0x262d810a661e873ce1f5c79b65f83e1192af2025698690193e933ac6bdba6ecc
>>> ue.decrypt(ue_reg)
0.0137707544490695