Пример #1
0
def ln_likelihood_2d(mu_obs, sig_obs, z_vector, theta):
    #print (h)
    cosmo = LambdaCDM(Om0=theta[0], Ode0=theta[1], H0=100 * h)
    mu_pred = cosmo.distmod(z_vector).value
    #print ('pred', )
    chi_2 = np.sum(np.power(((mu_obs - mu_pred) / sig_obs), 2.0))
    return (-chi_2 / 2.0)
Пример #2
0
    def generate_model_data_vector(self, times, parameters):
        #        parameters = get_parameter_set()

        cosmo = LambdaCDM(H0=parameters[0],
                          Om0=parameters[1],
                          Ode0=parameters[2],
                          Ob0=parameters[3],
                          Tcmb0=2.725)
        model_data_vector = cosmo.distmod(times).value
        #not keeping units here

        return model_data_vector
Пример #3
0
#----------------------------------------------------------------------
# This function adjusts matplotlib settings for a uniform feel in the textbook.
# Note that with usetex=True, fonts are rendered with LaTeX.  This may
# result in an error if LaTeX is not installed on your system.  In that case,
# you can set usetex to False.
if "setup_text_plots" not in globals():
    from astroML.plotting import setup_text_plots
setup_text_plots(fontsize=8, usetex=True)

#------------------------------------------------------------
# Generate data
z_sample, mu_sample, dmu = generate_mu_z(100, random_state=0)

cosmo = LambdaCDM(H0=70, Om0=0.30, Ode0=0.70, Tcmb0=0)
z = np.linspace(0.01, 2, 1000)
mu_true = cosmo.distmod(z)

#------------------------------------------------------------
# Define our classifiers
basis_mu = np.linspace(0, 2, 15)[:, None]
basis_sigma = 3 * (basis_mu[1] - basis_mu[0])

subplots = [221, 222, 223, 224]
classifiers = [
    LinearRegression(),
    PolynomialRegression(4),
    BasisFunctionRegression('gaussian', mu=basis_mu, sigma=basis_sigma),
    NadarayaWatson('gaussian', h=0.1)
]
text = [
    'Straight-line Regression', '4th degree Polynomial\n Regression',
Пример #4
0
def compute_logL(beta):
    cosmo = LambdaCDM(H0=71, Om0=beta[0], Ode0=beta[1], Tcmb0=0)
    mu_pred = cosmo.distmod(z_sample).value
    return - np.sum(0.5 * ((mu_sample - mu_pred) / dmu) ** 2)
Пример #5
0
#------------------------------------------------------------
# Plot the results
fig = plt.figure(figsize=(5, 2.5))
fig.subplots_adjust(left=0.1, right=0.95, wspace=0.25,
                    bottom=0.15, top=0.9)

# left plot: the data and best-fit
ax = fig.add_subplot(121)
whr = np.where(res == np.max(res))
omegaM_best = omegaM[whr[0][0]]
omegaL_best = omegaL[whr[1][0]]
cosmo = LambdaCDM(H0=71, Om0=omegaM_best, Ode0=omegaL_best, Tcmb0=0)

z_fit = np.linspace(0.04, 2, 100)
mu_fit = cosmo.distmod(z_fit).value

ax.plot(z_fit, mu_fit, '-k')
ax.errorbar(z_sample, mu_sample, dmu, fmt='.k', ecolor='gray')

ax.set_xlim(0, 1.8)
ax.set_ylim(36, 46)

ax.set_xlabel('$z$')
ax.set_ylabel(r'$\mu$')

ax.text(0.04, 0.96, "%i observations" % len(z_sample),
        ha='left', va='top', transform=ax.transAxes)

# right plot: the likelihood
ax = fig.add_subplot(122)