Пример #1
0
        return True
    else:
        return False


# whether to perform regression testing
def regression_test():
    print(
        "Do you want to perform regression testing?[y/n] (<Enter> default to y)"
    )
    option = input()
    if (option == 'y' or option == ''):
        return True
    else:
        return False


if __name__ == "__main__":
    os.chdir(path)
    buildcwd()
    if (debug_test()):
        enum_and_sort_cases("./download_data")
        get_result("./download_data")
    elif (regression_test()):
        get_result("./data")
    else:
        case_cnt = int(input("Please tell us how many cases do you want:\n"))
        gene_data(case_cnt)
        get_result("./data")
    get_graph()
Пример #2
0
# =============================================================================
# ###############minmize lnprob#######################
# =============================================================================
############to generate the likehood with zs############
error_l = 5  #input("which error level?:\n")
writefile = open('minima_LDCM_sc{0}_fixOM'.format(scenario), 'w')
writefile.write("# Omage H0" + "\n")
import scipy.optimize as op
nll = lambda *args: -lnprob(*args)
bnds = ((0, None), )
import time
points = input("how many minima points?:\n")  #default as 10,000
for loop in range(points):
    ticks1 = time.time()
    dl = gene_data(10000, error_l)
    z = dl[:, 0]
    y = dl[:, 2]
    err = dl[:, 3]
    result = op.minimize(nll, (70), method='SLSQP', bounds=bnds, args=(y, err))
    ticks2 = time.time()
    print "the precentage:", float(
        loop) / points * 100, "%;", "time remain:", round(
            (ticks2 - ticks1) * (points - loop) / 60,
            2), "mins;", "para:", result["x"], "\n\r",
    writefile.write(repr(result["x"]) + "\n")
writefile.close()

#################perfrom MCMC##################
#import emcee
#z=z
Пример #3
0
# =============================================================================
# ###############minmize lnprob#######################
# =============================================================================
############to generate the likehood with zs############
import scipy.optimize as op

nll = lambda *args: -lnprob(*args)
bnds = ((0, None), (0, None))
error_ls = (5, 15)
error_prior = (5, 20)
################perfrom MCMC##################
import emcee

value = 50000
dl = gene_data(value, error_ls=error_ls)
z = dl[:, 0]
y = dl[:, 2]  #set to the 1 truth, 2 biased
errs = (dl[:, 1] * error_prior[0] / 100., dl[:, 1] * error_prior[1] / 100.)

##==============================================================================
## de-Activate this part if the minimaztion is OK to you
##==============================================================================
mcmc_count = 0
result = op.minimize(nll, (0.3, 70),
                     method='SLSQP',
                     bounds=bnds,
                     args=(y, errs[0], errs[1]))
print "para:", result[
    "x"], "\n\r",  # test the natural value of the minimazation
Пример #4
0
import numpy as np
from scipy import integrate
import matplotlib.pyplot as plt
#import sys
#sys.path.insert(0,'../')
from pz import pz
from gene_data import gene_data

import matplotlib as matt
import matplotlib.lines as mlines
from matplotlib import colors
matt.rcParams['font.family'] = 'STIXGeneral'

# =============================================================================
# Test differnet cosmology
# =============================================================================
fig = plt.figure(figsize=(15, 6))
ax = fig.add_subplot(111)
err_level = input("Input the error level:\n")
dl = gene_data(10000, err_level, H0=70., om=0.3)
#dl_wr =  gene_data(10000,3, H0=57., om=0.7)
##dl_wwr =  gene_data(10000, 20, H0=65., om=0.54)
ax.errorbar(x=dl[:, 0], y=dl[:, 2], yerr=dl[:, 3], fmt='b.', zorder=-1)
ax.set_yscale('log')

plt.title('The $D_L$ vs redshift, {0} per cent level'.format(err_level),
          fontsize=15)
plt.xlabel('$z$', fontsize=15)
plt.ylabel('$D_L$', fontsize=15)
plt.tick_params(labelsize=15)
plt.show()
Пример #5
0
if_file = glob.glob(filename)
if if_file == []:
    writefile = open(filename, 'w')
    writefile.write("# Omage H0" + "\n")
elif if_file is not []:
    writefile = open(filename, "r+")
    writefile.read()

import scipy.optimize as op
nll = lambda *args: -lnprob(*args)
bnds = ((0, None), (0, None))
import time
points = 5000  #input("how many minima points?:\n")  #default as 10,000
for loop in range(points):
    ticks1 = time.time()
    dl = gene_data(10000, error_ls=error_ls)
    z = dl[:, 0]
    y = dl[:, 2]
    errs = (dl[:, 1] * error_prior[0] / 100., dl[:, 1] * error_prior[1] / 100.)
    result = op.minimize(nll, (0.3, 70),
                         method='SLSQP',
                         bounds=bnds,
                         args=(y, errs[0], errs[1]))
    ticks2 = time.time()
    if loop / 10 > (loop - 1) / 10:
        print "To write to the", filename
    print "the precentage:", float(
        loop) / points * 100, "%;", "time remain:", round(
            (ticks2 - ticks1) * (points - loop) / 60,
            2), "mins;", "para:", result["x"], "\n\r",
    writefile.write(repr(result["x"][0]) + " " + repr(result["x"][1]) + "\n")
Пример #6
0
#pz_std= pz(0.3,70)
#pz_wr= pz(0.7,57)
##pz(0.3,70)
#plt.figure(figsize=(8,6))
#plt.plot(pz_std[:,0],pz_std[:,1],label='Om=0.3,H0=70')
#plt.plot(pz_wr[:,0],pz_wr[:,1],label='Om=0.45,H0=60')
#plt.xlabel('$z$',fontsize=15)
#plt.ylabel('P(z)', fontsize=15)
#plt.legend()
#plt.close()

# =============================================================================
# Calculate lnprob
# =============================================================================
from likelihoods import lnlike,lnlike_inpz, lnlike_with_z,chisq_with_z, lnprob
dl = gene_data(10000,5, H0=70., om=0.3)
like_r= lnlike((0.3,70),dl[:,2], dl[:,3])
like_w= lnlike((0.51, 65),dl[:,2], dl[:,3])
print like_r, like_w, like_r-like_w

#like_r= lnlike_with_z((0.3,70),dl[:,2], dl[:,3]*6,dl[:,0])
#like_w= lnlike_with_z((0.7,57),dl[:,2], dl[:,3]*6,dl[:,0])
#print like_r, like_w, like_r-like_w

'''
#om=0.3
#h0=70
#ps=pz(om,h0)
#zs=ps[:,0]
#
#from LCDM_minima import twod_like, lnlike,lnprob