Skip to content

mean_compression

Bases: metric_compression

The mean metric based compression function.

It performs the data compression based on provided mean 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 mean metric based compression function as follows:

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

For the mean 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 = 'mean_compression'

Name of the mean compression function.

Methods:

Name Description
__init__

It performs the initialization of the mean 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 mean_compression(metric_compression):
    r"""
        The mean metric based compression function.

        It performs the data compression based on provided mean 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 mean metric based compression function as follows:

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

        For the mean 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 = 'mean_compression'
            Name of the mean compression function.

        Methods
        ----------
        __init__
            It performs the initialization of the mean 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 = 'mean_compression', *args, **kwargs):
        """
            The initialization method of the mean metric based compression function.

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

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

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

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

The initialization method of the mean metric based compression function.

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

Parameters:

Name Type Description Default
name str

Name of the compression function.

'mean_compression'

Returns:

Type Description
transformation

The mean metric based compression function.

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

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

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

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