numcodecs_random_projection
numcodecs_random_projection
RPCodec for the numcodecs buffer compression API.
Modules:
-
mt_rng–
Classes:
-
RPMethod–Random projection method.
-
RPCodec–Random projection codec for lossy compression of numerical data.
RPMethod
Bases: Enum
Random projection method.
dct
class-attribute
instance-attribute
dct = 'dct'
Discrete Cosine Transform (DCT).
Generate DxK projection matrix R using Type II Discrete Cosine Transform (DCT) basis 1.
-
Amador, J. J. (2006). Random projection and orthonormality for lossy image compression. Image and Vision Computing, 25(5), 754–766. Available from: doi:10.1016/j.imavis.2006.05.018. ↩
gaussian
class-attribute
instance-attribute
gaussian = 'gaussian'
Gaussian random projection.
Generate random DxK matrix R with entries drawn from N(0, 1/sqrt(K))
distribution, which preserves expected distances according to
Johnson-Lindenstrauss lemma.
RPCodec
RPCodec(
mae: None | float = None,
cr: None | float = None,
k: None | int = None,
method: str | RPMethod = dct,
seed: None | int = None,
max_block_memory: None | int = None,
debug: bool = False,
)
Bases: Codec
Random projection codec for lossy compression of numerical data.
Compresses 2D finite floating point data by projecting it onto a lower-dimensional subspace using a specified method. The Discrete Cosine Transform (DCT) is used by default.
A two-dimensional array of shape N x D is encoded as an array of
shape N x K, where k is either set explicitly or chosen based on the
compression ratio cr. Alternatively, k can be estimated from the data
during encoding by giving a loose Mean Absolute Error (MAE) bound.
Arrays that are not two-dimensional are automatically reshaped to be 2D as follows: - 0D scalar -> 1x1 - 1D array of shape D -> 1xD - 2D array of shape NxD -> NxD - >2D arrays: the dimensions are automatically partitioned into two subsets ...N and ...D that balance the product dimensions NxD; to use a different partitioning, you need to manually transpose and reshape the data into 2D before encoding it with this codec
Initialize Random Projection codec.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Methods:
-
encode–Encode data using random projection.
-
decode–Decode random projection encoded data.
-
get_config–Get codec configuration.
encode
encode(buf: Buffer) -> Buffer
Encode data using random projection.
During encode, the input data is standardized (mean=0, std=1) before projection.
If mae is specified, the number of projected dimensions k is
estimated based on the standardized data.
| Parameters: |
|
|---|
| Returns: |
|
|---|
decode
decode(buf: Buffer, out: None | Buffer = None) -> Buffer
Decode random projection encoded data.
During decode, the standardized data is reconstructed and denormalized.
| Parameters: |
|
|---|
| Returns: |
|
|---|