Skip to content

arc_hyperbolic_expansion

Bases: transformation

The arc hyperbolic data expansion function.

It performs the arc hyperbolic expansion of the input vector, and returns the expansion result. The class inherits from the base expansion class (i.e., the transformation class in the module directory).

...

Notes

For input vector \(\mathbf{x} \in R^m\), its arc hyperbolic expansion can be represented as follows: $$ \begin{equation} \kappa (\mathbf{x}) = \left[ \text{arccosh}(\mathbf{x}), \text{arcsinh}(\mathbf{x}), \text{arctanh}(\mathbf{x}) \right] \in {R}^D, \end{equation} $$ where the output dimensions will be \(D = 3 m\).

By default, the input and output can also be processed with the optional pre- or post-processing functions in the arc hyperbolic expansion function.

Attributes:

Name Type Description
name str, default = 'arc_hyperbolic_expansion'

Name of the expansion function.

Methods:

Name Description
__init__

It performs the initialization of the expansion function.

calculate_D

It calculates the expansion space dimension D based on the input dimension parameter m.

forward

It implements the abstract forward method declared in the base expansion class.

Source code in tinybig/expansion/trigonometric_expansion.py
class arc_hyperbolic_expansion(transformation):
    r"""
    The arc hyperbolic data expansion function.

    It performs the arc hyperbolic expansion of the input vector, and returns the expansion result.
    The class inherits from the base expansion class (i.e., the transformation class in the module directory).

    ...

    Notes
    ----------
    For input vector $\mathbf{x} \in R^m$, its arc hyperbolic expansion can be represented as follows:
    $$
    \begin{equation}
        \kappa (\mathbf{x}) = \left[ \text{arccosh}(\mathbf{x}), \text{arcsinh}(\mathbf{x}), \text{arctanh}(\mathbf{x}) \right] \in {R}^D,
    \end{equation}
    $$
    where the output dimensions will be $D = 3 m$.

    By default, the input and output can also be processed with the optional pre- or post-processing functions
    in the arc hyperbolic expansion function.

    Attributes
    ----------
    name: str, default = 'arc_hyperbolic_expansion'
        Name of the expansion function.

    Methods
    ----------
    __init__
        It performs the initialization of the expansion function.

    calculate_D
        It calculates the expansion space dimension D based on the input dimension parameter m.

    forward
        It implements the abstract forward method declared in the base expansion class.

    """
    def __init__(self, name='arc_hyperbolic_expansion', *args, **kwargs):
        r"""
        The initialization method of the arc hyperbolic expansion function.

        It initializes a arc hyperbolic expansion object based on the input function name.
        This method will also call the initialization method of the base class as well.

        Parameters
        ----------
        name: str, default = 'arc_hyperbolic_expansion'
            The name of the arc hyperbolic expansion function.

        Returns
        ----------
        transformation
            The arc hyperbolic expansion function.
        """
        super().__init__(name=name, *args, **kwargs)

    def calculate_D(self, m: int):
        r"""
        The expansion dimension calculation method.

        It calculates the intermediate expansion space dimension based on the input dimension parameter m.
        For the arc hyperbolic expansion function, the expansion space dimension will be
        $$ D = 3m. $$

        Parameters
        ----------
        m: int
            The dimension of the input space.

        Returns
        -------
        int
            The dimension of the expansion space.
        """
        return m * 3

    def forward(self, x: torch.Tensor, device='cpu', *args, **kwargs):
        r"""
        The forward method of the data expansion function.

        It performs the arc hyperbolic data expansion of the input data and returns the expansion result as
        $$
            \begin{equation}
                \kappa (\mathbf{x}) = \left[ \text{arccosh}(\mathbf{x}), \text{arcsinh}(\mathbf{x}), \text{arctanh}(\mathbf{x}) \right] \in {R}^D.
            \end{equation}
        $$


        Parameters
        ----------
        x: torch.Tensor
            The input data vector.
        device: str, default = 'cpu'
            The device to perform the data expansion.

        Returns
        ----------
        torch.Tensor
            The expanded data vector of the input.
        """
        b, m = x.shape
        x = self.pre_process(x=x, device=device)
        # pre-normalize the input to range [0, 1]
        x = torch.nn.functional.sigmoid(x)
        arcsinh = torch.arcsinh(x)
        arccosh = torch.arccosh(x+1.01)
        arctanh = torch.arctanh(0.99*x)
        expansion = torch.cat((arcsinh, arccosh, arctanh), dim=1)

        assert expansion.shape == (b, self.calculate_D(m=m))
        return self.post_process(x=expansion, device=device)

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

The initialization method of the arc hyperbolic expansion function.

It initializes a arc hyperbolic expansion object based on the input function name. This method will also call the initialization method of the base class as well.

Parameters:

Name Type Description Default
name

The name of the arc hyperbolic expansion function.

'arc_hyperbolic_expansion'

Returns:

Type Description
transformation

The arc hyperbolic expansion function.

Source code in tinybig/expansion/trigonometric_expansion.py
def __init__(self, name='arc_hyperbolic_expansion', *args, **kwargs):
    r"""
    The initialization method of the arc hyperbolic expansion function.

    It initializes a arc hyperbolic expansion object based on the input function name.
    This method will also call the initialization method of the base class as well.

    Parameters
    ----------
    name: str, default = 'arc_hyperbolic_expansion'
        The name of the arc hyperbolic expansion function.

    Returns
    ----------
    transformation
        The arc hyperbolic expansion function.
    """
    super().__init__(name=name, *args, **kwargs)

calculate_D(m)

The expansion dimension calculation method.

It calculates the intermediate expansion space dimension based on the input dimension parameter m. For the arc hyperbolic expansion function, the expansion space dimension will be $$ D = 3m. $$

Parameters:

Name Type Description Default
m int

The dimension of the input space.

required

Returns:

Type Description
int

The dimension of the expansion space.

Source code in tinybig/expansion/trigonometric_expansion.py
def calculate_D(self, m: int):
    r"""
    The expansion dimension calculation method.

    It calculates the intermediate expansion space dimension based on the input dimension parameter m.
    For the arc hyperbolic expansion function, the expansion space dimension will be
    $$ D = 3m. $$

    Parameters
    ----------
    m: int
        The dimension of the input space.

    Returns
    -------
    int
        The dimension of the expansion space.
    """
    return m * 3

forward(x, device='cpu', *args, **kwargs)

The forward method of the data expansion function.

It performs the arc hyperbolic data expansion of the input data and returns the expansion result as $$ \begin{equation} \kappa (\mathbf{x}) = \left[ \text{arccosh}(\mathbf{x}), \text{arcsinh}(\mathbf{x}), \text{arctanh}(\mathbf{x}) \right] \in {R}^D. \end{equation} $$

Parameters:

Name Type Description Default
x Tensor

The input data vector.

required
device

The device to perform the data expansion.

'cpu'

Returns:

Type Description
Tensor

The expanded data vector of the input.

Source code in tinybig/expansion/trigonometric_expansion.py
def forward(self, x: torch.Tensor, device='cpu', *args, **kwargs):
    r"""
    The forward method of the data expansion function.

    It performs the arc hyperbolic data expansion of the input data and returns the expansion result as
    $$
        \begin{equation}
            \kappa (\mathbf{x}) = \left[ \text{arccosh}(\mathbf{x}), \text{arcsinh}(\mathbf{x}), \text{arctanh}(\mathbf{x}) \right] \in {R}^D.
        \end{equation}
    $$


    Parameters
    ----------
    x: torch.Tensor
        The input data vector.
    device: str, default = 'cpu'
        The device to perform the data expansion.

    Returns
    ----------
    torch.Tensor
        The expanded data vector of the input.
    """
    b, m = x.shape
    x = self.pre_process(x=x, device=device)
    # pre-normalize the input to range [0, 1]
    x = torch.nn.functional.sigmoid(x)
    arcsinh = torch.arcsinh(x)
    arccosh = torch.arccosh(x+1.01)
    arctanh = torch.arctanh(0.99*x)
    expansion = torch.cat((arcsinh, arccosh, arctanh), dim=1)

    assert expansion.shape == (b, self.calculate_D(m=m))
    return self.post_process(x=expansion, device=device)