Skip to content

linear_compression

Bases: linear_expansion

The linear data compression function.

It performs the linear compression of the input vector, and returns the compression result. The class inherits from the linear_expansion class, which inherits from the base data transformation class.

...

Notes

For input vector \(\mathbf{x} \in R^m\), its linear compression can be based on one of the following equations: $$ \begin{align} \kappa(\mathbf{x}) &= c \mathbf{x} \in {R}^d, \\ \kappa(\mathbf{x}) &= \mathbf{x} \mathbf{C}_{post} \in {R}^d,\\ \kappa(\mathbf{x}) &= \mathbf{C}_{pre} \mathbf{x} \in {R}^{d}, \end{align} $$ where \(c \in {R}\), \(\mathbf{C}_{post}, \mathbf{C}_{pre} \in {R}^{m \times m}\) denote the provided constant scalar and linear transformation matrices, respectively. Linear data compression will not change the data vector dimensions, and the output data vector dimension \(d=m\).

By default, the input and output can also be processed with the optional pre- or post-processing functions in the linear compression function.

Attributes:

Name Type Description
name str, default = 'linear_compression'

Name of the compression function.

Methods:

Name Description
__init__

It performs the initialization of the compression function.

calculate_D

It calculates the compression space dimension D based on the input dimension parameter m.

forward

It implements the abstract forward method declared in the base compression class.

Source code in tinybig/compression/basic_compression.py
class linear_compression(linear_expansion):
    r"""
        The linear data compression function.

        It performs the linear compression of the input vector, and returns the compression result.
        The class inherits from the linear_expansion class, which inherits from the base data transformation class.

        ...

        Notes
        ----------
        For input vector $\mathbf{x} \in R^m$, its linear compression can be based on one of the following equations:
        $$
        \begin{align}
            \kappa(\mathbf{x}) &= c \mathbf{x} \in {R}^d, \\\\
            \kappa(\mathbf{x}) &= \mathbf{x} \mathbf{C}\_{post} \in {R}^d,\\\\
            \kappa(\mathbf{x}) &= \mathbf{C}\_{pre} \mathbf{x} \in {R}^{d},
        \end{align}
        $$
        where $c \in {R}$, $\mathbf{C}_{post}, \mathbf{C}_{pre} \in {R}^{m \times m}$ denote the provided
        constant scalar and linear transformation matrices, respectively.
        Linear data compression will not change the data vector dimensions, and the output data vector dimension $d=m$.

        By default, the input and output can also be processed with the optional pre- or post-processing functions
        in the linear compression function.

        Attributes
        ----------
        name: str, default = 'linear_compression'
            Name of the compression function.

        Methods
        ----------
        __init__
            It performs the initialization of the compression function.

        calculate_D
            It calculates the compression space dimension D based on the input dimension parameter m.

        forward
            It implements the abstract forward method declared in the base compression class.

    """
    def __init__(self, name='linear_compression', c=None, pre_C=None, post_C=None, *args, **kwargs):
        r"""
            The initialization method of the linear compression function.

            It initializes a linear compression object based on the input function name.
            This method will also call the initialization method of the base class as well.

            Parameters
            ----------
            name: str, default = 'linear_compression'
                The name of the linear compression function.
            c: float | torch.Tensor, default = None
                The scalar $c$ of the linear compression.
            pre_C: torch.Tensor, default = None
                The $\mathbf{C}_{pre}$ matrix of the linear compression.
            post_C: torch.Tensor, default = None
                The $\mathbf{C}_{post}$ matrix of the linear compression.

            Returns
            ----------
            transformation
                The linear compression function.
        """
        super().__init__(name=name, c=c, pre_C=pre_C, post_C=post_C, *args, **kwargs)

__init__(name='linear_compression', c=None, pre_C=None, post_C=None, *args, **kwargs)

The initialization method of the linear compression function.

It initializes a linear compression object based on the input function name. This method will also call the initialization method of the base class as well.

Parameters:

Name Type Description Default
name

The name of the linear compression function.

'linear_compression'
c

The scalar \(c\) of the linear compression.

None
pre_C

The \(\mathbf{C}_{pre}\) matrix of the linear compression.

None
post_C

The \(\mathbf{C}_{post}\) matrix of the linear compression.

None

Returns:

Type Description
transformation

The linear compression function.

Source code in tinybig/compression/basic_compression.py
def __init__(self, name='linear_compression', c=None, pre_C=None, post_C=None, *args, **kwargs):
    r"""
        The initialization method of the linear compression function.

        It initializes a linear compression object based on the input function name.
        This method will also call the initialization method of the base class as well.

        Parameters
        ----------
        name: str, default = 'linear_compression'
            The name of the linear compression function.
        c: float | torch.Tensor, default = None
            The scalar $c$ of the linear compression.
        pre_C: torch.Tensor, default = None
            The $\mathbf{C}_{pre}$ matrix of the linear compression.
        post_C: torch.Tensor, default = None
            The $\mathbf{C}_{post}$ matrix of the linear compression.

        Returns
        ----------
        transformation
            The linear compression function.
    """
    super().__init__(name=name, c=c, pre_C=pre_C, post_C=post_C, *args, **kwargs)