Fixed diffusion confidence interval plot
This commit is contained in:
@@ -19,8 +19,6 @@ def sample_diffusion(model: DiffusionModel, n: int, inputs: torch.tensor, noise_
|
||||
alpha = 1. - beta
|
||||
alpha_hat = torch.cumprod(alpha, dim=0)
|
||||
|
||||
# inputs: (num_features) -> (batch_size, num_features)
|
||||
# inputs: (time_steps, num_features) -> (batch_size, time_steps, num_features)
|
||||
if len(inputs.shape) == 2:
|
||||
inputs = inputs.repeat(n, 1)
|
||||
elif len(inputs.shape) == 3:
|
||||
@@ -42,17 +40,17 @@ def sample_diffusion(model: DiffusionModel, n: int, inputs: torch.tensor, noise_
|
||||
noise = torch.zeros_like(x)
|
||||
|
||||
x = 1/torch.sqrt(_alpha) * (x-((1-_alpha) / (torch.sqrt(1 - _alpha_hat))) * predicted_noise) + torch.sqrt(_beta) * noise
|
||||
x = torch.clamp(x, -1.0, 1.0)
|
||||
return x
|
||||
|
||||
|
||||
|
||||
class DiffusionTrainer:
|
||||
def __init__(self, model: nn.Module, data_processor: DataProcessor, device: torch.device):
|
||||
self.model = model
|
||||
self.device = device
|
||||
|
||||
self.noise_steps = 20
|
||||
self.beta_start = 1e-4
|
||||
self.noise_steps = 30
|
||||
self.beta_start = 0.0001
|
||||
self.beta_end = 0.02
|
||||
self.ts_length = 96
|
||||
|
||||
@@ -183,17 +181,18 @@ class DiffusionTrainer:
|
||||
with torch.no_grad():
|
||||
samples = self.sample(self.model, 100, features).cpu().numpy()
|
||||
|
||||
ci_99_upper = np.quantile(samples, 0.99, axis=0)
|
||||
ci_99_lower = np.quantile(samples, 0.01, axis=0)
|
||||
ci_99_upper = np.quantile(samples, 0.995, axis=0)
|
||||
ci_99_lower = np.quantile(samples, 0.005, axis=0)
|
||||
|
||||
ci_95_upper = np.quantile(samples, 0.95, axis=0)
|
||||
ci_95_lower = np.quantile(samples, 0.05, axis=0)
|
||||
ci_95_upper = np.quantile(samples, 0.975, axis=0)
|
||||
ci_95_lower = np.quantile(samples, 0.025, axis=0)
|
||||
|
||||
ci_90_upper = np.quantile(samples, 0.9, axis=0)
|
||||
ci_90_lower = np.quantile(samples, 0.1, axis=0)
|
||||
ci_90_upper = np.quantile(samples, 0.95, axis=0)
|
||||
ci_90_lower = np.quantile(samples, 0.05, axis=0)
|
||||
|
||||
ci_50_lower = np.quantile(samples, 0.25, axis=0)
|
||||
ci_50_upper = np.quantile(samples, 0.75, axis=0)
|
||||
|
||||
ci_50_upper = np.quantile(samples, 0.5, axis=0)
|
||||
ci_50_lower = np.quantile(samples, 0.5, axis=0)
|
||||
|
||||
sns.set_theme()
|
||||
time_steps = np.arange(0, 96)
|
||||
|
||||
Reference in New Issue
Block a user