Beispiel #1
0
        # func = lambda zs: lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2))
        # plot_isocontours(ax, func, cmap='Blues')
        # if samp_i==0:  ax.annotate('Prior p(z)', xytext=(.3, 1.1), xy=(0, 1), textcoords='axes fraction')

        #Scatter plot of q
        # col +=1

        ax = plt.subplot2grid((rows, cols), (row, samp_i + 1), frameon=False)

        # Ws, logpW, logqW = model.sample_W()  #_ , [1], [1]
        # func = lambda zs: lognormal4(torch.Tensor(zs), torch.squeeze(mean.data), torch.squeeze(logvar.data))
        # plot_isocontours(ax, func, cmap='Reds',xlimits=xlimits,ylimits=ylimits)
        func = lambda zs: model.logposterior_func(samp_torch, zs)
        plot_isocontours2_exp_norm(ax,
                                   func,
                                   cmap='Blues',
                                   legend=legend,
                                   xlimits=xlimits,
                                   ylimits=ylimits)
        # if samp_i==0:  ax.annotate('p(z|x,W1)', xytext=(.1, 1.1), xy=(0, 1), textcoords='axes fraction')
        # func = lambda zs: lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2))
        # plot_isocontours(ax, func, cmap='Blues', alpha=.3,xlimits=xlimits,ylimits=ylimits)

        # plot_scatter(ax, samps=z ,xlimits=xlimits,ylimits=ylimits)

        # #Plot q
        # col +=1
        # ax = plt.subplot2grid((rows,cols), (samp_i,col), frameon=False)

        # # # mean, logvar = model.encode(Variable(torch.unsqueeze(samp,0)))

        # samp_torch = Variable(torch.from_numpy(np.array([samp]))).type(model.dtype)
        # if samp_i==0:  ax.annotate('Prior p(z)', xytext=(.3, 1.1), xy=(0, 1), textcoords='axes fraction')



        #Scatter plot of q
        # col +=1



        ax = plt.subplot2grid((rows,cols), (row,samp_i+1), frameon=False)

        # Ws, logpW, logqW = model.sample_W()  #_ , [1], [1]   
        # func = lambda zs: lognormal4(torch.Tensor(zs), torch.squeeze(mean.data), torch.squeeze(logvar.data))
        # plot_isocontours(ax, func, cmap='Reds',xlimits=xlimits,ylimits=ylimits)
        func = lambda zs: model.logposterior_func(samp_torch,zs)
        plot_isocontours2_exp_norm(ax, func, cmap='Blues', legend=legend,xlimits=xlimits,ylimits=ylimits)
        # if samp_i==0:  ax.annotate('p(z|x,W1)', xytext=(.1, 1.1), xy=(0, 1), textcoords='axes fraction')
        # func = lambda zs: lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2))
        # plot_isocontours(ax, func, cmap='Blues', alpha=.3,xlimits=xlimits,ylimits=ylimits)

        # plot_scatter(ax, samps=z ,xlimits=xlimits,ylimits=ylimits)







        # #Plot q
        # col +=1
        # ax = plt.subplot2grid((rows,cols), (samp_i,col), frameon=False)
Beispiel #3
0
        # func = lambda zs: lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2))
        # plot_isocontours(ax, func, cmap='Blues')
        # if samp_i==0:  ax.annotate('Prior p(z)', xytext=(.3, 1.1), xy=(0, 1), textcoords='axes fraction')

        #Scatter plot of q
        # col +=1

        ax = plt.subplot2grid((rows, cols), (row, samp_i + 1), frameon=False)

        # Ws, logpW, logqW = model.sample_W()  #_ , [1], [1]
        # func = lambda zs: lognormal4(torch.Tensor(zs), torch.squeeze(mean.data), torch.squeeze(logvar.data))
        # plot_isocontours(ax, func, cmap='Reds',xlimits=xlimits,ylimits=ylimits)
        func = lambda zs: model.logposterior_func(samp_torch, zs)
        plot_isocontours2_exp_norm(ax,
                                   func,
                                   cmap='Greens',
                                   legend=legend,
                                   xlimits=xlimits,
                                   ylimits=ylimits)
        # if samp_i==0:  ax.annotate('p(z|x,W1)', xytext=(.1, 1.1), xy=(0, 1), textcoords='axes fraction')
        # func = lambda zs: lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2))
        # plot_isocontours(ax, func, cmap='Blues', alpha=.3,xlimits=xlimits,ylimits=ylimits)

        # plot_scatter(ax, samps=z ,xlimits=xlimits,ylimits=ylimits)

        # #Plot q
        # col +=1
        # ax = plt.subplot2grid((rows,cols), (samp_i,col), frameon=False)

        # # # mean, logvar = model.encode(Variable(torch.unsqueeze(samp,0)))

        # samp_torch = Variable(torch.from_numpy(np.array([samp]))).type(model.dtype)
            # if samp_i==0:  ax.annotate('Prior p(z)', xytext=(.3, 1.1), xy=(0, 1), textcoords='axes fraction')

            #Plot q
            col +=1
            val = 3
            ax = plt.subplot2grid((rows,cols), (samp_i,col), frameon=False)
            mean, logvar = model.encode(Variable(torch.unsqueeze(samp,0)))
            func = lambda zs: lognormal4(torch.Tensor(zs), torch.squeeze(mean.data), torch.squeeze(logvar.data))
            plot_isocontours(ax, func, cmap='Reds', xlimits=[-val, val], ylimits=[-val, val])
            if samp_i==0:  ax.annotate('p(z)\nq(z|x)\np(z|x)', xytext=(.3, 1.1), xy=(0, 1), textcoords='axes fraction')
            func = lambda zs: lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2))
            plot_isocontours(ax, func, cmap='Blues', alpha=.3, xlimits=[-val, val], ylimits=[-val, val])
            
            Ws, logpW, logqW = model.sample_W()  #_ , [1], [1]   
            func = lambda zs: log_bernoulli(model.decode(Ws, Variable(torch.unsqueeze(zs,1))), Variable(torch.unsqueeze(samp,0)))+ Variable(torch.unsqueeze(lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2)), 1))
            plot_isocontours2_exp_norm(ax, func, cmap='Greens', legend=legend, xlimits=[-val, val], ylimits=[-val, val])

            # #Plot logprior
            # col +=1
            # ax = plt.subplot2grid((rows,cols), (samp_i,col), frameon=False)
            # func = lambda zs: lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2))
            # plot_isocontoursNoExp(ax, func, cmap='Blues', legend=legend)
            # if samp_i==0:  ax.annotate('Prior\nlogp(z)', xytext=(.3, 1.1), xy=(0, 1), textcoords='axes fraction')

            # #Plot logq
            # col +=1
            # ax = plt.subplot2grid((rows,cols), (samp_i,col), frameon=False)
            # mean, logvar = model.encode(Variable(torch.unsqueeze(samp,0)))
            # func = lambda zs: lognormal4(torch.Tensor(zs), torch.squeeze(mean.data), torch.squeeze(logvar.data))
            # plot_isocontoursNoExp(ax, func, cmap='Reds', legend=legend)
            # if samp_i==0:  ax.annotate('Post Approx\nlog q(z|x)', xytext=(.1, 1.1), xy=(0, 1), textcoords='axes fraction')
            # func = lambda zs: lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2))
            # plot_isocontours(ax, func, cmap='Blues', alpha=.3)
            # func = lambda zs: lognormal4(torch.Tensor(zs), torch.squeeze(mean.data), torch.squeeze(logvar.data))
            # plot_isocontours(ax, func, cmap='Reds')




            #Plot prob
            col +=1
            ax = plt.subplot2grid((rows,cols), (samp_i,col), frameon=False)
            Ws, logpW, logqW = model.sample_W()  #_ , [1], [1]   
            func = lambda zs: lognormal4(torch.Tensor(zs), torch.squeeze(mean.data), torch.squeeze(logvar.data))
            plot_isocontours(ax, func, cmap='Reds',xlimits=xlimits,ylimits=ylimits)
            func = lambda zs: log_bernoulli(model.decode(Ws, Variable(torch.unsqueeze(zs,1))), Variable(torch.unsqueeze(samp,0)))+ Variable(torch.unsqueeze(lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2)), 1))
            plot_isocontours2_exp_norm(ax, func, cmap='Greens', legend=legend,xlimits=xlimits,ylimits=ylimits)
            if samp_i==0:  ax.annotate('p(z|x,W1)', xytext=(.1, 1.1), xy=(0, 1), textcoords='axes fraction')
            func = lambda zs: lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2))
            plot_isocontours(ax, func, cmap='Blues', alpha=.3,xlimits=xlimits,ylimits=ylimits)



            # #Plot prob
            # col +=1
            # ax = plt.subplot2grid((rows,cols), (samp_i,col), frameon=False)
            # Ws, logpW, logqW = model.sample_W()  #_ , [1], [1]   
            # # func = lambda zs: lognormal4(torch.Tensor(zs), torch.squeeze(mean.data), torch.squeeze(logvar.data))
            # # plot_isocontours(ax, func, cmap='Reds')
            # # func = lambda zs: log_bernoulli(model.decode(Ws, Variable(torch.unsqueeze(zs,1))), Variable(torch.unsqueeze(samp,0)))+ Variable(torch.unsqueeze(lognormal4(torch.Tensor(zs), torch.zeros(2), torch.zeros(2)), 1))
            # plot_isocontours2_exp_norm_logspace(ax, func, cmap='Greens', legend=legend)
            # if samp_i==0:  ax.annotate('p(z|x,W1)', xytext=(.1, 1.1), xy=(0, 1), textcoords='axes fraction')