Exemplo n.º 1
0
Arquivo: mmaf.py Projeto: mlzxy/dac
 def plot_clustering(self, X, params, labels):
     B = X.shape[0]
     K = len(params)
     nx, ny = 50, 50
     if B > 1:
         fig, axes = plt.subplots(2, B // 2, figsize=(2.5 * B, 10))
         for b, ax in enumerate(axes.flatten()):
             ulabels, colors = scatter(X[b], labels=labels[b], ax=ax)
             for l, c in zip(ulabels, colors):
                 Xbl = X[b][labels[b] == l]
                 Z, x, y = meshgrid_around(Xbl, nx, ny, margin=0.1)
                 ll = self.net.flow.log_prob(Z,
                                             context=params[l][b]).reshape(
                                                 nx, ny)
                 ax.contour(to_numpy(x),
                            to_numpy(y),
                            to_numpy(ll.exp()),
                            zorder=10,
                            alpha=0.3)
     else:
         ulabels, colors = scatter(X[0], labels=labels[0])
         for l, c in zip(ulabels, colors):
             Xbl = X[0][labels[0] == l]
             Z, x, y = meshgrid_around(Xbl, nx, ny, margin=0.1)
             ll = self.net.flow.log_prob(Z, context=params[l][0]).reshape(
                 nx, ny)
             plt.contour(to_numpy(x),
                         to_numpy(y),
                         to_numpy(ll.exp()),
                         zorder=10,
                         alpha=0.3)
Exemplo n.º 2
0
 def plot_filtering(self, batch):
     X = batch['X']
     B = X.shape[0]
     with torch.no_grad():
         outputs = self.compute_loss(batch, train=False)
     mu, cov = self.net.mvn.stats(outputs['theta'])
     labels = (outputs['logits'] > 0.0).long()
     fig, axes = plt.subplots(min(B, 2),
                              max(B // 2, 1),
                              figsize=(2.5 * B if B > 1 else 10, 10))
     axes = [axes] if B == 1 else axes.flatten()
     for b, ax in enumerate(axes):
         scatter(X[b], labels=labels[b], ax=ax)
         draw_ellipse(mu[b], cov[b], ax=ax)
Exemplo n.º 3
0
Arquivo: mog.py Projeto: mlzxy/dac
 def plot_step(self, X):
     B = X.shape[0]
     self.net.eval()
     params, _, logits = self.net(X)
     mu, cov = self.net.mvn.stats(params)
     labels = (logits > 0.0).int().squeeze(-1)
     if B == 1:
         scatter(X[0], labels=labels[0])
         draw_ellipse(mu[0][0], cov[0][0])
     else:
         fig, axes = plt.subplots(2, B // 2, figsize=(2.5 * B, 10))
         for b, ax in enumerate(axes.flatten()):
             scatter(X[b], labels=labels[b], ax=ax)
             draw_ellipse(mu[b][0], cov[b][0], ax=ax)
Exemplo n.º 4
0
Arquivo: mmaf.py Projeto: mlzxy/dac
 def plot_step(self, X):
     B = X.shape[0]
     self.net.eval()
     params, logits = self.net(X)
     labels = (logits > 0.0).int().squeeze(-1)
     nx, ny = 50, 50
     fig, axes = plt.subplots(2, B // 2, figsize=(7 * B / 5, 5))
     for b, ax in enumerate(axes.flatten()):
         scatter(X[b], labels=labels[b], ax=ax)
         Z, x, y = meshgrid_around(X[b], nx, ny, margin=0.1)
         ll = self.net.flow.log_prob(Z, context=params[b]).reshape(nx, ny)
         ax.contour(to_numpy(x),
                    to_numpy(y),
                    to_numpy(ll.exp()),
                    zorder=10,
                    alpha=0.3)
Exemplo n.º 5
0
 def plot_clustering(self, X, results):
     labels = results.get('labels')
     theta = results.get('theta')
     B = X.shape[0]
     K = theta.shape[1]
     nx, ny = 50, 50
     fig, axes = plt.subplots(min(B, 2),
                              max(B // 2, 1),
                              figsize=(2.5 * B if B > 1 else 10, 10))
     axes = [axes] if B == 1 else axes.flatten()
     for b, ax in enumerate(axes):
         ulabels, colors = scatter(X[b], labels=labels[b], ax=ax)
         for l, c in zip(ulabels, colors):
             Xbl = X[b][labels[b] == l]
             Z, x, y = meshgrid_around(Xbl, nx, ny, margin=0.1)
             ll = self.net.flow.log_prob(Z,
                                         context=theta[b,
                                                       l]).reshape(nx, ny)
             ax.contour(to_numpy(x),
                        to_numpy(y),
                        to_numpy(ll.exp()),
                        zorder=10,
                        alpha=0.5)
             ax.set_xticks([])
             ax.set_yticks([])
Exemplo n.º 6
0
 def plot_filtering(self, batch):
     X = batch['X']
     B, N = X.shape[0], X.shape[1]
     with torch.no_grad():
         outputs = self.compute_loss(batch, train=False)
     labels = (outputs['logits'] > 0.0).long()
     theta = outputs['theta']
     nx, ny = 50, 50
     fig, axes = plt.subplots(min(B, 2),
                              max(B // 2, 1),
                              figsize=(2.5 * B if B > 1 else 10, 10))
     axes = [axes] if B == 1 else axes.flatten()
     for b, ax in enumerate(axes):
         scatter(X[b], labels=labels[b], ax=ax)
         Z, x, y = meshgrid_around(X[b], nx, ny, margin=0.1)
         ll = self.net.flow.log_prob(Z, context=theta[b]).reshape(nx, ny)
         ax.contour(to_numpy(x),
                    to_numpy(y),
                    to_numpy(ll.exp()),
                    zorder=10,
                    alpha=0.3)