Skip to content

CircleDataset

Methods and Attributes

Bases: BaseSyntheticDataset

Generates points sampled uniformly on a circle with noise.

Parameters:

Name Type Description Default
n_samples int

Number of samples. Default: 2000.

2000
noise float

Standard deviation of Gaussian noise added. Default: 0.05.

0.05
radius float

Radius of the circle. Default: 1.0.

1.0
device Optional[Union[str, device]]

Device for the tensor.

None
dtype dtype

Data type for the tensor. Default: torch.float32.

float32
seed Optional[int]

Random seed for reproducibility.

None
Source code in torchebm/datasets/generators.py
class CircleDataset(BaseSyntheticDataset):
    """
    Generates points sampled uniformly on a circle with noise.

    Args:
        n_samples (int): Number of samples. Default: 2000.
        noise (float): Standard deviation of Gaussian noise added. Default: 0.05.
        radius (float): Radius of the circle. Default: 1.0.
        device (Optional[Union[str, torch.device]]): Device for the tensor.
        dtype (torch.dtype): Data type for the tensor. Default: torch.float32.
        seed (Optional[int]): Random seed for reproducibility.
    """

    def __init__(
        self,
        n_samples: int = 2000,
        noise: float = 0.05,
        radius: float = 1.0,
        device: Optional[Union[str, torch.device]] = None,
        dtype: torch.dtype = torch.float32,
        seed: Optional[int] = None,
    ):
        self.noise = noise
        self.radius = radius
        super().__init__(n_samples=n_samples, device=device, dtype=dtype, seed=seed)

    def _generate_data(self) -> torch.Tensor:
        # Logic from make_circle
        angles = 2 * np.pi * np.random.rand(self.n_samples)
        x = self.radius * np.cos(angles)
        y = self.radius * np.sin(angles)
        X = np.vstack((x, y)).T.astype(np.float32)

        tensor_data = torch.from_numpy(X)
        tensor_data += torch.randn_like(tensor_data) * self.noise

        return tensor_data

noise instance-attribute

noise = noise

radius instance-attribute

radius = radius

_generate_data

_generate_data() -> torch.Tensor
Source code in torchebm/datasets/generators.py
def _generate_data(self) -> torch.Tensor:
    # Logic from make_circle
    angles = 2 * np.pi * np.random.rand(self.n_samples)
    x = self.radius * np.cos(angles)
    y = self.radius * np.sin(angles)
    X = np.vstack((x, y)).T.astype(np.float32)

    tensor_data = torch.from_numpy(X)
    tensor_data += torch.randn_like(tensor_data) * self.noise

    return tensor_data