Ejemplo n.º 1
0
def plot_one_slice_of_ninja_star_samples_2(samples, output_image_path_generator, dpi=100):

    import ninja_star_distribution

    pylab.hold(True)

    print "Computing the original pdf values."
    M = 4.0
    mesh_x,mesh_y = np.mgrid[-M:M:.01, -M:M:.01]
    z = ninja_star_distribution.mesh_pdf(mesh_x, mesh_y)

    print "Generating the nice plots."
    model_pdf_values_plot_handle = plt.pcolor(mesh_x, mesh_y, z)
    #plt.winter()
    plt.pink()
    #d = plt.colorbar(model_pdf_value_plot_handle, orientation='horizontal')

    for c in np.arange(samples.shape[0]):
        x = samples[c,:,0]
        y = samples[c,:,1]
        scatter_handle = pylab.scatter(x, y)

        pylab.draw()
        pylab.savefig(output_image_path_generator(c), dpi=dpi)
        print "Wrote " + output_image_path_generator(c)                                             
        del(scatter_handle)

    pylab.close()
Ejemplo n.º 2
0
def plot_one_slice_of_ninja_star_samples(samples_slice, output_image_path, dpi=100, omit_ninja_star_from_plots = False):
    """
        Samples should be of size (M, d).
        You would generally pick either one chain alone
        or one time slice from a set of chains.

        This plotting function doesn't pretend to be
        a very general method. It assumes that the samples
        are 2-dimensional and that [-4.0, 4.0]^2 is the
        best choice of window to plot the samples.
    """

    import ninja_star_distribution

    pylab.hold(True)

    x = samples_slice[:,0]
    y = samples_slice[:,1]

    # TODO : pick better color for the sample dots
    pylab.scatter(x, y)

    # TODO : stamp the KL divergence on the plots

    M = 4.0
    if not omit_ninja_star_from_plots:
        print "Computing the original pdf values."

        mesh_x,mesh_y = np.mgrid[-M:M:.01, -M:M:.01]
        z = ninja_star_distribution.mesh_pdf(mesh_x, mesh_y)

        print "Generating the nice plots."
        model_pdf_values_plot_handle = plt.pcolor(mesh_x, mesh_y, z)
        #plt.winter()
        plt.pink()
        #d = plt.colorbar(model_pdf_value_plot_handle, orientation='horizontal')

    pylab.axes([-M, M, -M, M])
    count_of_points_outside = np.count_nonzero( (x < M) + (M < x) + (y < M) + (M < y) )
    pylab.text(0.0, 0.0,"%d points outside" % count_of_points_outside,fontsize=12, transform = pylab.gca().transAxes)

    pylab.draw()
    #pylab.savefig(output_image_path)
    pylab.savefig(output_image_path, dpi=dpi)
    pylab.close()