示例#1
0
def newGraph_Confidence(result):
    H_0 = [ii[0] for ii in result]
    omega_m0 = [ii[1] for ii in result]
    omega_q0 = [ii[2] for ii in result]
    alpha = [ii[3] for ii in result]
    alpha_x = [ii[4] for ii in result]
    m = [ii[5] for ii in result]

    names = [
        "H_0", "\Omega_{m_0}", "\Omega_{Q_0}", r"\tilde{\alpha}",
        r"\tilde{\alpha}_x", "m"
    ]
    #names = ["H_0"]
    labels = names

    newShape = [H_0, omega_m0, omega_q0, alpha, alpha_x, m]
    #newShape = [H_0]
    values = np.array(newShape).T
    #print(values.shape)
    s1 = MCSamples(samples=values, names=names, labels=labels)
    g = plots.get_subplot_plotter()
    s1.updateSettings({'contours': [0.68, 0.95, 0.99]})
    g.settings.colormap = "binary"
    g.settings.num_plot_contours = 3
    g.triangle_plot([s1], shaded=True, title_limit=1)

    plt.savefig("result.pdf")
示例#2
0
    def _triangle_plot(self, these_samples, these_y, plotname):
        names = self._parameters_list
        labels = []

        level_lines = [0.2, 0.4, 0.6, 0.8, 0.95, 0.98]

        num_level_lines = len(level_lines)
        g = plots.getSubplotPlotter(width_inch=9)
        g.settings.num_plot_contours = num_level_lines

        mcsamples = MCSamples(samples=these_samples, names=names, labels=names)
        mcsamples.updateSettings({'contours': level_lines})

        g.triangle_plot(
            [mcsamples],
            names,
            # filled_compare=True,
            legend_labels=labels,
            legend_loc='upper right',
            # filled=False,
            contour_colors=['darkblue', 'green'],
            #                     filled=True,
            #                     contour_lws=[.2, .4, .68, .95, .98]
        )

        n_params = len(names)

        for i in range(n_params):
            for j in range(n_params):
                if j > i:
                    continue

                ax = g.subplots[i, j]
                ax.axvline(these_y[j], color='black', ls='--', alpha=0.4)
                if i != j:
                    ax.axhline(these_y[i], color='black', ls='-.', alpha=0.4)

        g.export(plotname)
示例#3
0
#data.reshape(7,7)
cov = data
ndim = data.shape[0]
mean_ = [0.01, 0.082, -2.6, -3.14, 20 * 0.53, -2.54, 1.53]
samps = np.random.multivariate_normal(mean_, cov, size=nsamp)

#samps = np.random.multivariate_normal([0]*ndim, cov, size=nsamp)
#A = np.random.rand(ndim,ndim)
#cov = np.dot(A, A.T)
#samps2 = np.random.multivariate_normal([0]*ndim, cov, size=nsamp)
#names = ['r','As','$\alpha_s$','$\beta_s$','Ad','$\alpha_d$','$\beta_d$']
#labels = ['r','As','$\alpha_s$','$\beta_s$','Ad','$\alpha_d$','$\beta_d$']
names = ['r', 'As', 'alpha_s', 'beta_s', 'Ad', 'alpha_d', 'beta_d']
#labels = ['r','As','alpha_s','beta_s','Ad','alpha_d','beta_d']
labels = ['r', 'A_s', '\\alpha_s', 'beta_s', 'Ad', 'alpha_d', 'beta_d']
samples = MCSamples(samples=samps,
                    names=names,
                    labels=labels,
                    ranges={
                        'r': (0, None),
                        'As': (0, None)
                    })
#samples2 = MCSamples(samples=samps2,names = names, labels = labels, label='Second set')

g = plots.getSubplotPlotter()
samples.updateSettings({'contours': [0.68, 0.95, 0.99]})
g.settings.num_plot_contours = 3
g.triangle_plot(samples, filled=True)
#g.triangle_plot([samples, samples2], filled=True)
g.export('output_file.pdf')
                        usecols=[2, 3],
                        sep='\s+',
                        skiprows=1,
                        names=colname)

from getdist import plots, MCSamples
labels = ['\\mathrm{X}', '\\mathrm{Y}']
samples1 = MCSamples(samples=chains1[['Separation', 'Flux_Ratio']].values,
                     names=colname,
                     labels=labels)
samples2 = MCSamples(samples=chains2[['Separation', 'Flux_Ratio']].values,
                     names=colname,
                     labels=labels)

conf = [0.683, 0.955, 0.997]
samples1.updateSettings({'contours': conf})
samples2.updateSettings({'contours': conf})

g = plots.getSubplotPlotter()
g.settings.num_plot_contours = 3
g.settings.shade_level_scale = 3
g.settings.fig_width_inch = 8.5
g.settings.linewidth = 0.3
g.plot_2d(samples1,
          'Separation',
          'Flux_Ratio',
          filled=False,
          lims=[881, 911, 807, 837])  #30 x 30 pixels
g.plot_2d(samples2,
          'Separation',
          'Flux_Ratio',
示例#5
0
'''
2D contours
'''
xstep1, ystep1 = loadtxt('flat-LCDM_steps.dat', unpack=True)
xstep = int(xstep1)
ystep = int(ystep1)
print('check 6')

z2 = loadtxt('flat_LCDM_chi2_H(z)only.dat', unpack=True)
y2 = loadtxt('flat_LCDM_Omega_m0.dat', unpack=True)
x2 = loadtxt('flat_LCDM_H0.dat', unpack=True)
zmin = z2.tolist().index(min(z2))   
xmin2 = x2[zmin]
ymin2 = y2[zmin]
c2 = z2[zmin]
print(c2, xmin2, ymin2, "2D best fit points with grid")

g = plots.getSinglePlotter(width_inch=4, ratio=1)
samples.updateSettings({'contours': [0.6827, 0.9545, 0.9973]})
g.settings.num_plot_contours = 3
g.plot_2d([samples],['H','m'],filled_compare=False,
    line_args=[{'ls':'solid','color':'k'}])
x2_2D_mcase3 = reshape(x2, (xstep, ystep))
y2_2D_mcase3 = reshape(y2, (xstep, ystep))
z2_2D_mcase3 = reshape(z2, (xstep, ystep))
plt.contour(x2_2D_mcase3, y2_2D_mcase3, z2_2D_mcase3, [c2, c2 + 2.3, c2 + 6.17, c2 + 11.8],
            colors='blue', linestyles=':')
plt.plot([xmin2, xmin2], [ymin2, ymin2], marker='+', color='blue') #Best fit parameters
g.export('flat_LCDM_H0_Om_2D_MCMC_vs_grid_my_data.pdf')
        
print("--- %s seconds ---" % (time.time() - start_time))
示例#6
0
    "N_{mu}"
]

gamma, log10_g, log10_M, N_a, N_conv, N_pr, N_mu, something_1, something_2, \
    something_3 = Read_Data_File(os.getcwd()+'/out/likelihood/ev.dat')

samps = np.array([gamma, log10_g, log10_M, N_a, N_conv, N_pr, N_mu]).T

# names = ["gamma", "N_a", "N_{conv}", "N_{pr}", "N_{mu}"]
# labels = ["gamma", "N_a", "N_{conv}", "N_{pr}", "N_{mu}"]

# gamma, N_a, N_conv, N_pr, N_mu, something_1, something_2, \
#     something_3 = Read_Data_File(os.getcwd()+'/out/likelihood/ev.dat')

# samps = np.array([gamma, N_a, N_conv, N_pr, N_mu]).T

samples = MCSamples(samples=samps, names=names, labels=labels)

plt.figure()
g = plots.get_subplot_plotter()
samples.updateSettings({
    'contours': [0.68, 0.90],
    'fine_bins_2D': 40,
    'smooth_scale_2D': 0.6
})
g.settings.num_plot_contours = 3
g.triangle_plot(samples, shaded=True)
#plt.plot(-2.37, -1.80, 'X', color = 'black', markersize=14)
# g.export(os.getcwd()+'/out/plots/all_param_marg.pdf')
g.export(os.getcwd() + '/out/plots/all_param_marg.png')
示例#7
0
def plot_triangle(sim_samples,
                  gp_samples,
                  burnin_frac=0.1,
                  emulator=True,
                  gp_error=False):

    if gp_error and emulator:
        label_gp = 'GP (Error)'

    elif emulator and not gp_error:
        label_gp = 'GP (Mean)'

    else:
        label_gp = 'Simulator (MOPED)'

    ndim = sim_samples.shape[-1]

    names = ["x%s" % i for i in range(ndim)]

    labels = [
        r"\Omega_{m}", r"w_{0}", r"M_{B}", r"\delta M", r"\alpha", r"\beta"
    ]

    # for the simulator
    burnin = int(burnin_frac * sim_samples.shape[1])
    samples_exact = sim_samples[:, burnin:, :].reshape((-1, ndim))
    cut_samps = samples_exact[samples_exact[:, 0] >= 0.0, :]
    samples1 = MCSamples(samples=cut_samps,
                         names=names,
                         labels=labels,
                         ranges={'x0': (0.0, None)})

    # for the emulator
    burnin = int(burnin_frac * gp_samples.chain.shape[1])
    samples_emu = gp_samples.chain[:, burnin:, :].reshape((-1, ndim))
    cut_samps = samples_emu[samples_emu[:, 0] >= 0.0, :]
    samples2 = MCSamples(samples=cut_samps,
                         names=names,
                         labels=labels,
                         ranges={'x0': (0.0, None)})

    # setups for plotting
    sim_color = '#EEC591'
    gp_color = 'Blue'
    alpha_tri = 0.1
    red_patch = mpatches.Patch(color=sim_color,
                               label='Simulator',
                               alpha=alpha_tri)
    gp_line = Line2D([0], [0],
                     color=gp_color,
                     linewidth=3,
                     linestyle='--',
                     label=label_gp)
    rec_leg = [red_patch, gp_line]

    contours = np.array([0.68, 0.95])

    G = plots.getSubplotPlotter(subplot_size=3.5)
    samples1.updateSettings({'contours': [0.68, 0.95]})

    G.triangle_plot([samples1],
                    filled=True,
                    line_args={
                        'lw': 3,
                        'color': sim_color
                    },
                    contour_colors=[sim_color])
    G.settings.num_plot_contours = 2
    plt.legend(handles=rec_leg,
               loc='best',
               prop={'size': 25},
               bbox_to_anchor=(0.7, 6.0),
               borderaxespad=0.)
    G.settings.alpha_filled_add = alpha_tri
    for i in range(0, 6):
        for j in range(0, i + 1):
            if i != j:
                ax = G.subplots[i, j]

                a, b = G.get_param_array(samples2,
                                         ['x' + str(j), 'x' + str(i)])
                density = G.sample_analyser.get_density_grid(samples2, a, b)
                density.contours = density.getContourLevels(contours)
                contour_levels = density.contours
                ax.contour(density.x,
                           density.y,
                           density.P,
                           sorted(contour_levels),
                           colors=gp_color,
                           linewidths=3,
                           linestyles='--')

                ax.tick_params(labelsize=20)
                ax.yaxis.label.set_size(20)
                ax.xaxis.label.set_size(20)
            else:
                ax = G.subplots[i, j]

                dense = samples2.get1DDensity('x' + str(i))
                dense.normalize(by='max')
                ax.plot(dense.x, dense.P, lw=3, c=gp_color, linestyle='--')

                ax.tick_params(labelsize=20)
                ax.yaxis.label.set_size(20)
                ax.xaxis.label.set_size(20)
    plt.savefig('images/triangle_plot.jpg',
                bbox_inches='tight',
                transparent=False)
    plt.close()