NeuralSW / GradientFlow /target.py
khai199733's picture
push
b389bd5
Raw History Blame Contribute Delete
889 Bytes
"""Target distribution for the gradient-flow experiment: a ring of 8 isotropic
Gaussians in 2D (the classic toy multi-modal target)."""
import math
import torch
def make_ring_mixture(n_components=8, radius=5.0, std=0.3, device='cpu'):
"""Equal-weight mixture of `n_components` isotropic Gaussians on a circle.
Returns (means, covs, weights) in the same layout expected by
Amortized_simulation.sw_common's mixture-Gaussian helpers:
means (K, d), covs (K, d, d), weights (K,).
"""
angles = torch.arange(n_components, dtype=torch.float32) * (2 * math.pi / n_components)
means = radius * torch.stack([torch.cos(angles), torch.sin(angles)], dim=1)
means = means.to(device)
covs = (std ** 2) * torch.eye(2, device=device).unsqueeze(0).repeat(n_components, 1, 1)
weights = torch.full((n_components,), 1.0 / n_components)
return means, covs, weights