Class - SparsityTransformer#
- class openfl.pipelines.stc_pipeline.SparsityTransformer(p=0.01)[source]#
Bases:
TransformerA transformer class to sparsify input data.
- p#
The sparsity ratio.
- Type:
float
- lossy#
A flag indicating if the transformation is lossy.
- Type:
bool
- __init__(p=0.01)[source]#
Initialize.
- Parameters:
p (float, optional) – The sparsity ratio. Defaults to 0.01.
Methods
__init__([p])Initialize.
backward(data, metadata, **kwargs)Recover data array with the right shape and numerical type.
forward(data, **kwargs)Sparsify data and pass over only non-sparsified elements by reducing the array size.
- backward(data, metadata, **kwargs)[source]#
Recover data array with the right shape and numerical type.
- Parameters:
data – an numpy array with non-zero values.
metadata – dictionary to contain information for recovering back to original data array.
- Returns:
an numpy array with original shape.
- Return type:
recovered_data
- forward(data, **kwargs)[source]#
Sparsify data and pass over only non-sparsified elements by reducing the array size.
- Parameters:
data – an numpy array from the model tensor_dict.
- Returns:
- a flattened, sparse representation of the input
tensor.
metadata: dictionary to store a list of meta information.
- Return type:
sparse_data