Skip to content

discrete_wavelet

Bases: object

Base class for discrete wavelet functions.

This class provides a framework for implementing various discrete wavelet functions with scaling and translation parameters.

Attributes:

Name Type Description
name str

The name of the wavelet.

a float

The scaling parameter, must be > 1.

b float

The translation parameter, must be > 0.

Methods:

Name Description
psi

Abstract method for wavelet function definition.

forward

Apply the wavelet transformation to the input signal.

__call__

Perform wavelet transformation via call.

Source code in tinybig/koala/signal_processing/wavelet.py
class discrete_wavelet(object):
    """
    Base class for discrete wavelet functions.

    This class provides a framework for implementing various discrete wavelet functions with scaling and translation parameters.

    Attributes
    ----------
    name : str
        The name of the wavelet.
    a : float
        The scaling parameter, must be > 1.
    b : float
        The translation parameter, must be > 0.

    Methods
    -------
    psi(tau: torch.Tensor)
        Abstract method for wavelet function definition.
    forward(x: torch.Tensor, s: int, t: int)
        Apply the wavelet transformation to the input signal.
    __call__(x: torch.Tensor, s: int, t: int)
        Perform wavelet transformation via call.
    """
    def __init__(self, name: str = 'discrete_wavelet', a: float = 1.0, b: float = 1.0, *args, **kwargs):
        """
        Initialize the discrete wavelet class.

        Parameters
        ----------
        name : str, optional
            Name of the wavelet. Default is 'discrete_wavelet'.
        a : float, optional
            Scaling parameter. Must be > 1. Default is 1.0.
        b : float, optional
            Translation parameter. Must be > 0. Default is 1.0.
        *args, **kwargs
            Additional parameters.
        """
        if a < 1 or b < 0:
            raise ValueError('a must be > 1 and b mush > 0...')

        self.name = name
        self.a = a
        self.b = b

    @abstractmethod
    def psi(self, tau: torch.Tensor):
        """
        Abstract method for wavelet function definition.

        Parameters
        ----------
        tau : torch.Tensor
            Transformed input values.

        Returns
        -------
        torch.Tensor
            Wavelet values for the input.
        """
        pass

    def forward(self, x: torch.Tensor, s: int, t: int):
        """
        Apply the wavelet transformation to the input signal.

        Parameters
        ----------
        x : torch.Tensor
            Input signal.
        s : int
            Scaling factor.
        t : int
            Translation factor.

        Returns
        -------
        torch.Tensor
            Transformed signal.
        """
        tau = x/(self.a**s) - t*self.b
        return 1.0/math.sqrt(self.a**s) * self.psi(tau=tau)

    def __call__(self, x: torch.Tensor, s: int, t: int):
        """
        Perform wavelet transformation via call.

        Parameters
        ----------
        x : torch.Tensor
            Input signal.
        s : int
            Scaling factor.
        t : int
            Translation factor.

        Returns
        -------
        torch.Tensor
            Transformed signal.
        """
        return self.forward(x=x, s=s, t=t)

__call__(x, s, t)

Perform wavelet transformation via call.

Parameters:

Name Type Description Default
x Tensor

Input signal.

required
s int

Scaling factor.

required
t int

Translation factor.

required

Returns:

Type Description
Tensor

Transformed signal.

Source code in tinybig/koala/signal_processing/wavelet.py
def __call__(self, x: torch.Tensor, s: int, t: int):
    """
    Perform wavelet transformation via call.

    Parameters
    ----------
    x : torch.Tensor
        Input signal.
    s : int
        Scaling factor.
    t : int
        Translation factor.

    Returns
    -------
    torch.Tensor
        Transformed signal.
    """
    return self.forward(x=x, s=s, t=t)

__init__(name='discrete_wavelet', a=1.0, b=1.0, *args, **kwargs)

Initialize the discrete wavelet class.

Parameters:

Name Type Description Default
name str

Name of the wavelet. Default is 'discrete_wavelet'.

'discrete_wavelet'
a float

Scaling parameter. Must be > 1. Default is 1.0.

1.0
b float

Translation parameter. Must be > 0. Default is 1.0.

1.0
*args

Additional parameters.

()
**kwargs

Additional parameters.

()
Source code in tinybig/koala/signal_processing/wavelet.py
def __init__(self, name: str = 'discrete_wavelet', a: float = 1.0, b: float = 1.0, *args, **kwargs):
    """
    Initialize the discrete wavelet class.

    Parameters
    ----------
    name : str, optional
        Name of the wavelet. Default is 'discrete_wavelet'.
    a : float, optional
        Scaling parameter. Must be > 1. Default is 1.0.
    b : float, optional
        Translation parameter. Must be > 0. Default is 1.0.
    *args, **kwargs
        Additional parameters.
    """
    if a < 1 or b < 0:
        raise ValueError('a must be > 1 and b mush > 0...')

    self.name = name
    self.a = a
    self.b = b

forward(x, s, t)

Apply the wavelet transformation to the input signal.

Parameters:

Name Type Description Default
x Tensor

Input signal.

required
s int

Scaling factor.

required
t int

Translation factor.

required

Returns:

Type Description
Tensor

Transformed signal.

Source code in tinybig/koala/signal_processing/wavelet.py
def forward(self, x: torch.Tensor, s: int, t: int):
    """
    Apply the wavelet transformation to the input signal.

    Parameters
    ----------
    x : torch.Tensor
        Input signal.
    s : int
        Scaling factor.
    t : int
        Translation factor.

    Returns
    -------
    torch.Tensor
        Transformed signal.
    """
    tau = x/(self.a**s) - t*self.b
    return 1.0/math.sqrt(self.a**s) * self.psi(tau=tau)

psi(tau) abstractmethod

Abstract method for wavelet function definition.

Parameters:

Name Type Description Default
tau Tensor

Transformed input values.

required

Returns:

Type Description
Tensor

Wavelet values for the input.

Source code in tinybig/koala/signal_processing/wavelet.py
@abstractmethod
def psi(self, tau: torch.Tensor):
    """
    Abstract method for wavelet function definition.

    Parameters
    ----------
    tau : torch.Tensor
        Transformed input values.

    Returns
    -------
    torch.Tensor
        Wavelet values for the input.
    """
    pass