Skip to content

lphm_parameterized_bilinear_interdependence

Bases: parameterized_bilinear_interdependence

A low-rank hierarchical mapping (LPHM) parameterized bilinear interdependence function.

This class models interdependence using low-rank approximations with hierarchical mapping, where the parameter fabrication aligns with the LPHM methodology.

Notes

Formally, given a data batch \(\mathbf{X} \in R^{b \times m}\), we can represent the parameterized bilinear form-based interdependence function as follows:

\[
    \begin{equation}\label{equ:bilinear_interdependence_function}
    \xi(\mathbf{X} | \mathbf{w}) = \mathbf{X}^\top \mathbf{W} \mathbf{X} = \mathbf{A} \in R^{m \times m}.
    \end{equation}
\]

Notation \(\mathbf{W} \in R^{b \times b}\) denotes the parameter matrix fabricated from the learnable parameter vector \(\mathbf{w} \in R^{l_{\xi}}\), which can be represented as follows:

$$ \begin{equation} \psi(\mathbf{w}) = \mathbf{A} \otimes \mathbf{B} = \mathbf{A} \otimes ( \mathbf{S} \mathbf{T}^\top) \in R^{b \times b}, \end{equation} $$ where \(\mathbf{A} \in R^{p \times q}\), \(\mathbf{S} \in R^{\frac{b}{p} \times r}\) and \(\mathbf{T} \in R^{\frac{b}{q} \times r}\) are partitioned and reshaped from the parameter vector \(\mathbf{w}\).

The required length of parameter vector of this interdependence function is \(l_{\xi} = pq + r \times (\frac{b}{p} + \frac{b}{q})\).

Attributes:

Name Type Description
r int

Rank of the low-rank approximation.

p int

Number of partitions in the input dimension.

q int

Number of partitions in the output dimension.

Methods:

Name Description
__init__

Initializes the low-rank hierarchical mapping parameterized bilinear interdependence function.

Source code in tinybig/interdependence/parameterized_bilinear_interdependence.py
class lphm_parameterized_bilinear_interdependence(parameterized_bilinear_interdependence):
    r"""
        A low-rank hierarchical mapping (LPHM) parameterized bilinear interdependence function.

        This class models interdependence using low-rank approximations with hierarchical mapping,
        where the parameter fabrication aligns with the LPHM methodology.

        Notes
        ----------
        Formally, given a data batch $\mathbf{X} \in R^{b \times m}$, we can represent the parameterized bilinear form-based interdependence function as follows:

        $$
            \begin{equation}\label{equ:bilinear_interdependence_function}
            \xi(\mathbf{X} | \mathbf{w}) = \mathbf{X}^\top \mathbf{W} \mathbf{X} = \mathbf{A} \in R^{m \times m}.
            \end{equation}
        $$

        Notation $\mathbf{W} \in R^{b \times b}$ denotes the parameter matrix fabricated from the learnable parameter vector $\mathbf{w} \in R^{l_{\xi}}$,
        which can be represented as follows:

        $$
            \begin{equation}
            \psi(\mathbf{w}) = \mathbf{A} \otimes \mathbf{B} = \mathbf{A} \otimes ( \mathbf{S} \mathbf{T}^\top) \in R^{b \times b},
            \end{equation}
        $$
        where $\mathbf{A} \in R^{p \times q}$, $\mathbf{S} \in R^{\frac{b}{p} \times r}$ and $\mathbf{T} \in R^{\frac{b}{q} \times r}$ are partitioned and reshaped from the parameter vector $\mathbf{w}$.

        The required length of parameter vector of this interdependence function is $l_{\xi} = pq + r \times (\frac{b}{p} + \frac{b}{q})$.

        Attributes
        ----------
        r : int
            Rank of the low-rank approximation.
        p : int
            Number of partitions in the input dimension.
        q : int
            Number of partitions in the output dimension.

        Methods
        -------
        __init__(...)
            Initializes the low-rank hierarchical mapping parameterized bilinear interdependence function.
    """
    def __init__(self, r: int, p: int, q: int = None, name: str = 'lphm_parameterized_bilinear_interdependence', *args, **kwargs):
        """
            Initializes the low-rank hierarchical mapping parameterized bilinear interdependence function.

            Parameters
            ----------
            r : int
                Rank of the low-rank approximation.
            p : int
                Number of partitions in the input dimension.
            q : int, optional
                Number of partitions in the output dimension. Defaults to `p`.
            name : str, optional
                Name of the interdependence function. Defaults to 'lphm_parameterized_bilinear_interdependence'.
            *args : tuple
                Additional positional arguments for the parent class.
            **kwargs : dict
                Additional keyword arguments for the parent class.

            Raises
            ------
            ValueError
                If the interdependence type is not supported.
            AssertionError
                If the dimensions are not divisible by the partitions.
        """

        super().__init__(name=name, *args, **kwargs)

        self.r = r
        self.p = p
        self.q = q if q is not None else p

        if self.interdependence_type in ['row', 'left', 'instance', 'instance_interdependence']:
            d, d_prime = self.m, self.calculate_m_prime()
        elif self.interdependence_type in ['column', 'right', 'attribute', 'attribute_interdependence']:
            d, d_prime = self.b, self.calculate_b_prime()
        else:
            raise ValueError(f'Interdependence type {self.interdependence_type} not supported')
        assert d % self.p == 0 and d_prime % self.q == 0

        self.parameter_fabrication = lphm_reconciliation(p=self.p, q=self.q, r=self.r)

__init__(r, p, q=None, name='lphm_parameterized_bilinear_interdependence', *args, **kwargs)

Initializes the low-rank hierarchical mapping parameterized bilinear interdependence function.

Parameters:

Name Type Description Default
r int

Rank of the low-rank approximation.

required
p int

Number of partitions in the input dimension.

required
q int

Number of partitions in the output dimension. Defaults to p.

None
name str

Name of the interdependence function. Defaults to 'lphm_parameterized_bilinear_interdependence'.

'lphm_parameterized_bilinear_interdependence'
*args tuple

Additional positional arguments for the parent class.

()
**kwargs dict

Additional keyword arguments for the parent class.

{}

Raises:

Type Description
ValueError

If the interdependence type is not supported.

AssertionError

If the dimensions are not divisible by the partitions.

Source code in tinybig/interdependence/parameterized_bilinear_interdependence.py
def __init__(self, r: int, p: int, q: int = None, name: str = 'lphm_parameterized_bilinear_interdependence', *args, **kwargs):
    """
        Initializes the low-rank hierarchical mapping parameterized bilinear interdependence function.

        Parameters
        ----------
        r : int
            Rank of the low-rank approximation.
        p : int
            Number of partitions in the input dimension.
        q : int, optional
            Number of partitions in the output dimension. Defaults to `p`.
        name : str, optional
            Name of the interdependence function. Defaults to 'lphm_parameterized_bilinear_interdependence'.
        *args : tuple
            Additional positional arguments for the parent class.
        **kwargs : dict
            Additional keyword arguments for the parent class.

        Raises
        ------
        ValueError
            If the interdependence type is not supported.
        AssertionError
            If the dimensions are not divisible by the partitions.
    """

    super().__init__(name=name, *args, **kwargs)

    self.r = r
    self.p = p
    self.q = q if q is not None else p

    if self.interdependence_type in ['row', 'left', 'instance', 'instance_interdependence']:
        d, d_prime = self.m, self.calculate_m_prime()
    elif self.interdependence_type in ['column', 'right', 'attribute', 'attribute_interdependence']:
        d, d_prime = self.b, self.calculate_b_prime()
    else:
        raise ValueError(f'Interdependence type {self.interdependence_type} not supported')
    assert d % self.p == 0 and d_prime % self.q == 0

    self.parameter_fabrication = lphm_reconciliation(p=self.p, q=self.q, r=self.r)