Skip to content

prod_compression

Bases: metric_compression

The prod metric based compression function.

It performs the data compression based on provided prod metric.

...

Notes

Formally, given a data instance \(\mathbf{x} \in R^m\) and a provided metric \(\phi: {R}^m \to {R}^{d_{\phi}}\), which transforms it into a dense representation of length \(d_{\phi}\), we can represent the prod metric based compression function as follows:

\[
    \begin{equation}
    \kappa(\mathbf{x}) = prod(\mathbf{x}) \in {R}^{d}.
    \end{equation}
\]

For the prod metric studied in this project, the output is typically a scalar, i.e., the dimension \(d = d_{\phi} = 1\).

Attributes:

Name Type Description
metric Callable[[Tensor], Tensor]

The metric compression metric.

name str, default = 'prod_compression'

Name of the prod compression function.

Methods:

Name Description
__init__

It performs the initialization of the prod 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 to define the compression function.

Source code in tinybig/compression/metric_based_compression.py
class prod_compression(metric_compression):
    r"""
        The prod metric based compression function.

        It performs the data compression based on provided prod metric.

        ...

        Notes
        ----------
        Formally, given a data instance $\mathbf{x} \in R^m$ and a provided metric $\phi: {R}^m \to {R}^{d_{\phi}}$,
        which transforms it into a dense representation of length $d_{\phi}$,
        we can represent the prod metric based compression function as follows:

        $$
            \begin{equation}
            \kappa(\mathbf{x}) = prod(\mathbf{x}) \in {R}^{d}.
            \end{equation}
        $$

        For the prod metric studied in this project, the output is typically a scalar, i.e., the dimension $d = d_{\phi} = 1$.

        Attributes
        ----------
        metric: Callable[[torch.Tensor], torch.Tensor]
            The metric compression metric.
        name: str, default = 'prod_compression'
            Name of the prod compression function.

        Methods
        ----------
        __init__
            It performs the initialization of the prod 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 to define the compression function.

    """
    def __init__(self, name: str = 'prod_compression', *args, **kwargs):
        """
            The initialization method of the prod metric based compression function.

            It initializes the compression function based on the provided prod metric.

            Parameters
            ----------
            name: str, default = 'prod_compression'
                Name of the compression function.

            Returns
            ----------
            transformation
                The prod metric based compression function.
        """
        super().__init__(name=name, metric=batch_prod, *args, **kwargs)

__init__(name='prod_compression', *args, **kwargs)

The initialization method of the prod metric based compression function.

It initializes the compression function based on the provided prod metric.

Parameters:

Name Type Description Default
name str

Name of the compression function.

'prod_compression'

Returns:

Type Description
transformation

The prod metric based compression function.

Source code in tinybig/compression/metric_based_compression.py
def __init__(self, name: str = 'prod_compression', *args, **kwargs):
    """
        The initialization method of the prod metric based compression function.

        It initializes the compression function based on the provided prod metric.

        Parameters
        ----------
        name: str, default = 'prod_compression'
            Name of the compression function.

        Returns
        ----------
        transformation
            The prod metric based compression function.
    """
    super().__init__(name=name, metric=batch_prod, *args, **kwargs)