<reponame>RiccardoLincetto/toy-gans
# PyTorch dataset for M-dimensional Gaussian distributions.
# This data is meant to be used as 'real data' to feed the Discriminator:
# p_real then depends on this.

import matplotlib.pyplot as plt
from numpy import dtype
import torch
from torch.utils.data import Dataset


class Gaussian(Dataset):
    """M-dimensional gaussian distribution dataset."""

    def __init__(self, N: int, M: int, mean: float, std: float) -> None:
        """
        :param N: number of samples in the dataset, equivalent to its length;
        :param M: number of dimensions for the gaussian distribution;
        :param mean: M-element vector of means;
        :param std: M-element vector of standard variances.
        """
        mean = torch.Tensor(mean)
        std = torch.Tensor(std)

        self.lims = (mean - 3*std, mean + 3*std)

        self.points = torch.normal(0., 1., (N, M))
        for i in range(M):
            self.points[:, i] *= std[i]
            self.points[:, i] += mean[i]

    def __len__(self) -> int:
        """Number of vectors (data points)."""
        return self.points.shape[0]

    def __getitem__(self, index: int) -> float:
        """Index-th vector."""
        return self.points[index, ...]

    @property
    def dimensions(self) -> int:
        """Number of dimensions per vector."""
        return self.points.shape[1]

    def plot(self):
        if self.dimensions == 2:
            plt.figure()
            plt.title("Data points")
            plt.scatter(self.points[..., 0], self.points[..., 1])
            plt.xlabel(f"dim {0}")
            plt.ylabel(f"dim {1}")
            # plt.xlim(*self.xlim)
            # plt.ylim(*self.ylim)
            # plt.gca().set_aspect('equal')
# PyTorch dataset for M-dimensional Gaussian distributions.
# This data is meant to be used as 'real data' to feed the Discriminator:
# p_real then depends on this.

import matplotlib.pyplot as plt
from numpy import dtype
import torch
from torch.utils.data import Dataset


class Gaussian(Dataset):
    """M-dimensional gaussian distribution dataset."""

    def __init__(self, N: int, M: int, mean: float, std: float) -> None:
        """
        :param N: number of samples in the dataset, equivalent to its length;
        :param M: number of dimensions for the gaussian distribution;
        :param mean: M-element vector of means;
        :param std: M-element vector of standard variances.
        """
        mean = torch.Tensor(mean)
        std = torch.Tensor(std)

        self.lims = (mean - 3*std, mean + 3*std)

        self.points = torch.normal(0., 1., (N, M))
        for i in range(M):
            self.points[:, i] *= std[i]
            self.points[:, i] += mean[i]

    def __len__(self) -> int:
        """Number of vectors (data points)."""
        return self.points.shape[0]

    def __getitem__(self, index: int) -> float:
        """Index-th vector."""
        return self.points[index, ...]

    @property
    def dimensions(self) -> int:
        """Number of dimensions per vector."""
        return self.points.shape[1]

    def plot(self):
        if self.dimensions == 2:
            plt.figure()
            plt.title("Data points")
            plt.scatter(self.points[..., 0], self.points[..., 1])
            plt.xlabel(f"dim {0}")
            plt.ylabel(f"dim {1}")
            # plt.xlim(*self.xlim)
            # plt.ylim(*self.ylim)
            # plt.gca().set_aspect('equal')
# PyTorch dataset for M-dimensional Gaussian distributions. # This data is meant to be used as 'real data' to feed the Discriminator: # p_real then depends on this. M-dimensional gaussian distribution dataset. :param N: number of samples in the dataset, equivalent to its length;         :param M: number of dimensions for the gaussian distribution;         :param mean: M-element vector of means;         :param std: M-element vector of standard variances. Number of vectors (data points). Index-th vector. Number of dimensions per vector. # plt.xlim(*self.xlim) # plt.ylim(*self.ylim) # plt.gca().set_aspect('equal')