Skip to content

constant_c_interdependence

Bases: constant_interdependence

A class for constant interdependence with a scalar multiplier.

This class defines an interdependence matrix as a scalar (c) multiplied by a matrix of ones.

Notes

Formally, based on the (optional) input data batch \(\mathbf{X} \in {R}^{b \times m}\), we define the constant interdependence function as: $$ \begin{equation} \xi(\mathbf{X}) = c \times \mathbf{1} \in {R}^{m \times m}, \text{ or } \xi(\mathbf{X}) = c \times \mathbf{1} \in {R}^{b \times b}, \end{equation} $$ where \(c\) is the provided constant factor and \(\mathbf{1}\) is a matrix of ones.

Methods:

Name Description
__init__

Initializes the constant-c interdependence function.

Source code in tinybig/interdependence/basic_interdependence.py
class constant_c_interdependence(constant_interdependence):
    r"""
        A class for constant interdependence with a scalar multiplier.

        This class defines an interdependence matrix as a scalar (`c`) multiplied by a matrix of ones.

        Notes
        -------
        Formally, based on the (optional) input data batch $\mathbf{X} \in {R}^{b \times m}$, we define the constant interdependence function as:
        $$
            \begin{equation}
            \xi(\mathbf{X}) = c \times \mathbf{1} \in {R}^{m \times m}, \text{ or } \xi(\mathbf{X}) = c \times \mathbf{1} \in {R}^{b \times b},
            \end{equation}
        $$
        where $c$ is the provided constant factor and $\mathbf{1}$ is a matrix of ones.

        Methods
        -------
        __init__(b, m, b_prime=None, m_prime=None, c=1.0, ...)
            Initializes the constant-c interdependence function.
    """

    def __init__(
        self,
        b: int, m: int,
        b_prime: int = None, m_prime: int = None,
        c: float | int = 1.0,
        name: str = 'constant_c_interdependence',
        interdependence_type: str = 'attribute',
        device: str = 'cpu',
        *args, **kwargs
    ):
        """
            Initializes the constant-c interdependence function.

            Parameters
            ----------
            b : int
                Number of rows in the input tensor.
            m : int
                Number of columns in the input tensor.
            b_prime : int, optional
                Number of rows in the output tensor for row-based interdependence. Required for row-based interdependence types.
            m_prime : int, optional
                Number of columns in the output tensor for column-based interdependence. Required for column-based interdependence types.
            c : float or int, optional
                Scalar multiplier for the interdependence matrix. Defaults to 1.0.
            name : str, optional
                Name of the interdependence function. Defaults to 'constant_c_interdependence'.
            interdependence_type : str, optional
                Type of interdependence ('attribute', 'instance', etc.). Defaults to 'attribute'.
            device : str, optional
                Device for computation. Defaults to 'cpu'.
            *args : tuple
                Additional positional arguments for the parent `constant_interdependence` class.
            **kwargs : dict
                Additional keyword arguments for the parent `constant_interdependence` class.

            Raises
            ------
            ValueError
                If the interdependence type is not supported.
        """

        if interdependence_type in ['row', 'left', 'instance', 'instance_interdependence']:
            assert b_prime is not None
            A = c * torch.ones((b, b_prime), device=device)
        elif interdependence_type in ['column', 'right', 'attribute', 'attribute_interdependence']:
            assert m_prime is not None
            A = c * torch.ones((m, m_prime), device=device)
        else:
            raise ValueError(f'Interdependence type {interdependence_type} is not supported')
        super().__init__(b=b, m=m, A=A, name=name, interdependence_type=interdependence_type, device=device, *args, **kwargs)

__init__(b, m, b_prime=None, m_prime=None, c=1.0, name='constant_c_interdependence', interdependence_type='attribute', device='cpu', *args, **kwargs)

Initializes the constant-c interdependence function.

Parameters:

Name Type Description Default
b int

Number of rows in the input tensor.

required
m int

Number of columns in the input tensor.

required
b_prime int

Number of rows in the output tensor for row-based interdependence. Required for row-based interdependence types.

None
m_prime int

Number of columns in the output tensor for column-based interdependence. Required for column-based interdependence types.

None
c float or int

Scalar multiplier for the interdependence matrix. Defaults to 1.0.

1.0
name str

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

'constant_c_interdependence'
interdependence_type str

Type of interdependence ('attribute', 'instance', etc.). Defaults to 'attribute'.

'attribute'
device str

Device for computation. Defaults to 'cpu'.

'cpu'
*args tuple

Additional positional arguments for the parent constant_interdependence class.

()
**kwargs dict

Additional keyword arguments for the parent constant_interdependence class.

{}

Raises:

Type Description
ValueError

If the interdependence type is not supported.

Source code in tinybig/interdependence/basic_interdependence.py
def __init__(
    self,
    b: int, m: int,
    b_prime: int = None, m_prime: int = None,
    c: float | int = 1.0,
    name: str = 'constant_c_interdependence',
    interdependence_type: str = 'attribute',
    device: str = 'cpu',
    *args, **kwargs
):
    """
        Initializes the constant-c interdependence function.

        Parameters
        ----------
        b : int
            Number of rows in the input tensor.
        m : int
            Number of columns in the input tensor.
        b_prime : int, optional
            Number of rows in the output tensor for row-based interdependence. Required for row-based interdependence types.
        m_prime : int, optional
            Number of columns in the output tensor for column-based interdependence. Required for column-based interdependence types.
        c : float or int, optional
            Scalar multiplier for the interdependence matrix. Defaults to 1.0.
        name : str, optional
            Name of the interdependence function. Defaults to 'constant_c_interdependence'.
        interdependence_type : str, optional
            Type of interdependence ('attribute', 'instance', etc.). Defaults to 'attribute'.
        device : str, optional
            Device for computation. Defaults to 'cpu'.
        *args : tuple
            Additional positional arguments for the parent `constant_interdependence` class.
        **kwargs : dict
            Additional keyword arguments for the parent `constant_interdependence` class.

        Raises
        ------
        ValueError
            If the interdependence type is not supported.
    """

    if interdependence_type in ['row', 'left', 'instance', 'instance_interdependence']:
        assert b_prime is not None
        A = c * torch.ones((b, b_prime), device=device)
    elif interdependence_type in ['column', 'right', 'attribute', 'attribute_interdependence']:
        assert m_prime is not None
        A = c * torch.ones((m, m_prime), device=device)
    else:
        raise ValueError(f'Interdependence type {interdependence_type} is not supported')
    super().__init__(b=b, m=m, A=A, name=name, interdependence_type=interdependence_type, device=device, *args, **kwargs)