Skip to content

hm_parameterized_interdependence

Bases: parameterized_interdependence

A parameterized interdependence function using hierarchical mapping (HM).

Notes

Formally, given the parameter vector \(\mathbf{w} \in R^{l_{\xi}}\), we partition \(\mathbf{w}\) into two sub-vectors and subsequently reshape them into two matrices \(\mathbf{A} \in R^{p \times q}\) and \(\mathbf{B} \in R^{s \times t}\) (where \(s =\frac{m}{p}\) and \(t = \frac{m'}{q}\)).

These two sub-matrices \(\mathbf{A}\) and \(\mathbf{B}\) help define the hypercomplex parameterized interdependence function as follows:

$$ \begin{equation} \xi(\mathbf{w}) = \mathbf{A} \otimes \mathbf{B} \in R^{m \times m'}, \end{equation} $$ whose required length of vector \(\mathbf{w}\) is \(l_{\xi} = pq + \frac{mm'}{pq}\).

Attributes:

Name Type Description
p int

Number of partitions in the input dimension.

q int

Number of partitions in the output dimension.

Methods:

Name Description
__init__

Initializes the hierarchical mapping parameterized interdependence function.

Source code in tinybig/interdependence/parameterized_interdependence.py
class hm_parameterized_interdependence(parameterized_interdependence):
    r"""
        A parameterized interdependence function using hierarchical mapping (HM).

        Notes
        ----------

        Formally, given the parameter vector $\mathbf{w} \in R^{l_{\xi}}$, we partition $\mathbf{w}$ into two sub-vectors and subsequently reshape them into two matrices
        $\mathbf{A} \in R^{p \times q}$ and $\mathbf{B} \in R^{s \times t}$ (where $s =\frac{m}{p}$ and $t = \frac{m'}{q}$).

        These two sub-matrices $\mathbf{A}$ and $\mathbf{B}$ help define the hypercomplex parameterized interdependence function as follows:

        $$
            \begin{equation}
            \xi(\mathbf{w}) = \mathbf{A} \otimes \mathbf{B} \in R^{m \times m'},
            \end{equation}
        $$
        whose required length of vector $\mathbf{w}$ is $l_{\xi} = pq + \frac{mm'}{pq}$.

        Attributes
        ----------
        p : int
            Number of partitions in the input dimension.
        q : int
            Number of partitions in the output dimension.

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

            Parameters
            ----------
            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 'hm_parameterized_interdependence'.
            *args : tuple
                Additional positional arguments.
            **kwargs : dict
                Additional keyword arguments.

            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.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.b, self.calculate_b_prime()
        elif self.interdependence_type in ['column', 'right', 'attribute', 'attribute_interdependence']:
            d, d_prime = self.m, self.calculate_m_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 = hm_reconciliation(p=self.p, q=self.q)

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

Initializes the hierarchical mapping parameterized interdependence function.

Parameters:

Name Type Description Default
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 'hm_parameterized_interdependence'.

'hm_parameterized_interdependence'
*args tuple

Additional positional arguments.

()
**kwargs dict

Additional keyword arguments.

{}

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_interdependence.py
def __init__(self, p: int, q: int = None, name: str = 'hm_parameterized_interdependence', *args, **kwargs):
    """
        Initializes the hierarchical mapping parameterized interdependence function.

        Parameters
        ----------
        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 'hm_parameterized_interdependence'.
        *args : tuple
            Additional positional arguments.
        **kwargs : dict
            Additional keyword arguments.

        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.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.b, self.calculate_b_prime()
    elif self.interdependence_type in ['column', 'right', 'attribute', 'attribute_interdependence']:
        d, d_prime = self.m, self.calculate_m_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 = hm_reconciliation(p=self.p, q=self.q)