File size: 1,121 Bytes
c0f6452 b389bd5 c0f6452 b389bd5 c0f6452 b389bd5 c0f6452 b389bd5 c0f6452 b389bd5 c0f6452 b389bd5 c0f6452 b389bd5 c0f6452 b389bd5 c0f6452 b389bd5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import torch
from sw_common import (
set_seed,
train_amortized_phi,
evaluate_and_plot,
sample_mixture_gaussian,
mixture_gaussian_true_quantiles,
)
set_seed(42)
device = 'cuda'
n_dim = 2
means = torch.tensor([[1.0, 2.0], [4.0, 5.0], [7.0, 8.0]], device=device) # 3 components' means
covs = torch.tensor([[[1.0, 0.5], [0.5, 2.0]], # Covariance for component 1
[[0.8, 0.2], [0.2, 1.0]], # Covariance for component 2
[[1.5, 0.4], [0.4, 1.2]]], device=device) # Covariance for component 3
weights = torch.tensor([0.4, 0.3, 0.3]) # Weights for the 3 components
def sample_fn(n_samples):
return sample_mixture_gaussian(n_samples, means, covs, weights, n_dim, device)
def true_quantile_fn(test_thetas, taus_test):
return mixture_gaussian_true_quantiles(test_thetas, taus_test, means, covs, weights)
model = train_amortized_phi(sample_fn, d=n_dim, device=device)
evaluate_and_plot(
model, d=n_dim, device=device,
true_quantile_fn=true_quantile_fn,
sample_fn=sample_fn,
title="Amortized Quantile Function — Gaussian Mixture",
)
|