mixture = VariationalMixture( xdim=xdim, hdim=hdim, n_hidden=n_hidden, n_classes=n_classes, components=[ RealNVP(n_blocks=n_realnvp_blocks, xdim=xdim, hdim=hdim_realnvp, n_hidden=n_hidden_realnvp, base_dist=base_dist) for _ in range(n_classes) ], ) # %% count_parameters(mixture) # %% x = np.linspace(-1, 1, 1000) z = np.array(np.meshgrid(x, x)).transpose(1, 2, 0) z = np.reshape(z, [z.shape[0] * z.shape[1], -1]) mesh = z.reshape([1000, 1000, 2]).transpose(2, 0, 1) xx = mesh[0] yy = mesh[1] def _pre_backward_callback(mixture, n_iter, log_probs, prior_crossent, q_entropy, temperature, writer): if n_iter % 5 == 0: writer.add_scalar('train/log_probs', log_probs, n_iter)
colors[idx_3] = 3 # %% plt.scatter(X0[:, 0], X0[:, 1], s=5, c=colors) # %% flow = RealNVP(n_blocks=4, input_size=2, hidden_size=32, n_hidden=1, base_dist=base_dist) opt = optim.Adam(flow.parameters(), lr=1e-2) # %% count_parameters(flow) # %% n_epochs = 500 bs = 256 # %% writer = SummaryWriter(f"../tensorboard_logs/{now_str()}") dataloader = DataLoader(X, batch_size=bs, shuffle=True, num_workers=0) best_loss = torch.Tensor([float("+inf")]) #attempts = 0 for epoch in trange(n_epochs): batches = range((len(X) - 1) // bs + 1) for i, xb in enumerate(dataloader):
c = torch.Tensor(c) plt.figure(figsize=(10, 10)) plt.scatter(X[:, 0].numpy(), X[:, 1].numpy(), c=c.numpy(), s=5) plt.show() # %% xdim = 2 hdim = 2 n_hidden = 3 n_classes = 3 mlp = MLP(xdim=xdim, hdim=hdim, n_hidden=n_hidden, n_classes=n_classes) # %% count_parameters(mlp) # %% n_epochs = 10000 bs = 512 opt = optim.Adam(mlp.parameters(), lr=0.001) # %% c_onehot = torch_onehot(c, 3) # %% writer = SummaryWriter(f"/workspace/sandbox/tensorboard_logs/{now_str()}") best_loss = torch.Tensor([float("+inf")]) attempts = 0