Skip to content

Distributions

Distribution

Base class for all distributions.

Source code in models/tts/styledtts2/diffusion/distributions.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
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
12
13
14
15
16
17
18
19
20
21
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
37
38
39
40
41
42
43
44
45
46
47
48
49
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
27
28
29
30
31
32
33
34
35
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
52
53
54
55
56
57
58
59
60
61
62
63
64
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
55
56
57
58
59
60
61
62
63
64
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
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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