Skip to content

Distributions

Distribution

Base class for all distributions.

Source code in models/tts/styledtts2/diffusion/distributions.py
class Distribution:
    r"""Base class for all distributions."""

    def __call__(self, num_samples: int) -> Tensor:
        r"""Generate a number of samples from the distribution.

        Args:
            num_samples (int): The number of samples to generate.

        Raises:
            NotImplementedError: This method should be overridden by subclasses.
        """
        raise NotImplementedError

__call__(num_samples)

Generate a number of samples from the distribution.

Parameters:

Name Type Description Default
num_samples int

The number of samples to generate.

required

Raises:

Type Description
NotImplementedError

This method should be overridden by subclasses.

Source code in models/tts/styledtts2/diffusion/distributions.py
def __call__(self, num_samples: int) -> Tensor:
    r"""Generate a number of samples from the distribution.

    Args:
        num_samples (int): The number of samples to generate.

    Raises:
        NotImplementedError: This method should be overridden by subclasses.
    """
    raise NotImplementedError

LogNormalDistribution

Bases: Distribution

Log-normal distribution.

Source code in models/tts/styledtts2/diffusion/distributions.py
class LogNormalDistribution(Distribution):
    r"""Log-normal distribution."""

    def __init__(self, mean: float, std: float):
        r"""Initialize the distribution with a mean and standard deviation.

        Args:
            mean (float): The mean of the log-normal distribution.
            std (float): The standard deviation of the log-normal distribution.
        """
        self.mean = mean
        self.std = std

    def __call__(
        self, num_samples: int,
    ) -> Tensor:
        r"""Generate a number of samples from the log-normal distribution.

        Args:
            num_samples (int): The number of samples to generate.

        Returns:
            Tensor: A tensor of samples from the log-normal distribution.
        """
        normal = self.mean + self.std * torch.randn((num_samples,))
        return normal.exp()

__call__(num_samples)

Generate a number of samples from the log-normal distribution.

Parameters:

Name Type Description Default
num_samples int

The number of samples to generate.

required

Returns:

Name Type Description
Tensor Tensor

A tensor of samples from the log-normal distribution.

Source code in models/tts/styledtts2/diffusion/distributions.py
def __call__(
    self, num_samples: int,
) -> Tensor:
    r"""Generate a number of samples from the log-normal distribution.

    Args:
        num_samples (int): The number of samples to generate.

    Returns:
        Tensor: A tensor of samples from the log-normal distribution.
    """
    normal = self.mean + self.std * torch.randn((num_samples,))
    return normal.exp()

__init__(mean, std)

Initialize the distribution with a mean and standard deviation.

Parameters:

Name Type Description Default
mean float

The mean of the log-normal distribution.

required
std float

The standard deviation of the log-normal distribution.

required
Source code in models/tts/styledtts2/diffusion/distributions.py
def __init__(self, mean: float, std: float):
    r"""Initialize the distribution with a mean and standard deviation.

    Args:
        mean (float): The mean of the log-normal distribution.
        std (float): The standard deviation of the log-normal distribution.
    """
    self.mean = mean
    self.std = std

UniformDistribution

Bases: Distribution

Uniform distribution.

Source code in models/tts/styledtts2/diffusion/distributions.py
class UniformDistribution(Distribution):
    r"""Uniform distribution."""

    def __call__(self, num_samples: int):
        r"""Generate a number of samples from the uniform distribution.

        Args:
            num_samples (int): The number of samples to generate.

        Returns:
            Tensor: A tensor of samples from the uniform distribution.
        """
        return torch.rand(num_samples)

__call__(num_samples)

Generate a number of samples from the uniform distribution.

Parameters:

Name Type Description Default
num_samples int

The number of samples to generate.

required

Returns:

Name Type Description
Tensor

A tensor of samples from the uniform distribution.

Source code in models/tts/styledtts2/diffusion/distributions.py
def __call__(self, num_samples: int):
    r"""Generate a number of samples from the uniform distribution.

    Args:
        num_samples (int): The number of samples to generate.

    Returns:
        Tensor: A tensor of samples from the uniform distribution.
    """
    return torch.rand(num_samples)

VKDistribution

Bases: Distribution

VK distribution. The class is implementing a variant of a distribution that is based on the Von Mises distribution, which is a continuous probability distribution on the circle (it's often used as a circular version of the normal distribution).

Source code in models/tts/styledtts2/diffusion/distributions.py
class VKDistribution(Distribution):
    r"""VK distribution. The class is implementing a variant of a distribution that is based on the Von Mises distribution, which is a continuous probability distribution on the circle (it's often used as a circular version of the normal distribution)."""

    def __init__(
        self,
        min_value: float = 0.0,
        max_value: float = float("inf"),
        sigma_data: float = 1.0,
    ):
        r"""Initialize the distribution with a minimum value, maximum value, and sigma data.

        Args:
            min_value (float): The minimum value for the inverse CDF. Defaults to 0.0.
            max_value (float): The maximum value for the inverse CDF. Defaults to infinity.
            sigma_data (float): The sigma data of the VK distribution. Defaults to 1.0.
        """
        self.min_value = min_value
        self.max_value = max_value
        self.sigma_data = sigma_data

    def __call__(
        self, num_samples: int,
    ) -> Tensor:
        r"""Generate a number of samples from the VK distribution.

        Args:
            num_samples (int): The number of samples to generate.

        Returns:
            Tensor: A tensor of samples from the VK distribution.
        """
        sigma_data = self.sigma_data
        min_cdf = atan(self.min_value / sigma_data) * 2 / pi
        max_cdf = atan(self.max_value / sigma_data) * 2 / pi
        u = (max_cdf - min_cdf) * torch.randn((num_samples,)) + min_cdf
        return torch.tan(u * pi / 2) * sigma_data

__call__(num_samples)

Generate a number of samples from the VK distribution.

Parameters:

Name Type Description Default
num_samples int

The number of samples to generate.

required

Returns:

Name Type Description
Tensor Tensor

A tensor of samples from the VK distribution.

Source code in models/tts/styledtts2/diffusion/distributions.py
def __call__(
    self, num_samples: int,
) -> Tensor:
    r"""Generate a number of samples from the VK distribution.

    Args:
        num_samples (int): The number of samples to generate.

    Returns:
        Tensor: A tensor of samples from the VK distribution.
    """
    sigma_data = self.sigma_data
    min_cdf = atan(self.min_value / sigma_data) * 2 / pi
    max_cdf = atan(self.max_value / sigma_data) * 2 / pi
    u = (max_cdf - min_cdf) * torch.randn((num_samples,)) + min_cdf
    return torch.tan(u * pi / 2) * sigma_data

__init__(min_value=0.0, max_value=float('inf'), sigma_data=1.0)

Initialize the distribution with a minimum value, maximum value, and sigma data.

Parameters:

Name Type Description Default
min_value float

The minimum value for the inverse CDF. Defaults to 0.0.

0.0
max_value float

The maximum value for the inverse CDF. Defaults to infinity.

float('inf')
sigma_data float

The sigma data of the VK distribution. Defaults to 1.0.

1.0
Source code in models/tts/styledtts2/diffusion/distributions.py
def __init__(
    self,
    min_value: float = 0.0,
    max_value: float = float("inf"),
    sigma_data: float = 1.0,
):
    r"""Initialize the distribution with a minimum value, maximum value, and sigma data.

    Args:
        min_value (float): The minimum value for the inverse CDF. Defaults to 0.0.
        max_value (float): The maximum value for the inverse CDF. Defaults to infinity.
        sigma_data (float): The sigma data of the VK distribution. Defaults to 1.0.
    """
    self.min_value = min_value
    self.max_value = max_value
    self.sigma_data = sigma_data